EC2 Container Service (ECS)
“Getting started with Docker containers is relatively easy, but deploying and managing containers, in the thousands, at scale is difficult without proper cluster management. Maintaining your own cluster management platform involves installing and managing your own configuration management, service discovery, scheduling, and monitoring systems.”
Werner Vogels, CTO – Amazon.com
Docker containers are ideal for running on Spot instances and our support for ECS (AWS’ EC2 Container Service) makes it a cinch to do.
More Sophisticated Cluster Scheduling
Elastigroup automatically fetches
AWS/ECS CloudWatch metrics like
MemoryReservation so you can easily scale up or down EC2 resources whenever it is needed. Those metrics are presented within the context of the ECS cluster to enable maximum control over your ECS resources.
Safe Instance Draining
Elastigroup uses AWS ECS API calls to communicate with the ECS cluster’s scheduler to make sure your desired Task and Services are operating as expected. Whenever an EC2 instance is scheduled for replacement, whether if its due to Scale Down activity or a Spot Replacement Elastigroup invokes the
deregisterContainerInstance to notify the ECS scheduler and forces rescheduling of the containers that run on the hosts as well as safely drain the instance from the attached Elastic Load Balancers.
First things first, Launching a Spot cluster for ECS can be done easily when creating a Spotinst Elastigroup cluster. Just follow the steps below:
Select the correct ECS AMI
Amazon ECS provides ECS Optimized AMIs which contains Amazon ECS agent, and automatically registers new instances to your desired ECS cluster.
Select the appropriate ECS AMI and when creating your Spotinst Elastigroup, enter the image id in the “Launch Specifications” section.
Configure the ECS cluster
By default, your container instance launches into your default cluster. If you want to launch into your own cluster instead of the default, please fill the following script into the User data field, replacing YOUR_ECS_CLUSTER_NAME with the name of your desired cluster.
#!/bin/bash echo ECS_CLUSTER=CLUSTER_NAME >> /etc/ecs/ecs.config
Configure the ECS integration
Configure Scaling Metrics
When configuring scaling metrics be sure to add the dimension for “ClusterName” and provide the ECS cluster name for all scaling policies as you can see below. This will ensure scaling metrics will appear on your Elastigroup dashboard.
Create an IAM role for your container instances and services
Before the Amazon ECS agent can register container instance into a cluster, the agent must have IAM Role with appropriate account credentials.
If you haven’t done that already, Create the ECS IAM Role.
- Navigate to your IAM console
Go to – Roles.
- Create a new Role, Name it “ECS-ContainerInstance”
- Under “AWS Service Roles” choose the following role “Amazon EC2 Role for EC2 Container Service”
- Then attach the policy and create the Role.
- Navigate to your IAM console
Now, On the Elastigroup setup, you should specify the newly created IAM Role under “Launch Specification”
That’s it, you have an ECS cluster configured to run with Spotinst Elastigroup.