如何排查设置 Amazon EKS 集群上的 Cluster Autoscaler 时出现的问题?

4 分钟阅读
0

我想排查启动 Amazon Elastic Kubernetes Service(Amazon EKS)集群上的 Cluster Autoscaler 时遇到的问题。

简短描述

在开始之前,请确保验证以下各项:

  • 您已安装 eksctl 或更新到最新版本。
  • 您已将代码片段中的占位符值替换为自己的值。

注意:****--region 变量并不能一直在命令中使用,因为使用的是您的 AWS 区域的默认值。通过运行 AWS 命令行界面(AWS CLI)配置命令来检查此默认值。如果您需要更改 AWS 区域,请使用 --region 标记。

**注意:**如果您在运行 AWS CLI 命令时收到错误,请确认您正在运行最新版本的 AWS CLI

解决方法

集群 Autoscaler 容器组(pod)处于 CrashLoopBackOff 状态

运行以下命令检查 Cluster Autoscaler 容器组(pod)状态:

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

以下是处于 CrashLoopBackOff 状态的 Cluster Autoscaler 容器组(pod)示例:

NAME                            READY   STATUS             RESTARTS      AGE
cluster-autoscaler-xxxx-xxxxx   0/1     CrashLoopBackOff   3 (20s ago)   99s

运行以下命令查看 Cluster Autoscaler 容器组(pod)日志:

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

如果日志表明存在 AWS Identity and Access Management(IAM)权限问题,请执行以下操作:

  • 检查 OIDC 提供程序是否与 Amazon EKS 集群相关联。
  • 检查 Cluster Autoscaler 服务账户是否以 IAM 角色来注释。
  • 检查上述 IAM 角色是否附加了正确的 IAM policy。
  • 检查信任关系是否配置正确。

**注意:**以下是指示 IAM 权限问题的日志示例:

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

重要提示:请务必检查所有给定的 AWS CLI 命令,并将示例字符串的所有实例替换为您的值。例如,将 example-cluster 替换为您的集群。

检查 OIDC 提供程序是否与 EKS 集群相关联

1.    运行以下命令,检查您的集群上是否已经有 IAM OpenID Connect(OIDC)提供程序

oidc_id=$(aws eks describe-cluster --name example-cluster --query "cluster.identity.oidc.issuer" --output text | cut -d '/' -f 5)

2.    运行以下命令,检查您的账户中是否存在带您的集群 ID 的 IAM OIDC 提供程序:

aws iam list-open-id-connect-providers | grep $oidc_id | cut -d "/" -f4

**注意:**如果返回了输出,则表明您的集群已经有 IAM OIDC 提供程序,您可以跳过下一步。如果未返回任何输出,则您必须在下一步为您的集群创建 IAM OIDC 提供程序。

3.    通过运行以下命令为您的集群创建 IAM OIDC 身份提供程序:

eksctl utils associate-iam-oidc-provider --cluster example-cluster --approve

检查 Cluster Autoscaler 服务账户是否以 IAM 角色来注释

通过运行以下命令,检查服务账户是否以 IAM 角色来注释:

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

以下是预期结果:

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

检查上述 IAM 角色是否附加了正确的 IAM policy

请参阅以下示例:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "VisualEditor0",
      "Effect": "Allow",
      "Action": [
        "autoscaling:DescribeAutoScalingInstances",
        "autoscaling:SetDesiredCapacity",
        "autoscaling:DescribeAutoScalingGroups",
        "autoscaling:DescribeTags",
        "autoscaling:DescribeLaunchConfigurations",
        "ec2:DescribeLaunchTemplateVersions",
        "ec2:DescribeInstanceTypes",
        "autoscaling:TerminateInstanceInAutoScalingGroup"
      ],
      "Resource": "*"
    }
  ]
}

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

请参阅以下示例:

{
  "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"
        }
      }
    }
  ]
}

对服务账户角色或 IAM policy 进行任何更改后,重新启动 Cluster Autoscaler 容器组(pod)。

如果日志显示任何联网问题(例如,I/O 超时),请执行以下操作:

**注意:**以下是表示存在联网问题的日志示例:

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

1.    检查 Amazon EKS 集群是否配置了所需的联网设置。验证 Worker 节点子网是否有路由表,其可以将流量路由到以下端点,无论是全球还是区域端点

  • Amazon Elastic Compute Cloud(Amazon EC2)
  • AWS Auto Scaling
  • AWS Security Token Service(AWS STS)

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

3.    如果 Amazon EKS 集群为私有,请检查相关的 Amazon Virtual Private Cloud(VPC)端点的设置。例如,Amazon EC2、AWS Auto Scaling 和 AWS STS。

**注意:**每个 VPC 端点都需要此安全组,以允许 Amazon EKS Worker 节点安全组。还需要允许入口流量 443 端口上的 Amazon EKS VPC CIDR 数据块。

Cluster Autoscaler 没有缩减或扩展节点

如果您的 Cluster Autoscaler 没有缩减或扩展节点,请检查以下内容:

  • 检查 Cluster Autoscaler 容器组(pod)日志。
  • 检查 Cluster Autoscaler 的自动扩缩组标记。
  • 检查部署清单的配置。
  • 检查当前节点数量。
  • 检查容器组(pod)资源请求。
  • 检查节点组中节点的污点配置。
  • 检查节点是否使用了“禁止缩减”注释。

检查 Cluster Autoscaler 容器组(pod)日志

要查看容器组(pod)日志并确定您的 Cluster Autoscaler 没有缩减或扩展节点的原因,请运行以下命令:

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

通过运行以下“描述容器组(pod)”命令,检查处于待处理状态的容器组(pod)是否包含任何调度规则,例如关联性规则:

kubectl describe pod <example_podname> -n <example_namespace>

查看输出中的 events(事件)部分。本部分介绍了有关容器组(pod)为何处于待处理状态的信息。

**注意:**假设您相应地标记了节点组,那么 Cluster Autoscaler 会遵守 nodeAffinity 中的 nodeSelectorrequiredDuringSchedulingIgnoredDuringExecution。如果容器组(pod)无法使用 nodeSelectorrequiredDuringSchedulingIgnoredDuringExecution 进行调度,则 Cluster Autoscaler 仅考虑满足这些扩展要求的节点组。相应地修改在容器组(pod)或节点上定义的调度规则,以便将容器组(pod)调度到节点上。

检查 Cluster Autoscaler 的自动扩缩组标记

必须标记节点组的相应自动扩缩组,以便 Cluster Autoscaler 发现自动扩缩组,如下所示:

标签 1:

  • 键:k8s.io/cluster-autoscaler/example-cluster
  • 值:owned

标签 2:

  • 键:k8s.io/cluster-autoscaler/enabled
  • 值:true

检查部署清单的配置

要检查 Cluster Autoscaler 部署清单的配置,请运行以下命令:

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

检查清单配置的 node-group-auto-discovery 参数是否正确,如下所示:

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

检查当前节点数量

要检查当前节点数是否已达到托管节点组的最小值或最大值,请运行以下命令:

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

如果已达到最小值或最大值,则根据新的工作负载要求修改这些值。

检查容器组(pod)资源请求

要查看当前节点实例类型是否无法满足容器组(pod)资源请求,请运行以下命令:

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

要完成资源请求,请修改容器组(pod)资源请求或创建新的节点组。创建新的节点组时,请确保节点的实例类型可以满足容器组(pod)的资源需求。

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

通过运行以下命令,检查是否为该节点配置了污点,以及容器组(pod)是否可以容忍这些污点:

kubectl describe node <example_nodename> | grep taint -A2

如果配置了污点,则移除节点上定义的污点。如果容器组(pod)无法容忍污点,则定义容器组(pod)的容忍度,以便容器组(pod)调度到有污点的节点上。

检查节点是否使用了“禁止缩减”注释

要检查节点是否使用了禁止缩减注释,请运行以下命令:

kubectl describe node <example_nodename> | grep scale-down-disable

以下是预期结果:

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

如果禁止缩减设置为 true,则通过运行以下命令,删除节点的注释以便进行缩减:

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

有关故障排除的更多信息,请参阅 GitHub 网站上的 Cluster Autoscaler 常见问题解答


AWS 官方
AWS 官方已更新 1 年前