Let’s see, how to create a Multi-node ECS Cluster in AWS and task definitions to run containerized scalable applications smoothly. I have been working with few AWS labs and I thought to write up the steps that I followed just to share my experience with my followers.
Just select the ECS (Elastic Container Service), in the number of listed AWS services.
It will lead you to the “Get Started” page, and you can follow a wizard driven steps to create an ECS cluster. But I’m gonna follow the manual creation of a cluster. To do that select the “Clusters” as below.
Click on “Create Cluster” to begin the cluster deployment
You can select three different options as the cluster template:
- Networking Only
- EC2 Linux + Networking
- EC2 Windows + Networking
I’m going to deploy a linux based ECS cluster so, I selected “EC2 Linux + Networking” option. Proceed to the “Next Step“.
Select EC2 Instance type, number of instances, AMI, Storage Key pair, if you need to connect to underline EC2 instances and also VPC configurations such as Name, CIDR and Subnets
Container Instance IAM role is a necessary aspect for this ECS setup, which ECS agent to communicate with Amazon ECS API. “ecsInstanceRole” should be selected, and if it is not configured already. This is the option for you to configure it. Once all the settings are in place it’s time to create the cluster.
It will spin up a “CloudFormation Stack” and you can see the status of this, and by clicking on the small link to the stack, you can see more information
This was the status of my “CloudFormation Stack“
Once you go back to the “Clusters“, informations is visible about your container instances. See the ECS Agent connection status.
Create An ECS Task Definition
ECS Task Definition should be created in order to run the Docker Containers, some parameters such as Docker Image version, CPU and Memory, Docker networking, logging, etc should be specified here.
Basically, two options available at the time of this, “FARGATE” or the “EC2” should be selected, if the intention is a self managed EC2 infrastructure, EC2 is the choice. There are use cases for these two selections, and I’m not gonna discuss all of them in this article.
I used EC2 as my Launch type for this ECS deployment
In the next step, task definition parameters such as Name, Role, Networking mode should be specified and more information can be find in this AWS document. Scroll down for more configuration options
Task memory and cpu can be configured and containers should be added in this step
Under the “Add container” wizard, container details such as container name, docker image version, Hard memory limit, port mapping, health check, etc can be configured.
All these configurations can be saved as a json file and it can be used in a later time for the similar configuration
Once you completed the tasks definition, run the task
Select the launch type, run the task
Check the tasks status, if it is “PENDING” wait for sometime, until it become “RUNNING“.
Specific information can be find changing the tabs, move to ECS instance tab to see the container information
By clicking on the instances, link instance public IP address and DNS details can be found.
My Nginx container is publicly accessible with port 80 as I specified in the Task Definition.