Tuesday, November 5, 2024
HomeCloudAWSHow to Create ECS Cluster on AWS

How to Create ECS Cluster on AWS

ECS is the AWS Docker container service that handles the orchestration and provisioning of Docker containers. This is a beginner level introduction to AWS ECS. I’ve seen some nightmare posts and some glowing reviews about the ECS service so I knew it was going to interesting to get my hands dirty and see what ECS was all about.

Summary of the ECS Terms

First we need to cover ECS terminology:

  • Task Definition — This a blueprint that describes how a docker container should launch. If you are already familiar with AWS, it is like a LaunchConfig except instead it is for a docker container instead of a instance. It contains settings like exposed port, docker image, cpu shares, memory requirement, command to run and environmental variables.
  • Task — This is a running container with the settings defined in the Task Definition. It can be thought of as an “instance” of a Task Definition.
  • Service — Defines long running tasks of the same Task Definition. This can be 1 running container or multiple running containers all using the same Task Definition.
  • Cluster — A logic group of EC2 instances. When an instance launches the ecs-agent software on the server registers the instance to an ECS Cluster. This is easily configurable by setting the ECS_CLUSTER variable in /etc/ecs/ecs.config described here.
  • Container Instance — This is just an EC2 instance that is part of an ECS Cluster and has docker and the ecs-agent running on it.

Some of AWS terms will confuse while we start working on it. Better to refer AWS provided detailed diagrams to help explain it.

In this tutorial example will create the sample httpd web service with Amazon sample webpage.

The ECS First Run Wizard provided in the Getting Started with Amazon ECS documentation performs the similar above with a CloudFormation template and ECS API calls. Will do it one by one, step by step to understand better.

Step1: Create Task Definition

In this step we have to mention the task definition name and container name and which image we would like to use in image section. And also we can limit the container usage using hard limit and soft limit. Once hard/soft limit set, have to set the port forwarding with hostport:containerport with protocol details either TCP or UDP.

If you like to limit the container usage or want to add more parameters like storage, mount point, entry point etc click advanced options for that.

Create task definition

Create a task definitionOnce you done, all click next step to proceed.

Step2: Configure service

Create a service with no of task you would like to and in network access select the container name which we created on last step.

configure serviceIf you would like to add application load balancer select the option “use the application Loadbalancer” and mention the port details as mentioned and mention the “Application Load Balancer target group name”.

ECS load balanceYou can select the IAM Role which is already exist or create the new one based on the requirement.

Once you done all required details, client next step to configure the cluster.

Step3: Configure the Cluster

In this mention the cluster name and EC2 instance type which you would like to create. And number of instance you would like to create.

Read More: What is Amazon Container Server

Then select the keyfile which you have for SSH a instance. If you missed, you cannot SSH a machine, so make sure you picked one.

And Securitygroup which you would like to use select it and Pick or create IAM role and click next to proceed.

configure cluster

Step4: Launch

Check each details and click launch instance to create the First ECS Cluster.

ECS launchOnce all launched successfully, you will see all Green. Like below. Cluster instance

Step5: Confirm Everything is Working

Confirm that the service is running properly. You want to be thorough about confirming that all is working by checking a few things.

Read More: What is Amazon Container Server

Check that my-target-group is showing and maintaining healthy targets. Under Load Balancing / Target Groups, click on my-target-group and check the Targets tab. You should see a Target that is reporting healthy.

Cluster instacne details

# ssh ec2-54-201-158-18.us-west-2.compute.amazonaws.com
# docker ps
# curl ec2-54-201-158-18.us-west-2.compute.amazonaws.com

Step6: Scale Up the Service to 4 Tasks

This is the easiest part. To scale up and add more containers simply go to Clusters / my-cluster / my-service and click on “Update Service”. You can change “Number of tasks” from 1 to 4 there. After only a few moments you should see 4 running tasks. That’s it!

Read More: What is Amazon Container Server

RELATED ARTICLES
- Advertisment -

Most Popular

Recent Comments