跳至内容

如何对在 Amazon EKS 集群上设置 Cluster Autoscaler 时出现的问题进行故障排除?

5 分钟阅读
0

我想对在 Amazon Elastic Kubernetes Service (Amazon EKS) 集群上启动 Cluster Autoscaler 时出现的问题进行故障排除。

解决方法

**注意:**如果您在运行 AWS 命令行界面 (AWS CLI) 命令时收到错误,请参阅 AWS CLI 错误故障排除。此外,请确保您使用的是最新版本的 AWS CLI

以下解决方法中的命令不使用 --region 标志,因为它们使用默认的 AWS 区域。要查看您的默认区域,请运行以下 AWS CLI configure 命令:

aws configure

要更改区域,请使用 --region 标志。

**先决条件:**安装或更新 eksctl 到最新版本。有关说明,请参阅 eksctl 网站上的安装

根据您遇到的问题执行以下故障排除操作。要对探测问题进行故障排除,请参阅如何排查我的 Amazon EKS 集群的存活和就绪探测问题?

Cluster Autoscaler 容器组处于 "CrashLoopBackOff" 状态

要对 "CrashLoopBackOff" 状态进行故障排除,请完成以下步骤:

  1. 要检查 Cluster Autoscaler 容器组的状态,请运行以下命令:

    kubectl get pods -n kube-system | grep cluster-autoscaler

    输出示例:

    NAME                            READY   STATUS             RESTARTS      AGE
    cluster-autoscaler-abcd-abcd   0/1     CrashLoopBackOff   3 (20s ago)   99s
  2. 要详细了解容器组卡在 "CrashLoopBackOff" 状态的原因,请运行以下命令:

    kubectl describe pod cluster-autoscaler-abcd-abcde -n kube-system

    **注意:**请将 cluster-autoscaler-abcd-abcde 替换为 Cluster Autoscaler 容器组的名称。
    在输出中,查看 Reason(原因)的值。如果您看到 OOMKilled 问题,请使用 kubectl edit 命令来增加 Cluster Autoscaler 部署中内存资源的 limitsrequests 值。有关 kubectl edit 的详细信息,请参阅 Kubernetes 网站上的 kubectl edit。要查看 Cluster Autoscaler 的默认内存值,请参阅 GitHub 网站上的 cluster-autoscaler-autodiscover.yaml
    输出示例:

    Name:               cluster-autoscaler-abcd-abcde
    Namespace:          kube-system
    State:              Waiting
    Reason:             CrashLoopBackOff
    Last State:         Terminated
    Reason:             OOMKilled
    Exit Code:          137
    ...
  3. 要检查 Cluster Autoscaler 容器组日志中是否存在问题,请运行以下命令:

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

    如果日志显示存在 AWS Identity and Access Management (IAM) 权限问题,请继续查看“Cluster Autoscaler 容器组存在 IAM 权限问题”部分。输出示例:

    Failed to create AWS Manager: cannot autodiscover ASGs: AccessDenied: User: abc is not authorized to perform: autoscaling: DescribeTags because no identity-based policy allows the autoscaling:DescribeTags action status code: 403, request id: abcdexyz

    如果日志显示存在 I/O 超时等网络问题,请继续查看“Cluster Autoscaler 容器组存在网络问题”部分。输出示例:

    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

Cluster Autoscaler 容器组存在 IAM 权限问题

检查您是否已将 OIDC 提供商与集群关联

确保您已为集群创建了 OpenID Connect (OIDC) 提供商

检查您是否已使用 IAM 角色为 Cluster Autoscaler 服务账户添加了注释

要查看您的 AWS 服务账户注释,请运行以下命令:

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

检查注释,确保输出中列出了您的 Cluster Autoscaler 服务账户角色。输出示例:

apiVersion: v1
kind: ServiceAccount
metadata:
  annotations:
    eks.amazonaws.com/role-arn: arn:aws:iam::012345678912:role/cluster_auto_scaler_iam_role
  name: cluster-autoscaler
  namespace: kube-system

要对服务账户角色相关问题进行故障排除,请参阅如何对 Amazon EKS 中的 OIDC 提供商和 IRSA 问题进行故障排除?

检查 IAM 策略

确保您已将正确的 IAM 策略附加到 Cluster Autoscaler 服务账户角色。有关示例策略和所需权限列表,请参阅 GitHub 网站上的 IAM 策略

检查您是否正确配置了信任关系

确保您已正确配置信任关系。信任关系示例:

{  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "Federated": "arn:aws:iam::example_awsaccountid:oidc-provider/oidc.eks.example_region.amazonaws.com/id/example_oidcid"
      },
      "Action": "sts:AssumeRoleWithWebIdentity",
      "Condition": {
        "StringEquals": {
          "oidc.eks.example_region.amazonaws.com/id/example_oidcid:aud": "sts.amazonaws.com",
          "oidc.eks.example_region.amazonaws.com/id/example_oidcid:sub": "system:serviceaccount:kube-system:cluster-autoscaler"
        }
      }
    }
  ]
}

**注意:**请将 example_awsaccountid 替换为您的 AWS 账户 ID,将 example_region 替换为您的区域,将 example_oidcid 替换为您的 OIDC ID。

每次更改服务账户角色或策略时,请运行以下命令重启 Cluster Autoscaler 容器组:

kubectl rollout restart deployment cluster-autoscaler -n kube-system

Cluster Autoscaler 容器组存在网络问题

确保您已为 Amazon EKS 集群配置了所需的网络设置。验证 Worker 节点子网是否具有可以将流量路由到以下端点的路由表:

如果 Amazon EKS 集群是私有集群,则您必须为上述端点创建 Amazon Virtual Private Cloud (Amazon VPC) 端点

**注意:**每个 VPC 端点的安全组都必须允许 Amazon EKS Worker 节点安全组的访问。这些安全组还必须允许入站流量通过端口 443 流向 Amazon EKS VPC CIDR 块。

确保子网的网络访问控制列表(网络 ACL)以及 Worker 节点的安全组未阻止与这些端点通信的流量。

Cluster Autoscaler 无法横向缩减或横向扩展节点

查看 Cluster Autoscaler 容器组日志以了解调度规则

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

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

要检查处于待处理状态的容器组是否包含调度规则(如关联性规则),请运行以下命令:

kubectl describe pod example_podname -n example_namespace

**注意:**请将 example_podname 替换为容器组名称,将 example_namespace 替换为您的命名空间。

在输出中,查看事件部分,以了解有关容器组为何处于待处理状态的信息。输出示例:

$ kubectl describe pod cluster-autoscaler-abcde-abcd -n kube-system
Name: cluster-autoscaler-5b6b675456-npf8p
...
Status: Pending
...
Events:
 Type Reason Age From Message
 ---- ------ ---- ---- -------
 Warning FailedScheduling 12s (x4 over 2m) default-scheduler 0/4 nodes are available: 1 node(s) didn't match node selector, 3 node(s) didn't match pod affinity rules.

**注意:**Cluster Autoscaler 遵循 nodeSelector 以及 nodeAffinity 中的 requiredDuringSchedulingIgnoredDuringExecution 规则。请务必使用这些值标记您的节点组。要标记您的节点组,请运行以下命令:

kubectl get nodes --show-labels

如果 Cluster Autoscaler 无法通过 nodeSelectorrequiredDuringSchedulingIgnoredDuringExecution 来调度容器组,则 Cluster Autoscaler 仅会使用满足扩展要求的节点组。要在节点上调度容器组,您必须修改在容器组或节点上定义的调度规则。有关详细信息,请参阅 Kubernetes 网站上的关联性与反关联性

检查 Cluster Autoscaler 的 Amazon EC2 Auto Scaling 组标记

要让 Cluster Autoscaler 能够发现自动扩缩组,您必须使用以下标签标记节点组的 Amazon EC2 Auto Scaling 组

对于标签 1,请配置以下值:

  • 对于 key(键),输入 k8s.io/cluster-autoscaler/example-cluster
  • 对于 value(值),输入 owned

**注意:**请将 example-cluster 替换为您的集群名称。

对于标签 2,请配置以下值:

  • 对于 key(键),输入 k8s.io/cluster-autoscaler/enabled
  • 对于 value(值),输入 true

检查部署清单的配置

要打开部署清单,请运行以下命令:

kubectl -n kube-system edit deployment.apps/cluster-autoscaler

在输出中,对于 node-group-auto-discover,确保清单列出了正确的集群或节点组名称。输出示例:

containers:- 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/example-cluster
   --balance-similar-node-groups
   --skip-nodes-with-system-pods=false

确保不超过最大节点数

要查看当前的节点数量,请运行以下 describe-nodegroup 命令:

aws eks describe-nodegroup --cluster-name example-cluster --nodegroup-name example-nodegroup

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

如果已达到最小或最大节点数,请运行以下 update-nodegroup-config 命令来修改这些值:

aws eks update-nodegroup-config \
    --cluster-name cluster-name \
    --nodegroup-name nodegroup-name \
    --scaling-config minSize=minvalue,maxSize=maxvalue,desiredSize=desiredvalue \

**注意:**请将 cluster-name 替换为您的集群名称,将 nodegroup-name 替换为您的节点组名称。此外,请将 minvalue 替换为最小节点数,将 maxvalue 替换为最大节点数,将 desiredvalue 替换为所需的节点值。

确保您的节点可以加入集群

检查 Amazon EC2 Auto Scaling 组启动的新实例是否可以加入 Amazon EKS 集群。如果不能,请参阅如何让我的 Worker 节点加入我的 Amazon EKS 集群?

确保使用正确的节点实例类型

要检查 Cluster Autoscaler 当前使用的节点实例类型是否可以满足容器组的资源请求,请运行以下命令:

kubectl -n example_namespace get pod example_podname -o yaml | grep resources -A6

**注意:**请将 example-cluster 替换为您的集群名称,将 example-podname 替换为您的容器组名称。

输出示例:

 containers:
        - image: registry.k8s.io/autoscaling/cluster-autoscaler:v1.32.1
          name: cluster-autoscaler
          resources:
            limits:
              cpu: 100m
              memory: 600Mi
            requests:
              cpu: 100m
              memory: 600Mi

在输出中,检查 limitsrequests 的值。确保 cpumemory 值足够高,以便节点能够保留容器组。要查看您的容器组需求,请运行以下命令:

kubectl describe pod podname -n namespace,

**注意:**请将 podname 替换为您的容器组名称,将 namespace 替换为您的命名空间。

如果容器组需求高于节点的承载能力,请使用 kubectl edit 命令来增加 Cluster Autoscaler 部署中内存资源的 limitsrequests 值。或者,创建一个使用不同实例类型的新节点组,以满足容器组的资源需求。有关 kubectl edit 的详细信息,请参阅 Kubernetes 网站上的 kubectl edit

检查节点组中节点的污点配置

要检查您是否为节点配置了污点,以及容器组是否可以容忍这些污点,请运行以下命令:

kubectl describe node example_nodename | grep taint -A2

**注意:**请将 example_nodename 替换为您的节点名称。

如果您已配置污点,请移除节点上定义的这些污点。有关步骤,请参阅如何对 Amazon EKS 中的容器组状态进行故障排除?中的您的容器组处于待处理状态如果容器组无法容忍污点,请在容器组上定义容忍度。有关详细信息,请参阅 Kubernetes 网站上的污点和容忍度

确保节点未停用缩减功能

要检查节点上 scale-down-disable 的状态,请运行以下命令:

kubectl describe node example_nodename | grep scale-down-disable

**注意:**请将 example_nodename 替换为您的节点名称。

输出示例:

cluster-autoscaler.kubernetes.io/scale-down-disabled: true

如果 scale-down-disable 设置为 true,请运行以下命令移除该节点的注释,以允许其进行缩减:

kubectl annotate node example_nodename cluster-autoscaler.kubernetes.io/scale-down-disabled-

**注意:**请将 example_nodename 替换为您的节点名称。

有关 Cluster Autoscaler 的更多故障排除步骤,请参阅 GitHub 网站上的常见问题

AWS 官方已更新 7 个月前