跳至內容

如何對 Amazon EKS 中 (Cluster Autoscaler 的 Pod 排程問題進行疑難排解?

3 分的閱讀內容
0

當我在 Amazon Elastic Kubernetes Service (Amazon EKS) 中使用 Cluster Autoscaler 時,遇到 Pod 排程問題。我的 Pod 卡在「擱置」狀態,或我收到排程失敗事件的通知。

解決方法

如果您已啟用 Cluster Autoscaler,且您的 Pod 卡在 Pending (擱置中) 狀態,則 Cluster Autoscaler 可能無法為未排程的 Pod 新增節點。

檢查 Pod 的狀態

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

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

如果 Pod 處於 Pending (擱置中) 狀態,或您的 Pod 容器處於 Waiting (等待中) 狀態,請對 Pod 狀態進行疑難排解

如果您的 Pod 處於 CrashLoopBackOff 狀態,請執行以下 kubectl 描述 Pod 命令:

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

**注意:**將 cluster-autoscaler-####-#### 替換為您的 Cluster Autoscaler Pod。

如果命令輸出顯示「OOMKilled」且退出代碼為 137,請增加 cluster-autoscaler 部署的記憶體資源限制與請求。如需更多資訊,請參閱 Kubernetes 網站上的指定記憶體請求與記憶體限制

若要檢查 Pod 日誌,請執行以下 kubectl 日誌命令:

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

日誌可提供疑難排解資訊。例如,Pod 日誌可能顯示以下「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 政策附加至 Pod。如需更多資訊,請參閱 GitHub 網站上的 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」

如果您遇到網路連線問題,請確認您的工作節點子網路是否具有通往以下 AWS 服務端點的路由:

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

同時,請確認您的子網路網路存取控制清單 (網路 ACL) 或工作節點安全群組未封鎖通往上述端點的流量。

如果您的叢集是私有,請執行以下動作:

  • 將上述端點新增至您的虛擬私有雲端 (VPC)。
  • 為端點設定安全群組,允許來自工作節點安全群組的 443 連接埠流量。

確認 Cluster Autoscaler 無法向外擴展 Auto Scaling 群組的原因

若要檢查您的 Pod 是否包含排程規則 (例如親和性或反親和性),請執行以下 kubectl 描述 Pod 命令:

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

**注意:**將 pending-pod-name 替換為您擱置中 Pod 的名稱,並將 pending-pod-namespace 替換為您擱置中 Pod 的命名空間。如需詳細資訊,請參閱 Kubernetes 網站上的親和性和反親和性

在命令輸出結果中,查看 Events (事件) 區段,以判斷您的 Pod 卡在 Pending (擱置中) 狀態的原因。例如,您可能會發現節點群組標籤有問題。

為確保節點群組正常運作,請執行以下動作:

  • 使用與 Pod 的 nodeAffinity 規格中 nodeSelectorrequiredDuringSchedulingIgnoredDuringExecution 設定相符的標籤,設定您的節點群組。如需更多資訊,請參閱 Kubernetes 網站上的節點標籤。正確的標籤可讓 Cluster Autoscaler 辨識可用於擴展作業的合格節點。
  • 請確定您已正確定義 Pod 的排程規則。如需更多資訊,請參閱 Kubernetes 網站上的將 Pod 指派至節點。當 Pod 使用 nodeSelectorrequiredDuringSchedulingIgnoredDuringExecution 時,Cluster Autoscaler 只會考慮擴展那些符合這些設定排程條件的節點群組。

若要檢查 Cluster Autoscaler 組態,請執行以下 kubectl 取得部署命令:

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

檢查 Auto Scaling 群組是否具有正確標籤

Cluster Autoscaler 需要以下標籤以探索與節點群組關聯的 Auto Scaling 群組:

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 替換為您的節點群組名稱。

如果節點群組已達最大節點數,請更新節點群組以增加最大節點數。接著,新節點即可排程新的 Pod。

檢查 Auto Scaling 群組啟動的 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體是否能加入您的叢集。如果執行個體無法加入叢集,請對工作節點進行疑難排解

若要檢查 Pod 資源請求,請執行以下 kubectl 取得 Pod 命令:

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

**注意:**將 pending-pod-name 替換為擱置中 Pod 的名稱,並將 pending-pod-namespace 替換為擱置中 Pod 的命名空間。

檢查目前的節點執行個體類型是否符合 Pod 資源請求,並在需要時修改 Pod 資源請求。或者,建立新的節點群組,並使用修改後的執行個體類型。如需更多 Pod 資源請求的資訊,請參閱 Kubernetes 網站上的 Pod 與容器的資源管理

若要檢視節點的汙點,請執行以下 kubectl 描述節點命令:

kubectl describe node your-node-name

**注意:**將 your-node-name 替換為您的節點名稱。

請確定您的 Pod 能容忍您新增至節點的汙點。如果節點不需要這些汙點,請將其從節點中移除。如需詳細資訊,請參閱 Kubernetes 網站上的污點和容忍度

相關資訊

GitHub 網站上的常見問題

AWS 官方已更新 2 個月前