How do I change my container instance type in Amazon ECS?

6 分的閱讀內容
0

I want to change the container instance type in my Amazon Elastic Container Service (Amazon ECS) cluster. But, I don't know how.

Short description

To change your container instance type, complete the steps in one of the following sections:

  • Update container instances that are launched in an ECS cluster through the AWS CloudFormation stack
  • Update container instances that are launched manually in an ECS cluster
  • Update container instances in a cluster that's associate with a capacity provider

Resolution

Update container instances that are launched in an ECS cluster through the CloudFormation stack

Important: The following steps apply only to ECS clusters that are created with resources that internally create an underlying CloudFormation stack. The stack has a name in the following format: EC2ContainerService-yourClusterName. These steps don't apply to empty ECS clusters or to customized approaches for provisioning container instances.

Update the value of the EcsInstanceType parameter in the CloudFormation stack

  1. Open the AWS CloudFormation console.
  2. Select the stack that contains your ECS cluster.
    Note: The cluster name is appended to the end of your stack name (for example, EC2ContainerService-yourClusterName).
  3. Choose Actions, and then choose Update Stack.
  4. Choose Use current template, and then choose Next.
  5. For EcsInstanceType, set a value that's appropriate for the instance type in your container instance, and then choose Next.
  6. Skip the Options section, choose Next, and then choose Update.

Replace the old container instances in the cluster

  1. To update the CloudFormation stack, complete steps 1 through 4 in the preceding section.
  2. For AsgMaxSize, enter a parameter value that's double the current size.
    Note: For example, if the current value is 2, set the new value to 4. This helps prevent downtime when you change the instance type.
  3. Open the Amazon ECS console.
  4. In the navigation pane, choose Clusters, and then choose your cluster.
  5. Choose the ECS Instances tab, and then select the container instance IDs for the old container instances that you want to replace.
    Note: If DeploymentConfiguration allows for replacement tasks to be placed on container instances, then Amazon ECS automatically places the replacement tasks.
  6. Choose the Actions menu, and then choose Drain instances to drain the instances.
  7. On the ECS Instances tab, verify that Running tasks count is 0 for your old container instances.
  8. In the navigation pane, choose Clusters, and then select your cluster.
  9. Choose the ECS Instances tab, select the container instance IDs of your old container instances, and then choose Deregister.
    Note: Deregistering an instance removes it from Amazon ECS.
  10. In your CloudFormation template, set the value of AsgMaxSize to the original value to terminate the older container instances.
    Important: This step assumes that your Auto Scaling group has the Default Termination Policy.

Update container instances that are manually launched in an ECS cluster

  1. Copy the launch configuration of your Auto Scaling group, and then name your new launch configuration.
  2. Change your instance type.
  3. In the Amazon EC2 console, in the Auto Scaling section of the navigation pane, choose Auto Scaling Groups. Then, select the Auto Scaling group for your container instance.
  4. Choose Actions, and then choose Edit.
  5. In the pop-up window, for Launch Configuration, choose the launch configuration that you created in step 1 of this section.
  6. For Desired Capacity, enter a value that's double the size of the current value, and then update the value of Max as needed.
    Note: Desired capacity must be between minimum and maximum group size, inclusive.
  7. In the navigation pane of the Amazon ECS console, choose Clusters, and then choose your cluster.
  8. Choose the ECS Instances tab, select the container instance IDs for the old container instances that you want to replace.
  9. Choose the Actions menu, and then choose Drain instances to drain the instances.
  10. On the ECS Instances tab, for your old container instances, verify that Running tasks count is 0.
  11. Choose the ECS Instances tab, select the container instance IDs for your old container instances, and then choose Deregister.
    Note: Deregistering an instance removes it from Amazon ECS.
  12. In the Amazon EC2 console, in the Auto Scaling section of the navigation pane, choose Auto Scaling Groups.
  13. Choose Actions, and then choose Edit.
  14. In your Auto Scaling group configuration, set Desired Capacity and Max to their original values, and then save your changes.
    Note: This terminates the old container instances in the ECS cluster.

Update container instances in a cluster that's associated with a capacity provider

Note: This section assumes that you have capacity providers associated with your cluster and services associated with capacity provider strategy.

If the cluster was created using CloudFormation, then complete the following steps:

  1. Follow steps 1 through 6 in the preceding subsection:
    Update the value of the EcsInstanceType parameter in the CloudFormation stack
  2. In the navigation pane of the Amazon ECS console, choose Clusters, and then choose your cluster.
  3. Choose the ECS Instances tab, then select the container instance ID for the old container instance that you want to replace.
  4. Choose the Actions menu, and then choose Drain instances to drain the instances.
    Note: When you drain the instances, the capacity provider launches new container instances based on the DeploymentConfiguration of the services.
  5. On the ECS Instances tab of your old container instance, verify that the Running tasks count is 0.

If the cluster was created manually, then complete the following steps:

  1. Follow steps 1 through 5 in the preceding section:
    Update container instances that are manually launched in an ECS cluster
  2. In the navigation pane of the Amazon ECS console, choose Clusters, and then choose your cluster.
  3. Choose the ECS Instances tab, then select the container instance ID for the old container instance that you want to replace.
  4. Choose the Actions menu, and then choose Drain instances to drain the instances.
    Note: When you drain the instances, the capacity provider launches new container instances based on the DeploymentConfiguration of the services.
  5. On the ECS Instances tab of your old container instance, verify that the Running tasks count is 0.

Note: The capacity provider automatically terminates drained instances after a defined period of time.


AWS 官方
AWS 官方已更新 1 年前