I have a cluster in AWS EC2 Container Service. When I've set it up, I used t2.micro instances because those were sufficient for development. Now I'd like to use more powerful instances, like m4.large.
I would like to know whether it is possible to change the instance types only, so I don't need to recreate the whole cluster. I could not find how to do this.
Yes, this is possible.
The instance types in your cluster are determined by the 'Instance Type' setting within your Launch Configuration. To update the instance type without having to recreate the cluster:
- Make a copy of the cluster Launch Configuration and update the 'Instance Type'.
- Adjust the cluster Auto Scaling Group to point to your new Launch Configuration.
- Wait for your new instances to register in your cluster and your services to start.
You can also add multiple instances types to a single cluster by creating multiple Auto Scaling Groups linked to different Launch Configurations. Note however that you can't copy Auto Scaling Groups easily within the console.
Yes, you can achieve this in CloudFormation.
- Click on the Stack corresponding to your ECS-Cluster.
- Click
Update Stack
- Use radio
current template
,Next
- change EcsInstanceType
Next
,Next
,Update
- Upscale your cluster to
2*n
instances - Wait for the
n
new instances of the new type being created - Downscale your cluster to
n
- Or you could just drain and terminate the instances 1 by 1
This is how to do it without any downtime:
- Create a copy of the Launch Configuration used by your Auto Scaling Group, including any changes you want to make.
- Edit the Auto Scaling Group to:
- Use the new Launch Configuration
- Desired Capacity = Desired Capacity * 2
- Min = Desired Capacity
- Wait for all new instances to become 'ACTIVE' in the ECS Instances tab of the ECS Cluster
- Select the old instances and click Actions -> Drain Instances
- Wait until all the old instances are running 0 tasks
- Edit the Auto Scaling Group and change Min and Desired back to their original values
This can be achieved by modifying EcsInstanceType in the CloudFormation stack for the ECS instance. Any change to the autoscaling group by hand will be overwritten by the next "Scale ECS Instances" operation.
How do I change my container instance type in Amazon ECS?
To change your container instance type, complete the steps in one of the following sections:
- Update container instances launched in an ECS cluster through the AWS CloudFormation stack
- Update container instances launched manually in an ECS cluster
Resolution
- Update container instances launched in an ECS cluster through the AWS CloudFormation stack
Important: The following steps apply only to ECS clusters created with resources that internally create an underlying AWS 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 AWS CloudFormation stack:
1.Open the AWS CloudFormation console.
- 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).
Choose Actions, and then choose Update Stack.
Choose Use current template, and then choose Next.
For EcsInstanceType, set a value that's appropriate for the instance type in your container instance, and then choose Next.
Skip the Options section, choose Next, and then choose Update.
Replace the old container instances in the cluster:
To update the AWS CloudFormation stack, complete steps 1-4 in the preceding section.
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.
- Open the Amazon ECS console.
- In the navigation pane, choose Clusters, and then choose your cluster.
- 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 6. container instances, Amazon ECS places the replacement tasks automatically.
- Choose the Actions menu, and then choose Drain instances to drain the instances.
- On the ECS Instances tab, verify that Running tasks count is 0 for your old container instances.
- In the navigation pane, choose Clusters, and then select your cluster. 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.
- In your AWS 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.
Here are the exact steps I took to update the instance type on my cluster:
Go to the cluster service, update Number of tasks to 0
Go to EC2 -> Launch Configurations -> Actions dropdown -> Copy launch configuration and set the new instance type
Go to EC2 -> Auto Scaling Groups -> Edit -> set Launch Configuration to newly created launch configuration
Go to EC2 -> Auto Scaling Groups -> Instances -> Detach instance
Go to EC2 -> Launch Configurations -> Delete old launch configuration
Go to the cluster service, update Number of tasks to your desired count.
Now when tasks start, it'll be running on the updated EC2 instance type.
Definitely, there are multiple ways to change the instance type as suggested about using launch configurations.
But beware that, it is a challenge to use multiple launch configuration to attach to ECS cluster that has Container Instances Scaling policies.
For example, If one is running a cluster with t2.medium type of instances using a launch configuration and have a Auto scaling policy attached to ECS cluster then it can signal only Auto scaling group and not more than 1.
Yes, you can change the instance type in ECS cluster. I believe you have created ECS cluster manually from AWS GUI. Behind the scene, its creating aws cloud formation template as per your inputs from AWS console(ECS) like VPC, instance type, and size, etc. Please follow the below steps for the same.
- Find the cloud formation template with the name "EC2ContainerService-{your-ecs-cluster-name}".
- Check the existing setting in the Parameters tab(you can check your instance type here).
- Now you need to update the cloud formation. Click on-> Update ->use current template ->next->update the EcsInstanceType variable ->next->next->update stack.
- Now your cloud formation update. now you can check in EC2 console that there is a new spot fleet with new instance type.
来源:https://stackoverflow.com/questions/44637225/how-to-change-instance-type-in-aws-ecs-cluster