npd-node-replace 组件用于缓解当前 Amazon EKS 在中国区EKS 集群中的问题节点无法被及时处理的痛点 推荐使用当前最新版本为 v0.1.2 (https://github.com/normalzzz/npd-node-replace/releases/tag/v0.1.2)
npd-node-replace 的主要功能如下:
kubectl label nodes <node name> npd-node-replace-enabled=true (v0.1.1 版本为黑名单机制,标签为 npd-node-replace-disabled=true, 在 v0.1.2 版本推出修改) - name: NODE_DOULBE_CHECK_GRACE_TIME
value: "5" # the grace time for double check before replacing node, in minutes, default is 3 minutes



您可以使用如下命令进行镜像构建,并将镜像推送到镜像仓库,例如 Amazon ECR
docker build -t npd-node-replace .
对于中国区用户,可以使用如下命令:
docker build -t npd-node-replace -f ./Dockerfile_cn .
- name: NODE_DOULBE_CHECK_GRACE_TIME
value: "5" # the grace time for double check before replacing node, in minutes, default is 3 minutes
npd-node-place 依赖 node-problem-detector 组件侦听事件,请先部署 node-problem-detector
Tolerance 配置中可以配置对于某些问题发生问题的容忍次数,示例配置:
{
"tolerancecollection": {
"OOMKill": {
"times": 2,
"action": "reboot",
"timewindowinminutes": 30
},
"KernelHang": {
"times": 3,
"action": "replace",
"timewindowinminutes": 60
}
}
}
使用该配置,可以实现在30分钟内触发两次 OOMKill 事件之后重启节点,在60分钟内触发三次 KernelOops 事件之后,替换节点。 由于事件为 Node Problem Detector 组件发出,关于所有支持的事件类型,可以参考 Node Problem Detector config Tolerance 配置字段解释:
"tolerancecollection": {
"OOMKill": { // 事件类型
"times": 2, // 在指定窗口期内发生的次数
"action": "reboot", // 对于某种事件类型发生次数超过阈值时,应该采取的操作
"timewindowinminutes": 30 // 时间窗口大小
},
根据您的 Tolerance 配置需要修改 tolerance configmap
npd-node-replace 组件需要结合 Amazon EC2、Amazon Autoscaling group 、Amazon SNS 服务,您需要为其配置权限。
建议通过 IRSA 的方式为 npd-node-replace pod 赋予 Amazon Web Services 权限。
修改 sevice account 配置清单,添加与 IAM role 的关联,如下,您需要将
apiVersion: v1
kind: ServiceAccount
metadata:
annotations:
eks.amazonaws.com/role-arn: <irsa iam role arn>
creationTimestamp: null
name: npd-node-replace-sa
namespace: kube-system
创建 IAM 策略,IAM role 最小权限如下:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Statement1",
"Effect": "Allow",
"Action": [
"ec2:RebootInstances",
"ec2:DescribeInstances",
"autoscaling:DetachInstances",
"sns:Publish"
],
"Resource": [
"*"
]
}
]
}
IRSA 的创建方式您可以参考: https://docs.amazonaws.cn/eks/latest/userguide/iam-roles-for-service-accounts.html
在 npd-node-replace-deployment.yaml 中您需要在 Deployment.spec.template.spec.env 的如下环境变量中添加 SNS Topic ARN:
- name: SNS_TOPIC_ARN
value: <amazon sns topic arn>
需要在如下 Deployment.spec.template.containers[“npd-node-replace”].image 部分替换为您之前创建的容器镜像 URL:
containers:
- image: <image_url>
name: npd-node-replace
kubectl apply -f config/crd/nodeissuereporter.xingzhan.io_nodeissuereports.yaml
kubectl apply -f deploy/npd-node-replace-clusterrole.yaml
kubectl apply -f deploy/npd-node-replace-clusterrolebinding.yaml
kubectl apply -f deploy/npd-node-replace-sa.yaml
kubectl apply -f deploy/tolerance-configmap.yaml
kubectl apply -f deploy/npd-node-replace-deployment.yaml
Helm package link : https://github.com/normalzzz/npd-node-replace/blob/main/deploy/npd-node-replace/npd-node-replace-0.1.2.tgz
- <sns topic arn> 修改为 EKS 集群账户中存在的 Amazon SNS Topic ARN
- npdNodeReplace.npdNodeReplace.image 中的 zxxxxzz/npd-node-replace:v1 镜像存在于 Docker 官方,如果在中国大陆遇到镜像无法拉取的问题,请将镜像转移到 Amazon ECR 并将该字段替换为 Amazon ECR 镜像 URL,详细操作步骤可以参考 [Amazon ECR 官方文档](https://docs.amazonaws.cn/AmazonECR/latest/userguide/docker-push-ecr-image.html)
- sa.serviceAccount.annotations 中 <IRSA IAM role arn> 请替换为 [IAM 权限配置](https://github.com/normalzzz/npd-node-replace?tab=readme-ov-file#iam-%E6%9D%83%E9%99%90%E9%85%8D%E7%BD%AE) 部分创建的 Amazon IAM Role ARN **通过 Helm chart 创建的 service account 所处的命名空间(namespace) 以及 service account name 会与您 helm install 时传入的 release name 和 namespace 参数相关,请检查 Amazon IAM role 的信任实体中的 service account 信息与您当前集群中的 service account 信息一致**
- toleranceConfig 部分请根据业务需求修改,参考[Tolerance 配置](https://github.com/normalzzz/npd-node-replace?tab=readme-ov-file#tolerance-%E9%85%8D%E7%BD%AE)部分
2. 安装 release:
`helm install <release_name> <Helm Chart Path> -n <namespace> -f values.yaml`
或
`helm install <my-release> oci://registry-1.docker.io/zxxxxzz/npd-node-replace --version 0.1.0`
3. 卸载 release:
`helm uninstall <release name> -n <namespace>`
# 测试:
可以使用如下方式注入实例系统问题:
OOMKilling 问题模拟:
```bash
echo "Killed process 1234 (myapp) total-vm:102400kB, anon-rss:51200kB, file-rss:2048kB" | sudo tee /dev/kmsg
KernelOops 问题模拟:
echo "<1>BUG: unable to handle kernel NULL pointer dereference at 0x00000000" | sudo tee /dev/kmsg
echo "<1>divide error: 0000 [#1] SMP" | sudo tee /dev/kmsg
根据仓库中的示例配置,在使用上述方式触发两次 OOMKilling 事件之后,会发生节点重启。 触发三次 KernelOops 事件之后,会发生节点替换。且在节点重启和替换之后,在 npd-node-replace-deployment.yaml 中配置的 SNS topic 会受到邮件提醒,通知节点发生过的历史问题。
[root@Test ~]# kubectl top pod npd-node-replace-5c67496ffd-gkg2w -n kube-system
NAME CPU(cores) MEMORY(bytes)
npd-node-replace-5c67496ffd-gkg2w 1m 7Mi
const (
ConditionTrue ConditionStatus = "True"
ConditionFalse ConditionStatus = "False"
ConditionUnknown ConditionStatus = "Unknown"
)