Loading Posts...

How To Create A Multi-Node ECS Cluster And A Task Definition In AWS

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.

Create A Multi-Node ECS Cluster Select Service

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.

Create A Multi-Node ECS Cluster Clusters

Click on “Create Cluster” to begin the cluster deployment

Create A Multi-Node ECS Cluster Create Cluster

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

Create A Multi-Node ECS Cluster EC2 Linux

In this step, provide a cluster name, and select the instance types from the Spot Instances and On Demand instances. Scroll down for more configuration options.

Create A Multi-Node ECS Cluster Instance

Read More: VMware Kubernetes Academy – A Free Education Platform

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

Create A Multi-Node ECS Cluster VPC Config

In terms of AMI, you have two different versions Amazon Linux 1 and Amazon Linux 2.

Create A Multi-Node ECS Cluster AMI Selection

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.

Create A Multi-Node ECS Cluster AMI Role

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

Create A Multi-Node ECS Cluster Cloud Formation

This was the status of my “CloudFormation Stack

Create A Multi-Node ECS Cluster Cloud Formation Stack

Once you go back to the “Clusters“, informations is visible about your container instances. See the ECS Agent connection status.

Create A Multi-Node ECS Cluster ECS 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.

Create A Multi-Node ECS Cluster Task Definition

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

Create A Multi-Node ECS Cluster EC2

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

Create A Multi-Node ECS Cluster New Task Definition

Task memory and cpu can be configured and containers should be added in this step

Create A Multi-Node ECS Cluster resources

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.

Create A Multi-Node ECS Cluster container version

All these configurations can be saved as a json file and it can be used in a later time for the similar configuration

Create A Multi-Node ECS Cluster json

Once you completed the tasks definition, run the task

Create A Multi-Node ECS Cluster run task

Select the launch type, run the task

Create A Multi-Node ECS Cluster type

Check the tasks status, if it is “PENDING” wait for sometime, until it become “RUNNING“.

Create A Multi-Node ECS Cluster container status

Specific information can be find changing the tabs, move to ECS instance tab to see the container information

Create A Multi-Node ECS Cluster container instance type

By clicking on the instances, link instance public IP address and DNS details can be found.

Create A Multi-Node ECS Cluster public DNS

My Nginx container is publicly accessible with port 80 as I specified in the Task Definition.

Create A Multi-Node ECS Cluster Nginx page

Aruna Lakmal

Associate Technical Specialist at Pearson, Sri Lanka. Technology junky, enthusiast, a VMware vExpert and a blogger with more than 7 years of Experience in Information Technology more focusing on VMware Virtualization, Microsoft and Datacenter Technologies.

Get Updates Directly To Your Inbox!

   

Leave a Reply

Loading Posts...