Help us improve the AWS re:Post Knowledge Center by sharing your feedback in a brief survey. Your input can influence how we create and update our content to better support your AWS journey.
如何解決在 Amazon EKS 中升級叢集版本時出現的 API 錯誤?
我收到錯誤或警告狀態,提示我的叢集使用了已棄用的 API,我需要在下次升級之前修正 API。
簡短描述
在叢集版本升級期間,Amazon EKS 主控台中的「升級洞察」索引標籤會顯示各種 Kubernetes 元件的狀態。在不同元件的升級過程中,您會看到以下狀態:
- 錯誤狀態表示叢集升級後拒絕參考特定 API 版本的呼叫。
- 警告狀態表示存在問題,但無須立即採取行動。當計劃在比目前叢集版本至少舊 2 個版本的版本中移除 Kubernetes 資源時,就可能會出現此狀態。
- 通過狀態表示元件已通過所有升級檢查和驗證。無需採取任何行動。
- 未知狀態表示升級系統無法確定元件的狀態,這可能是因為缺乏足夠的資訊,或是在升級過程中處於不確定的狀態所致。您可能需要採取行動。
在升級叢集之前,請檢查狀態為錯誤或警告的元件,以了解並解決所有問題。
解決方法
**注意:**如果您在執行 AWS Command Line Interface (AWS CLI) 命令時收到錯誤訊息,請參閱對 AWS CLI 錯誤進行疑難排解。此外,請確定您使用的是最新的 AWS CLI 版本。
檢查 API 的狀態
使用 AWS 管理主控台或 AWS CLI 檢查叢集中已棄用 API 的狀態。
AWS 管理主控台
請完成下列步驟:
- 開啟 Amazon EKS 主控台。
- 選取您的叢集名稱。
- 在 Cluster info (叢集資訊) 中,選擇 Upgrade insights (升級洞察)。
- 查看 Insight status (洞察狀態) 下所有已棄用的 API 警告或錯誤訊息。
AWS CLI
若要列出 YAML 檔案中的所有升級洞察詳細資訊,請執行以下命令:
[+] aws eks list-insights --cluster-name your-cluster-name --region your-region-name --output yaml >> insight.yaml
**注意:**將 your-cluster-name 和 your-region-name 替換為您叢集中的值。
以您偏好的檔案格式儲存輸出結果。
若要篩選洞察以只顯示錯誤,請執行以下命令:
[+] aws eks list-insights --cluster-name your-cluster-name --region your-region-name --filter categories=UPGRADE_READINESS,statuses=ERROR
**注意:**將 your-cluster-name 和 your-region-name 替換為您叢集中的值。
輸出結果會以文字格式儲存。
解決已棄用的 API 狀態錯誤
如果 Upgrade insights (升級洞察) 索引標籤的狀態顯示您的叢集具有已棄用的 API,您可能會收到錯誤。例如,如果發生 Pod 中斷預算 (PDB) API 錯誤,您可能會收到以下訊息:
"EKS using deprecated api version "/apis/policy/v1beta1/poddisruptionbudgets" and needs to replace it with "/apis/policy/v1/poddisruptionbudgets" before upgrading EKS cluster."
若要解決該錯誤,請完成下列步驟:
-
執行以下命令列出叢集使用的 PDB:
kubectl get pdb -A -
執行以下命令查看輸出結果,以檢視使用最新 API 版本或棄用版本的 PDB:
kubectl get pdb your-pdb-name -n your-namespace -o yaml**注意:**將 your-pdb-name 替換為您的 PDB,並將 your-namespace 替換為您的命名空間。
-
如果您有任何 PDB 使用已棄用的 API 版本,請將其更新為使用 YAML 組態檔案中的最新 API 版本。如需詳細資訊,請參閱 Kubernetes 網站上的為您的應用程式指定中斷預算。
-
如果您無法確定是哪個實體呼叫了已棄用的 API,因為它使用的是特定使用者代理程式 (例如 kube-apiserver、newrelic 或 kube-controller-manager),請檢查 EKS 叢集的 kube-api-server-audit 日誌檔案以確定該實體。
**注意:**您的 EKS 叢集必須啟用 Cloudwatch 稽核日誌才能執行下列查詢。 -
開啟 Amazon Cloudwatch Console (Amazon CloudWatch 主控台)。
-
選擇 Logs Insights,然後從功能表中選取您的日誌群組。例如,-/aws/eks/eksworkshop/cluster。
-
篩選時間和日期以顯示上次請求時間。
查詢:fields @logStream, @timestamp, responseStatus.code, @message | filter @logStream like /^kube-apiserver-audit/ | filter requestURI like /\/apis\/autoscaling\/v2beta2\/horizontalpodautoscalers/ ### ---> Replace this with your Deprecated API's | sort @timestamp desc | limit 1000輸出:
{ "kind":"Event", "apiVersion":"audit.k8s.io/v1", "level":"Request", "auditID":"bd2b2b0c-8556-4468-8b35-91e2e78759a6", "stage":"ResponseComplete", "requestURI":"/apis/autoscaling/v2beta2/horizontalpodautoscalers?allowWatchBookmarks=true\u0026resourceVersion=118801277\u0026timeout=5m51s\u0026timeoutSeconds=351\u0026watch=true", "verb":"watch", "user":{ "username":"system:serviceaccount:newrelic:newrelic-kube-state-metrics", "uid":"9b97a09a-cf70-4fe2-8fd8-6c87110ce672", "groups":[ "system:serviceaccounts", "system:serviceaccounts:newrelic", "system:authenticated" ], "extra":{ "authentication.kubernetes.io/pod-name":[ "newrelic-kube-state-metrics-5bb6ccc94d-8nj9v" ], "authentication.kubernetes.io/pod-uid":[ "5b156744-00b6-4dfb-a998-a32140409b8e" ] } }, "sourceIPs":[ "10.62.98.22" ], "userAgent":"v2.6.0", "objectRef":{ "resource":"horizontalpodautoscalers", "apiGroup":"autoscaling", "apiVersion":"v2beta2" }, "responseStatus":{ "metadata":{ }, "code":200 }, "requestReceivedTimestamp":"2024-12-13T20:13:04.438616Z", "stageTimestamp":"2024-12-13T20:18:55.441744Z", "annotations":{ "authorization.k8s.io/decision":"allow", "authorization.k8s.io/reason":"RBAC: allowed by ClusterRoleBinding \"newrelic-kube-state-metrics\" of ClusterRole \"newrelic-kube-state-metrics\" to ServiceAccount \"newrelic-kube-state-metrics/newrelic\"", "k8s.io/deprecated":"true", "k8s.io/removed-release":"1.26" } } -
若要使用最新 API 更新已棄用的 API,請執行下列其中一項:
如果使用者名稱顯示 cluster-autoscaler,請將您的 Cluster Autoscaler 更新至最新版本。
如果使用者名稱顯示 newrelic-kube-state-metric,請將叢集更新至較新的 kube-state-metrics 版本 (如果單獨安裝)。或者,如果搭配了 kube-state-metrics,請升級新的 relic 外掛程式。
注意:AWS 會掃描過去 30 天內已棄用的 API。更新 cluster-autoscaler 或 newrelic-kube-state-metric 後,AWS 可能需要最多 30 天的時間來掃描已棄用的 API,並更新 Update insights (更新洞察) 索引標籤上的狀態。
- 語言
- 中文 (繁體)
