本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
Amazon ECS 藍/綠部署疑難排解
以下提供使用藍/綠部署搭配 Amazon ECS 時可能遇到的常見問題的解決方案。藍/綠部署錯誤可能會在下列階段發生:
-
同步路徑:立即出現以回應
CreateService
或UpdateService
API 呼叫的錯誤。 -
非同步路徑:出現在
statusReason
欄位中DescribeServiceDeployments
並導致部署復原的錯誤
負載平衡器組態問題
負載平衡器組態是 Amazon ECS 中藍/綠部署的關鍵元件。正確設定接聽程式規則、目標群組和負載平衡器類型對於成功部署至關重要。本節涵蓋可能導致藍/綠部署失敗的常見負載平衡器組態問題。
疑難排解負載平衡器問題時,請務必了解接聽程式規則與目標群組之間的關係。在藍/綠部署中:
-
生產接聽程式規則會將流量導向目前作用中 (藍色) 服務修訂
-
測試接聽程式規則可用於在轉移生產流量之前驗證新的 (綠色) 服務修訂
-
目標群組用於註冊每個服務修訂中的容器執行個體
-
在部署期間,流量會透過調整接聽程式規則中目標群組的權重,逐漸從藍色服務修訂轉換為綠色服務修訂
接聽程式規則組態錯誤
下列問題與藍/綠部署的不正確接聽程式規則組態有關。
- 使用 Application Load Balancer 接聽程式 ARN 而非接聽程式規則 ARN
-
錯誤訊息:
productionListenerRule has an invalid ARN format. Must be RuleArn for ALB or ListenerArn for NLB. Got: arn:aws:elasticloadbalancing:us-west-2:123456789012:listener/app/my-alb/abc123/def456
解決方案:使用 Application Load Balancer 時,您必須為
productionListenerRule
和 指定接聽程式規則 ARNtestListenerRule
,而不是接聽程式 ARN。對於 Network Load Balancer,您必須使用接聽程式 ARN。如需有關如何尋找接聽程式 ARN 的資訊,請參閱《Application Load Balancer 使用者指南》中的 Application Load Balancer 的接聽程式。 Application Load Balancer 規則的 ARN 格式為
。arn:aws:elasticloadbalancing:region:account-id:listener-rule/app/...
- 對生產和測試接聽程式使用相同的規則
-
錯誤訊息:
The following rules cannot be used as both production and test listener rules: arn:aws:elasticloadbalancing:us-west-2:123456789012:listener-rule/app/my-alb/abc123/def456/ghi789
解決方案:生產和測試流量必須使用不同的接聽程式規則。為路由至測試目標群組的測試流量建立個別的接聽程式規則。
- Network Load Balancer 缺少測試接聽程式規則
-
錯誤訊息:
TestListenerRule is required for NLB with arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/nlb-targetgroup/abc123
解決方案:當您使用 Network Load Balancer 時,您必須同時指定
productionListenerRule
和testListenerRule
。將testListenerRule
具有有效接聽程式 ARN 的 新增至您的組態。如需詳細資訊,請參閱 Network Load Balancer 使用者指南中的為 Network Load Balancer 建立接聽程式 Load Balancer - 目標群組未與接聽程式規則建立關聯
-
錯誤訊息:
Service deployment rolled back because of invalid networking configuration: Target group arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/myAlternateTG/abc123 is not associated with either productionListenerRule or testListenerRule.
解決方案:主要目標群組和替代目標群組都必須與生產接聽程式規則或測試接聽程式規則建立關聯。更新您的負載平衡器組態,以確保兩個目標群組都與您的接聽程式規則正確關聯。
- 遺失具有 Application Load Balancer 的測試接聽程式規則
-
錯誤訊息:
For Application LoadBalancer, testListenerRule is required when productionListenerRule is not associated with both targetGroup and alternateTargetGroup
解決方案:當您使用 Application Load Balancer 時,如果兩個目標群組都未與生產接聽程式規則建立關聯,則必須指定測試接聽程式規則。將
testListenerRule
新增至您的組態,並確保兩個目標群組都與生產或測試接聽程式規則相關聯。如需詳細資訊,請參閱《Application Load Balancer 使用者指南》中的 Application Load Balancer 的接聽程式。 Application Load Balancer
目標群組組態錯誤
下列問題與藍/綠部署的目標群組組態不正確有關。
- 在接聽程式規則中具有流量的多個目標群組
-
錯誤訊息:
Service deployment rolled back because of invalid networking configuration. productionListenerRule arn:aws:elasticloadbalancing:us-west-2:123456789012:listener-rule/app/my-alb/abc123/def456/ghi789 should have exactly one target group serving traffic but found 2 target groups which are serving traffic
解決方案:開始藍/綠部署之前,請確定只有一個目標群組正在接聽程式規則中接收流量 (具有非零權重)。更新您的接聽程式規則組態,將不應接收流量的任何目標群組的權重設定為零。
- 負載平衡器項目之間的重複目標群組
-
錯誤訊息:
Duplicate targetGroupArn found: arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/myecs-targetgroup/abc123
解決方案:每個目標群組 ARN 在您服務定義中的所有負載平衡器項目中必須是唯一的。檢閱您的組態,並確保您為每個負載平衡器項目使用不同的目標群組。
- 生產接聽程式規則中的非預期目標群組
-
錯誤訊息:
Service deployment rolled back because of invalid networking configuration. Production listener rule is forwarding traffic to unexpected target group arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/random-nlb-tg/abc123. Expected traffic to be forwarded to either targetGroupArn: arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/nlb-targetgroup/def456 or alternateTargetGroupArn: arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/nlb-tg-alternate/ghi789
解決方案:生產接聽程式規則正在將流量轉送至服務定義中未指定的目標群組。請確定接聽程式規則已設定為僅將流量轉送至服務定義中指定的目標群組。
如需詳細資訊,請參閱《Application Load Balancer 使用者指南》中的轉送動作。
負載平衡器類型組態錯誤
下列問題與藍/綠部署的不正確負載平衡器類型組態相關。
- 混合 Classic Load Balancer 和 Application Load Balancer 或 Network Load Balancer 組態
-
錯誤訊息:
All loadBalancers must be strictly either ELBv1 (defining loadBalancerName) or ELBv2 (defining targetGroupArn)
注意
Classic Load Balancer 是 Elastic Load Balancing 的上一代負載平衡器。建議您遷移至目前世代的負載平衡器。如需詳細資訊,請參閱遷移 Classic Load Balancer。
解決方案:。使用所有 Classic Load Balancer 或所有 Application Load Balancer 和 Network Load Balancer。
對於 Application Load Balancer 和 Network Load Balancer,請僅指定
targetGroupArn
欄位。 - 搭配 Classic Load Balancer 使用進階組態
-
錯誤訊息:
advancedConfiguration field is not allowed with ELBv1 loadBalancers
解決方案:只有 Application Load Balancer 和 Network Load Balancer 支援藍/綠部署的進階組態。如果您使用 Classic Load Balancer (以 指定
loadBalancerName
),則無法使用advancedConfiguration
欄位。切換到 Application Load Balancer,或移除advancedConfiguration
欄位。 - 跨負載平衡器的不一致進階組態
-
錯誤訊息:
Either all or none of the provided loadBalancers must have advancedConfiguration defined
解決方案:如果您使用多個負載平衡器,您必須
advancedConfiguration
為所有負載平衡器定義 ,或為所有負載平衡器定義 。更新您的組態,以確保所有負載平衡器項目的一致性。 - 缺少藍/綠部署的進階組態
-
錯誤訊息:
advancedConfiguration field is required for all loadBalancers when using a non-ROLLING deployment strategy
解決方案:搭配 Application Load Balancer 使用藍/綠部署策略時,您必須為所有負載平衡器項目指定
advancedConfiguration
欄位。將所需的advancedConfiguration
新增至負載平衡器組態。
許可問題
下列問題與藍/綠部署的許可不足有關。
- 基礎設施角色缺少信任政策
-
錯誤訊息:
Service deployment rolled back because of invalid networking configuration. ECS was unable to manage the ELB resources due to missing permissions on ECS Infrastructure Role 'arn:aws:iam::123456789012:role/Admin'.
解決方案:指定用於管理負載平衡器資源的 IAM 角色沒有正確的信任政策。更新角色的信任政策,以允許服務擔任角色。信任政策必須包含:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Service": "ecs.amazonaws.com" }, "Action": "sts:AssumeRole" } ] }
- 負載平衡器角色缺少讀取許可
-
錯誤訊息:
service myService failed to describe target health on target-group myTargetGroup with (error User: arn:aws:sts::123456789012:assumed-role/myELBRole/ecs-service-scheduler is not authorized to perform: elasticloadbalancing:DescribeTargetHealth because no identity-based policy allows the elasticloadbalancing:DescribeTargetHealth action)
解決方案:用於管理負載平衡器資源的 IAM 角色沒有讀取目標運作狀態資訊的許可。將
elasticloadbalancing:DescribeTargetHealth
許可新增至角色的政策。如需 Elastic Load Balancing 許可的詳細資訊,請參閱 適用於負載平衡器的 Amazon ECS 基礎設施 IAM 角色。 - 負載平衡器角色缺少寫入許可
-
錯誤訊息:
service myService failed to register targets in target-group myTargetGroup with (error User: arn:aws:sts::123456789012:assumed-role/myELBRole/ecs-service-scheduler is not authorized to perform: elasticloadbalancing:RegisterTargets on resource: arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/myTargetGroup/abc123 because no identity-based policy allows the elasticloadbalancing:RegisterTargets action)
解決方案:用於管理負載平衡器資源的 IAM 角色沒有註冊目標的許可。將
elasticloadbalancing:RegisterTargets
許可新增至角色的政策。如需 Elastic Load Balancing 許可的詳細資訊,請參閱 適用於負載平衡器的 Amazon ECS 基礎設施 IAM 角色。 - 缺少修改接聽程式規則的許可
-
錯誤訊息:
Service deployment rolled back because TEST_TRAFFIC_SHIFT lifecycle hook(s) failed. User: arn:aws:sts::123456789012:assumed-role/myELBRole/ECSNetworkingWithELB is not authorized to perform: elasticloadbalancing:ModifyListener on resource: arn:aws:elasticloadbalancing:us-west-2:123456789012:listener/app/my-alb/abc123/def456 because no identity-based policy allows the elasticloadbalancing:ModifyListener action
解決方案:用於管理負載平衡器資源的 IAM 角色沒有修改接聽程式的許可。將
elasticloadbalancing:ModifyListener
許可新增至角色的政策。如需 Elastic Load Balancing 許可的詳細資訊,請參閱 適用於負載平衡器的 Amazon ECS 基礎設施 IAM 角色。
對於藍/綠部署,我們建議將 AmazonECS-ServiceLinkedRolePolicy
受管政策連接至您的基礎設施角色,其中包含管理負載平衡器資源的所有必要許可。
生命週期掛鉤問題
下列問題與藍/綠部署中的生命週期掛鉤有關。
- Lambda 勾點角色的信任政策不正確
-
錯誤訊息:
Service deployment rolled back because TEST_TRAFFIC_SHIFT lifecycle hook(s) failed. ECS was unable to assume role arn:aws:iam::123456789012:role/Admin
解決方案:為 Lambda 生命週期關聯指定的 IAM 角色沒有正確的信任政策。更新角色的信任政策,以允許服務擔任角色。信任政策必須包含:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Service": "ecs.amazonaws.com" }, "Action": "sts:AssumeRole" } ] }
- Lambda 勾點傳回 FAILED 狀態
-
錯誤訊息:
Service deployment rolled back because TEST_TRAFFIC_SHIFT lifecycle hook(s) failed. Lifecycle hook target arn:aws:lambda:us-west-2:123456789012:function:myHook returned FAILED status.
解決方案:指定為生命週期掛鉤的 Lambda 函數傳回 FAILED 狀態。檢查 Amazon CloudWatch logs以判斷失敗原因,並更新函數以正確處理部署事件。
- 缺少叫用 Lambda 函數的許可
-
錯誤訊息:
Service deployment rolled back because TEST_TRAFFIC_SHIFT lifecycle hook(s) failed. ECS was unable to invoke hook target arn:aws:lambda:us-west-2:123456789012:function:myHook due to User: arn:aws:sts::123456789012:assumed-role/myLambdaRole/ECS-Lambda-Execution is not authorized to perform: lambda:InvokeFunction on resource: arn:aws:lambda:us-west-2:123456789012:function:myHook because no identity-based policy allows the lambda:InvokeFunction action
解決方案:用於 Lambda 生命週期掛鉤的 IAM 角色沒有叫用 Lambda 函數的許可。將
lambda:InvokeFunction
許可新增至特定 Lambda 函數 ARN 的角色政策。如需 Lambda 許可的詳細資訊,請參閱 Amazon ECS 藍/綠部署中 Lambda 函數所需的許可。 - Lambda 函數逾時或無效的回應
-
錯誤訊息:
Service deployment rolled back because TEST_TRAFFIC_SHIFT lifecycle hook(s) failed. ECS was unable to parse the response from arn:aws:lambda:us-west-2:123456789012:function:myHook due to HookStatus must not be null
解決方案:Lambda 函數已逾時或傳回無效的回應。確保您的 Lambda 函數傳回
hookStatus
欄位設定為SUCCEEDED
或 的有效回應FAILED
。此外,請檢查 Lambda 函數逾時是否已針對您的驗證邏輯適當設定。如需詳細資訊,請參閱Amazon ECS 服務部署的生命週期掛鉤。有效 Lambda 回應的範例:
{ "hookStatus": "SUCCEEDED", "reason": "Validation passed" }