排解叢集建立或更新問題

本頁說明如何解決安裝或升級 GKE on AWS 時發生的問題。

如需其他協助,請與 Cloud Customer Care 團隊聯絡。

無法建立叢集

當您要求建立叢集時,AWS 上的 GKE 會先執行一組前置測試,以驗證要求。如果叢集建立失敗,可能是因為其中一項前置測試失敗,或是叢集建立程序中的某個步驟未完成。

如果飛行前測試失敗,叢集不會建立任何資源,並直接向您回報錯誤資訊。舉例來說,如果您嘗試建立名為 invalid%%%name 的叢集,有效叢集名稱的預檢測試就會失敗,且要求會傳回下列錯誤:

ERROR: (gcloud.container.aws.clusters.create) INVALID_ARGUMENT: must be
between 1-63 characters, valid characters are /[a-z][0-9]-/, should start with a
letter, and end with a letter or a number: "invalid%%%name",
field: aws_cluster_id

即使通過預檢測試,叢集建立作業仍可能失敗。叢集開始建立後,GKE on AWS 會在 Google Cloud 和 AWS 中建立資源,這時可能需要幾分鐘。在這種情況下,您的 Google Cloud 專案中會存在 AWS 資源,且狀態設為 ERROR

如要取得失敗的詳細資料,請執行下列指令:

gcloud container aws clusters describe CLUSTER_NAME \
    --location GOOGLE_CLOUD_LOCATION \
    --format "value(state, errors)"

更改下列內容:

  • CLUSTER_NAME:您要查詢狀態的叢集名稱
  • GOOGLE_CLOUD_LOCATION,並以管理這個 AWS 叢集的 Google Cloud 區域 名稱取代

或者,您也可以描述與建立叢集 API 呼叫相關聯的Operation資源,取得建立失敗的詳細資料。

gcloud container aws operations describe OPERATION_ID

OPERATION_ID 替換為建立叢集的作業 ID。如果沒有叢集建立要求的作業 ID,可以執行下列指令來擷取:

gcloud container aws operations list \
    --location GOOGLE_CLOUD_LOCATION

使用時間戳記或相關資訊,找出您感興趣的叢集建立作業。

舉例來說,如果叢集建立作業因 AWS IAM 角色權限不足而失敗,這項指令及其結果會類似於下列範例:

gcloud container aws operations describe b6a3d042-8c30-4524-9a99-6ffcdc24b370 \
  --location GOOGLE_CLOUD_LOCATION

輸出結果會與下列內容相似:

done: true
error:
  code: 9
  message: 'could not set deregistration_delay timeout for the target group: AccessDenied
    User: arn:aws:sts::0123456789:assumed-role/foo-1p-dev-oneplatform/multicloud-service-agent
    is not authorized to perform: elasticloadbalancing:ModifyTargetGroupAttributes
    on resource: arn:aws:elasticloadbalancing:us-west-2:0123456789:targetgroup/gke-4nrk57tlyjva-cp-tcp443/74b57728e7a3d5b9
    because no identity-based policy allows the elasticloadbalancing:ModifyTargetGroupAttributes
    action'
metadata:
  '@type': type.googleapis.com/google.cloud.gkemulticloud.v1.OperationMetadata
  createTime: '2021-12-02T17:47:31.516995Z'
  endTime: '2021-12-02T18:03:12.590148Z'
  statusDetail: Cluster is being deployed
  target: projects/123456789/locations/us-west1/awsClusters/aws-prod1
name: projects/123456789/locations/us-west1/operations/b6a3d042-8c30-4524-9a99-6ffcdc24b370

叢集建立或作業失敗,並出現授權錯誤

如果錯誤顯示授權失敗,通常表示您在叢集建立指令中指定的其中一個 AWS IAM 角色建立不正確。舉例來說,如果 API 角色未包含 elasticloadbalancing:ModifyTargetGroupAttributes 權限,叢集建立作業就會失敗,並顯示類似以下的錯誤訊息:

ERROR: (gcloud.container.aws.clusters.create) could not set
deregistration_delay timeout for the target group: AccessDenied User:
arn:aws:sts::0123456789:assumed-role/cloudshell-user-dev-api-role/multicloud-
service-agent is not authorized to perform:
elasticloadbalancing:ModifyTargetGroupAttributes on resource:
arn:aws:elasticloadbalancing:us-east-1:0123456789:targetgroup/gke-u6au6c65e4iq-
cp-tcp443/be4c0f8d872bb60e because no identity-based policy allows the
elasticloadbalancing:ModifyTargetGroupAttributes action

即使叢集看似已成功建立,但如果 IAM 角色指定有誤,之後在叢集作業期間 (例如使用 kubectl logs 等指令時),可能會發生失敗情形。

如要解決這類授權錯誤,請確認與您在建立叢集時指定的兩個 IAM 角色相關聯的政策正確無誤。具體來說,請確保這些角色與「建立 AWS IAM 角色」中的說明相符,然後刪除並重新建立叢集。如需個別角色說明,請參閱「API 角色」和「控制平面角色」。

叢集建立或作業在健康狀態檢查階段失敗

有時,叢集建立作業會在健康狀態檢查期間失敗,作業狀態類似於下列內容:

done: true
error:
  code: 4
  message: Operation failed
metadata:
  '@type': type.googleapis.com/google.cloud.gkemulticloud.v1.OperationMetadata
  createTime: '2022-06-29T18:26:39.739574Z'
  endTime: '2022-06-29T18:54:45.632136Z'
  errorDetail: Operation failed
  statusDetail: Health-checking cluster
  target: projects/123456789/locations/us-west1/awsClusters/aws-prod1
name: projects/123456789/locations/us-west1/operations/8a7a3b7f-242d-4fff-b518-f361d41c6597

這可能是因為缺少 IAM 角色,或是 IAM 角色指定有誤。您可以使用 AWS CloudTrail 找出 IAM 問題。

例如:

  • 如果 API 角色未包含控制平面主磁碟區 KMS 金鑰的 kms:GenerateDataKeyWithoutPlaintext 權限,您會看到下列事件:

    "eventName": "AttachVolume",
    "errorCode": "Client.InvalidVolume.NotFound",
    "errorMessage": "The volume 'vol-0ff75940ce333aebb' does not exist.",
    

    "errorCode": "AccessDenied",
    "errorMessage": "User: arn:aws:sts::0123456789:assumed-role/foo-1p-dev-oneplatform/multicloud-service-agent is not authorized to perform: kms:GenerateDataKeyWithoutPlaintext on resource: arn:aws:kms:us-west1:0123456789:key/57a61a45-d9c1-4038-9021-8eb08ba339ba because no identity-based policy allows the kms:GenerateDataKeyWithoutPlaintext action",
    
  • 如果控制層角色未包含控制層主要磁碟區 KMS 金鑰的 kms:CreateGrant 權限,您會看到下列事件:

    "eventName": "AttachVolume",
    "errorCode": "Client.CustomerKeyHasBeenRevoked",
    "errorMessage": "Volume vol-0d022beb769c8e33b cannot be attached. The encrypted volume was unable to access the KMS key.",
    

    "errorCode": "AccessDenied",
    "errorMessage": "User: arn:aws:sts::0123456789:assumed-role/foo-controlplane/i-0a11fae03eb0b08c1 is not authorized to perform: kms:CreateGrant on resource: arn:aws:kms:us-west1:0123456789:key/57a61a45-d9c1-4038-9021-8eb08ba339ba because no identity-based policy allows the kms:CreateGrant action",
    
  • 如果您未授予名為 AWSServiceRoleForAutoScaling 的服務連結角色 kms:CreateGrant 權限,以使用控制層根磁碟區 KMS 金鑰,您會看到下列事件:

    "errorCode": "AccessDenied",
    "errorMessage": "User: arn:aws:sts::0123456789:assumed-role/AWSServiceRoleForAutoScaling/AutoScaling is not authorized to perform: kms:CreateGrant on resource: arn:aws:kms:us-west1:0123456789:key/c77a3a26-bc91-4434-bac0-0aa963cb0c31 because no identity-based policy allows the kms:CreateGrant action",
    
  • 如果您未授予名為 AWSServiceRoleForAutoScaling 的服務連結角色 kms:GenerateDataKeyWithoutPlaintext 權限,以使用控制平面根磁碟區 KMS 金鑰,您會看到下列事件:

    "errorCode": "AccessDenied",
    "errorMessage": "User: arn:aws:sts::0123456789:assumed-role/AWSServiceRoleForAutoScaling/AutoScaling is not authorized to perform: kms:GenerateDataKeyWithoutPlaintext on resource: arn:aws:kms:us-west1:0123456789:key/c77a3a26-bc91-4434-bac0-0aa963cb0c31 because no identity-based policy allows the kms:CreateGrant action",
    

正在等待節點加入叢集

如果在建立節點集區時收到下列錯誤訊息,請檢查虛擬私有雲是否包含相關聯的次要 IPv4 CIDR 區塊

errorDetail: Operation failed
statusDetail: Waiting for nodes to join the cluster (0 out of 1 are ready)

如要修正這個問題,請建立包含所有 CIDR 區塊的安全性群組,然後將該群組新增至叢集。詳情請參閱「虛擬私有雲次要 CIDR 區塊中的節點集區」。

取得執行個體的系統記錄

如果控制層或節點集區執行個體無法啟動,您可以檢查系統記錄。如要檢查系統記錄,請按照下列步驟操作:

  1. 開啟 AWS EC2 執行個體控制台
  2. 按一下「執行個體」
  3. 依名稱尋找執行個體。GKE on AWS 通常會為控制層節點建立名為 CLUSTER_NAME-cp 的執行個體,或是為節點集區節點建立名為 CLUSTER_NAME-np 的執行個體。
  4. 依序選擇「動作」->「監控和疑難排解」->「取得系統記錄」。 系統隨即會顯示執行個體的系統記錄。

叢集更新失敗

更新叢集時,就像建立新叢集一樣,GKE on AWS 會先執行一組預檢測試,驗證要求。如果叢集更新失敗,可能是因為其中一項飛行前測試失敗,或是叢集更新程序中的某個步驟未完成。

如果飛行前測試失敗,叢集不會更新任何資源,並直接向您回報錯誤資訊。舉例來說,如果您嘗試更新叢集,改用名稱為 test_ec2_keypair 的 SSH 金鑰配對,預先測試會嘗試擷取 EC2 金鑰配對,但會失敗,且要求會傳回下列錯誤:

ERROR: (gcloud.container.aws.clusters.update) INVALID_ARGUMENT: key pair
"test_ec2_keypair" not found,
field: aws_cluster.control_plane.ssh_config.ec2_key_pair

預檢測試通過後,叢集更新作業也可能失敗。叢集更新開始後幾分鐘, Google Cloud 專案中的 AWS 資源狀態可能會設為 DEGRADED

如要取得失敗事件和相關作業的詳細資料,請按照「叢集建立失敗」一文所述的步驟操作。

更新控制層標記時,叢集更新失敗

AWS 更新 API 支援更新控制層標記。如要更新標記,叢集的 Kubernetes 版本必須為 1.24 以上。此外,請務必確認 AWS IAM 角色具有適當的權限,如更新叢集頁面所列,才能更新控制平面標記。

如果顯示驗證失敗錯誤,通常表示您漏加了某些 IAM 權限。舉例來說,如果 API 角色未包含 ec2:DeleteTags 權限,標記的叢集更新作業可能會失敗,並顯示類似下列的錯誤訊息 (為簡潔起見,已將 <encoded_auth_failure_message> 遮蓋):

ERROR: (gcloud.container.aws.clusters.update) could not delete tags:
UnauthorizedOperation You are not authorized to perform this operation.
Encoded authorization failure message: <encoded_auth_failure_message>

如要偵錯上述編碼的失敗訊息,您可以將要求傳送至 AWS STS decode-authorization-message API,如下列指令所示:

aws sts decode-authorization-message --encoded-message
<encoded_auth_failure_message> --query DecodedMessage --output
text | jq '.' | less

輸出結果會與下列內容相似:

...
"principal": {
  "id": "AROAXMEL2SCNPG6RCJ72B:iam-session",
  "arn": "arn:aws:sts::1234567890:assumed-role/iam_role/iam-session"
},
"action": "ec2:DeleteTags",
"resource": "arn:aws:ec2:us-west-2:1234567890:security-group-rule/sgr-00bdbaef24a92df62",
...

上述回應指出您無法對 AWS 叢集的 EC2 安全性群組規則資源執行 ec2:DeleteTags 動作。請據此更新 API 角色,然後重新傳送更新 API 要求,更新控制層標記。

後續步驟