跳至內容

如何對在 Amazon EKS 叢集上設定 Cluster Autoscaler 時,出現的問題進行疑難排解?

5 分的閱讀內容
0

我想對在 Amazon Elastic Kubernetes Service (Amazon EKS) 叢集上啟動 Cluster Autoscaler 時,出現的問題進行疑難排解。

解決方法

**注意:**如果您在執行 AWS Command Line Interface (AWS CLI) 命令時收到錯誤訊息,請參閱對 AWS CLI 錯誤進行疑難排解。此外,請確定您使用的是最新的 AWS CLI 版本

以下解決方案中的命令不使用 --region 旗標,因其使用的是預設的 AWS 區域。若要檢查您預設的區域,請執行以下 AWS CLI 的 configure 命令:

aws configure

若要變更區域,請使用 --region 旗標。

**先決條件:**安裝或更新 eksctl 到最新版本。如需說明,請參閱 eksctl 網站上的安裝

根據您遇到的問題採取以下疑難排解措施。若要對探查問題進行疑難排解,請參閱如何對 Amazon EKS 叢集的活躍度和準備度探查問題進行疑難排解?

Cluster Autoscaler Pod 處於「CrashLoopBackOff」狀態

若要對 「CrashLoopBackOff」 狀態進行疑難排解,請完成下列步驟:

  1. 若要檢查 Cluster Autoscaler Pod 狀態,請執行以下命令:

    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. 若要深入了解 Pod 為何卡在 「CrashLoopBackOff」 狀態的原因,請執行以下命令:

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

    **注意:**將 cluster-autoscaler-abcd-abcde 替換為 Cluster Autoscaler Pod 的名稱。
    在輸出中,檢查 Reason (原因) 的值。如果您發現 OOMKilled 問題,請使用 kubectl edit 命令增加 Cluster Autoscaler 部署中記憶體資源的 limits (限制) 和 requests (請求) 值。如需 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 Pod 日誌中的問題,請執行以下命令:

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

    如果日誌顯示有 AWS Identity and Access Management (IAM) 權限問題,請前往Cluster Autoscaler Pod 存在 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 Pod 存在網路問題進行後續處理。輸出範例:

    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 Pod 有 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 Pod:

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

Cluster Autoscaler Pod 有網路問題

確保您已為 Amazon EKS 叢集設定了所需的網路設定。確認工作節點子網路的路由表可將流量路由至以下端點

如果 Amazon EKS 叢集是私有的,則必須為前述端點建立 Amazon Virtual Private Cloud (Amazon VPC) 端點

**注意:**每個 VPC 端點的安全群組必須允許 Amazon EKS 工作節點的安全群組通行。安全群組還必須允許傳入流量進入連接埠 443 上的 Amazon EKS VPC CIDR 區塊。

確認子網路網路存取控制清單 (網路 ACL) 和工作節點安全群組沒有阻擋與這些端點通訊的流量。

Cluster Autoscaler 不會縮減或擴展節點

檢查 Cluster Autoscaler Pod 日誌中的排程規則

若要檢查 Pod 的狀態,請執行以下命令:

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

若要檢查處於擱置中狀態的 Pod 是否包含排程規則 (例如親和性規則),請執行下列命令:

kubectl describe pod example_podname -n example_namespace

**注意:**將 example_podname 替換為 Pod 名稱,並將 example_namespace 替換為您的命名空間。

在輸出中,檢查事件區段,以了解 Pod 處於擱置中狀態的原因。輸出範例:

$ 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 遵循 nodeSelectornodeAffinity 中的 requiredDuringSchedulingIgnoredDuringExecution。請務必為您的節點群組加上這些標籤。若要為您的節點群組加上標籤,請執行以下命令:

kubectl get nodes --show-labels

如果 Cluster Autoscaler 無法使用 nodeSelectorrequiredDuringSchedulingIgnoredDuringExecution 排程 Pod,則 Cluster Autoscaler 只會使用符合擴充要求的節點群組。若要在節點上排程 Pod,您必須修改 Pod 或節點上定義的排程規則。如需詳細資訊,請參閱 Kubernetes 網站上的親和性和反親和性

檢查 Cluster Autoscaler 的 Amazon EC2 Auto Scaling 群組標記

若要讓 Cluster Autoscaler 發現 Auto Scaling 群組,您必須使用下列標籤標記節點群組的 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 叢集。如果不能,請參閱如何讓我的工作節點加入 Amazon EKS 叢集?

確保使用正確的節點執行個體類型

若要檢查 Cluster Autoscaler 是否能以目前的節點執行個體類型滿足 Pod 資源需求,請執行下列命令:

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

**注意:**將 example-cluster 替換為您的叢集名稱,並將 example-podname 替換為您的 Pod 名稱。

輸出範例:

 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

在輸出中,檢查 limits (限制) 和 requests (請求) 的值。確保 cpumemory (記憶體) 值夠高,以讓節點能容納該 Pod。若要查看 Pod 需求,請執行以下命令:

kubectl describe pod podname -n namespace,

**注意:**將 podname 替換為您的 Pod 名稱,並將 namespace 替換為您的命名空間。

如果 Pod 的需求高於節點的能力,請使用 kubectl edit 命令增加 Cluster Autoscaler 部署中記憶體資源的 limits (限制) 和 requests (請求) 值。或者,建立一個具有不同執行個體類型的新節點群組,以滿足 Pod 的資源需求。如需 kubectl edit 的詳細資訊,請參閱 Kubernetes 網站上的 kubectl edit

檢查節點群組中節點的污點組態

若要檢查您是否為節點設定了污點,以及 Pod 是否能容忍這些污點,請執行以下命令:

kubectl describe node example_nodename | grep taint -A2

**注意:**將 example_nodename 替換為您的節點名稱。

如果您設定了污點,請將節點上定義的污點移除。如需步驟,請參閱如何對 Amazon EKS 中的 Pod 狀態問題進行疑難排解?中的您的 Pod 處於擱置中狀態如果 Pod 不能容忍污點,請在 Pod 上定義容忍度。如需更多資訊,請參閱 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 官方已更新 9 個月前