EC2 Container Service (ECS)

Reading Time: 3 minutes

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

ecs-cruise-control-ad

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 CPUReservation and 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.

elastigroup-gold

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.

untitled-drawing

How It Works

First things first, Launching a Spot cluster for ECS can be done easily when creating a Spotinst Elastigroup cluster. Just follow the steps below:

    1. 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.

    2. 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
    3. Configure the ECS integration

      Select the checkbox for the ECS integration from the “Compute” page of the Elastigroup edit mode. Select the name of the ECS cluster from the dropdown list.
      spotinst-_-console-google-chrome-2017-03-20-10-34-48

    4. 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.image-072

    5. 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.

      1. Navigate to your IAM console
        Go to – Roles.
      2. Create a new Role, Name it “ECS-ContainerInstance”
      3. Under “AWS Service Roles” choose the following role “Amazon EC2 Role for EC2 Container Service”
      4. Then attach the policy and create the Role.

 

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.