跳至内容

如何使用 Amazon EKS 中的 Cluster Autoscaler 对容器组调度问题进行故障排除?

2 分钟阅读
0

我在 Amazon Elastic Kubernetes Service (Amazon EKS) 中使用 Cluster Autoscaler 时遇到容器组调度问题。我的容器组处于 Pending(待处理)状态,或者我收到有关调度失败事件的通知。

解决方法

如果您激活了 Cluster Autoscaler 并且您的容器组处于 Pending(待处理)状态,则 Cluster Autoscaler 可能不会向计划外的容器组添加新节点。

检查容器组的状态

要检查您的容器组的状态,请运行以下 kubectl get pods 命令:

kubectl get pods -n kube-system -l app=cluster-autoscaler

如果容器组处于 Pending(待处理)状态或者您的容器组的容器处于 Waiting(等待)状态,请对容器组的状态进行故障排除

如果您的容器组处于 CrashLoopBackOff 状态,请运行以下 kubectl describe pod 命令:

kubectl describe pod cluster-autoscaler-####-#### -n kube-system

**注意:**将 cluster-autoscaler-####-#### 替换为您的 Cluster Autoscaler 容器组。

如果命令的输出显示“OOMKilled”(退出代码为 137),请增加您的内存资源限制和 cluster-autoscaler 部署请求。有关详细信息,请参阅 Kubernetes 网站上的 Specify a memory request and a memory limit(指定内存请求和内存限制)

要检查容器组日志,请运行以下 kubectl logs 命令:

kubectl logs -f -n kube-system -l app=cluster-autoscaler

日志可以提供故障排除信息。例如,容器组日志可能会显示以下“AccessDenied”错误消息:

“Failed to create AWS Manager: AccessDenied: User: arn:aws:sts::444455556666:assumed-role/your-role is not authorized to perform: your-action because no identity-based policy allows the your-action action”

要解决 AWS Identity and Access Management (IAM) 权限问题,请将正确的 IAM 策略附加到容器组。有关详细信息,请参阅 GitHub 网站上的 IAM policy(IAM 策略)

或者,日志可能会显示以下错误消息:

“Failed to create AWS Manager: cannot autodiscover ASGs: WebIdentityErr: failed to retrieve credentials caused by: RequestError: send request failed caused by: Post https://sts.region.amazonaws.com/: : dial tcp: i/o timeout”

如果您遇到网络连接问题,请验证您的 Worker 节点子网是否有通往以下 AWS 服务端点的路由:

  • ec2.region.amazonaws.com
  • autoscaling.region.amazonaws.com
  • sts.region.amazonaws.com

此外,请验证子网的网络访问控制列表(网络 ACL)或 Worker 节点安全组是否不会阻止流向前面端点的流量。

如果您的集群为私有,请执行以下操作:

  • 将上述端点添加到您的虚拟私有云 (VPC)。
  • 为端点配置安全组,以允许来自 Worker 节点安全组的端口 443 上的流量。

确定您的 Cluster Autoscaler 无法横向扩展自动扩缩组的原因

要检查您的容器组是否包含调度规则,例如关联性或反关联性,请运行以下 kubectl describe pod 命令:

kubectl describe pod pending-pod-name -n pending-pod-namespace

**注意:**将 pending-pod-name 替换为待处理容器组的名称,将 pending-pod-namespace 替换为待处理容器组的命名空间。有关详细信息,请参阅 Kubernetes 网站上的 Affinity and anti-affinity(关联性与反关联性)

在命令的输出中,查看 Events(事件)部分,以确定您的容器组卡滞在 Pending(待处理)状态的原因。例如,您可能会发现节点组标签存在问题。

为确保您的节点组正常运行,请执行以下操作:

  • 使用与容器组的 nodeAffinity 规范中的 nodeSelectorrequiredDuringSchedulingIgnoredDuringExecution 设置相匹配的标签来配置节点组。有关详细信息,请参阅 Kubernetes 网站上的 Node labels(节点标签)。正确的标签允许 Cluster Autoscaler 识别符合扩展操作条件的节点。
  • 确保您已正确定义容器组调度规则。有关详细信息,请参阅 Kubernetes 网站上的 Assigning Pods to nodes(将容器组分配给节点)。当容器组使用 nodeSelectorrequiredDuringSchedulingIgnoredDuringExecution 时,Cluster Autoscaler 只考虑扩展符合这些设置调度要求的节点组。

要检查 Cluster Autoscaler 配置,请运行以下 kubectl get deployment 命令:

kubectl get deployment cluster-autoscaler -n kube-system -o yaml

如果 Cluster Autoscaler 具有正确的 node-group-auto-discovery 参数,则该命令的输出显示以下配置:

command:
  - ./cluster-autoscaler
  - --v=4
  - --stderrthreshold=info
  - --cloud-provider=aws
  - --skip-nodes-with-local-storage=false
  - --expander=least-waste
  - --node-group-auto-discovery=asg:tag=k8s.io/cluster-autoscaler/enabled,k8s.io/cluster-autoscaler/your-cluster-name

检查自动扩缩组是否具有正确的标签

Cluster Autoscaler 需要以下标签才能发现与节点组关联的自动扩缩组:

Tag 1:
key: k8s.io/cluster-autoscaler/your-cluster-name
value: owned

Tag 2:
key: k8s.io/cluster-autoscaler/enabled
value: true

要检查节点组是否达到最大节点数,请运行以下 describe-nodegroup 命令:

aws eks describe-nodegroup --cluster-name your-cluster-name --nodegroup-name your-nodegroup-name

**注意:**将 your-cluster-name 替换为您的集群名称,将 your-nodegroup-name 替换为您的节点组的名称。

如果节点组达到最大节点数,请更新节点组以增加最大节点数。然后,新节点可以调度新容器组。

检查您的自动扩缩组启动的 Amazon Elastic Compute Cloud (Amazon EC2) 实例是否可以加入您的集群。如果该实例无法加入您的集群,请对您的 Worker 节点进行故障排除

要检查容器组资源请求,请运行以下 kubectl get pod 命令:

kubectl get pod pending-pod-name -n pending-pod-namespace -o yaml | grep resources -A6

**注意:**将 pending-pod-name 替换为待处理容器组的名称,将 pending-pod-namespace 替换为待处理容器组命名空间的名称。

检查当前节点实例类型是否满足容器组资源请求,并在需要时修改容器组资源请求。或者,使用修改后的实例类型创建新的节点组。有关容器组资源请求的详细信息,请参阅 Kubernetes 网站上的 容器组和容器的资源管理

要查看节点的污点,请运行以下 kubectl describe node 命令:

kubectl describe node your-node-name

**注意:**将 your-node-name 替换为您的节点名称。

确保您的容器组能容忍你添加到节点的污点。如果节点不需要污点,请从节点中移除污点。有关详细信息,请参阅 Kubernetes 网站上的污点和容忍度

相关信息

GitHub 网站上的 Frequently asked questions(常见问题解答)

AWS 官方已更新 2 个月前