設定 Amazon ECS 容量提供者以安全地關閉執行個體 - Amazon Elastic Container Service

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

設定 Amazon ECS 容量提供者以安全地關閉執行個體

您可以使用 Amazon ECS 主控台和 ,在建立或更新 Auto Scaling 群組容量提供者時開啟受管執行個體耗盡 AWS CLI。

注意

建立容量提供者時,受管執行個體耗盡預設為開啟。

以下是使用 AWS CLI 建立已啟用受管執行個體耗盡的容量提供者,以及為叢集現有容量提供者啟用受管執行個體耗盡的範例。

建立已啟用受管執行個體耗盡的容量提供者

若要在啟用受管執行個體耗盡的情況下建立容量提供者,請使用 create-capacity-provider命令。將 managedDraining 參數設為 ENABLED

aws ecs create-capacity-provider \ --name capacity-provider \ --auto-scaling-group-provider '{ "autoScalingGroupArn": "asg-arn", "managedScaling": { "status": "ENABLED", "targetCapacity": 100, "minimumScalingStepSize": 1, "maximumScalingStepSize": 1 }, "managedDraining": "ENABLED", "managedTerminationProtection": "ENABLED", }'

回應:

{ "capacityProvider": { "capacityProviderArn": "capacity-provider-arn", "name": "capacity-provider", "status": "ACTIVE", "autoScalingGroupProvider": { "autoScalingGroupArn": "asg-arn", "managedScaling": { "status": "ENABLED", "targetCapacity": 100, "minimumScalingStepSize": 1, "maximumScalingStepSize": 1 }, "managedTerminationProtection": "ENABLED" "managedDraining": "ENABLED" } } }
啟用叢集現有容量提供者的受管執行個體耗盡

啟用叢集現有容量提供者的受管執行個體耗盡使用 update-capacity-provider命令。您會看到 managedDraining目前顯示 DISABLEDupdateStatus UPDATE_IN_PROGRESS

aws ecs update-capacity-provider \ --name cp-draining \ --auto-scaling-group-provider '{ "managedDraining": "ENABLED" }

回應:

{ "capacityProvider": { "capacityProviderArn": "cp-draining-arn", "name": "cp-draining", "status": "ACTIVE", "autoScalingGroupProvider": { "autoScalingGroupArn": "asg-draining-arn", "managedScaling": { "status": "ENABLED", "targetCapacity": 100, "minimumScalingStepSize": 1, "maximumScalingStepSize": 1, "instanceWarmupPeriod": 300 }, "managedTerminationProtection": "DISABLED", "managedDraining": "DISABLED" // before update }, "updateStatus": "UPDATE_IN_PROGRESS", // in progress and need describe again to find out the result "tags": [ ] } }

使用 describe-clusters命令並包含 ATTACHMENTSstatus 受管執行個體的耗盡連接為 PRECREATED,而整體attachmentsStatusUPDATING

aws ecs describe-clusters --clusters cluster-name --include ATTACHMENTS

回應:

{ "clusters": [ { ... "capacityProviders": [ "cp-draining" ], "defaultCapacityProviderStrategy": [], "attachments": [ # new precreated managed draining attachment { "id": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "type": "managed_draining", "status": "PRECREATED", "details": [ { "name": "capacityProviderName", "value": "cp-draining" }, { "name": "autoScalingLifecycleHookName", "value": "ecs-managed-draining-termination-hook" } ] }, ... ], "attachmentsStatus": "UPDATING" } ], "failures": [] }

更新完成後,請使用 describe-capacity-providers,您看到現在managedDrainingENABLED

aws ecs describe-capacity-providers --capacity-providers cp-draining

回應:

{ "capacityProviders": [ { "capacityProviderArn": "cp-draining-arn", "name": "cp-draining", "status": "ACTIVE", "autoScalingGroupProvider": { "autoScalingGroupArn": "asg-draning-arn", "managedScaling": { "status": "ENABLED", "targetCapacity": 100, "minimumScalingStepSize": 1, "maximumScalingStepSize": 1, "instanceWarmupPeriod": 300 }, "managedTerminationProtection": "DISABLED", "managedDraining": "ENABLED" // successfully update }, "updateStatus": "UPDATE_COMPLETE", "tags": [] } ] }