44
votes

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.

8

8 Answers

43
votes

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:

  1. Make a copy of the cluster Launch Configuration and update the 'Instance Type'.
  2. Adjust the cluster Auto Scaling Group to point to your new Launch Configuration.
  3. 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.

59
votes

Yes, you can achieve this in CloudFormation.

  • Click on the Stack corresponding to your ECS-Cluster.
  • Click Update Stack
  • Use radiocurrent 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
9
votes

This is how to do it without any downtime:

  1. Create a copy of the Launch Configuration used by your Auto Scaling Group, including any changes you want to make.
  2. Edit the Auto Scaling Group to:
    • Use the new Launch Configuration
    • Desired Capacity = Desired Capacity * 2
    • Min = Desired Capacity
  3. Wait for all new instances to become 'ACTIVE' in the ECS Instances tab of the ECS Cluster
  4. Select the old instances and click Actions -> Drain Instances
  5. Wait until all the old instances are running 0 tasks
  6. Edit the Auto Scaling Group and change Min and Desired back to their original values
5
votes

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.

4
votes

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.

3
votes

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.

3
votes

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.

  1. Find the cloud formation template with the name "EC2ContainerService-{your-ecs-cluster-name}".
  2. Check the existing setting in the Parameters tab(you can check your instance type here).
  3. Now you need to update the cloud formation. Click on-> Update ->use current template ->next->update the EcsInstanceType variable ->next->next->update stack.
  4. Now your cloud formation update. now you can check in EC2 console that there is a new spot fleet with new instance type.
1
votes

The AWS docs has a complete step by step guide covering CloudFormationStack and ECS cluster launched manually.

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

From the guide:

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

  1. Update container instances launched in an ECS cluster through the AWS CloudFormation stack
  2. Update container instances launched manually in an ECS cluster