You might have heard about Docker. What it provides is- containers, which are light weight images that can be run independently. What is container ? A running Docker image is called an container. The only thing that you need is a Docker Engine. It has lot of bla bla benefits.
But the problem is how can you manage 1000’s of containers that has to scale up and down.
For this you need something called container orchestrator.
Kubernetes is one of the popular open source container orchestration tool.
AWS provides its own container orchestration in the form of EKS and ECS.
Container Orchestration
What are the benefits of a Container Orchestrator that a container (Docker) lacks ?
- Auto scaling
- Zero downtime deployments
- Service Discovery
- Self Healing
- Load balancing
What are the different Container Orchestrators in the market ?
- Kubernetes: This is a popular open source container orchestration service.
- AWS has 2 Container Orchestrators:
- EKS (Elastic Kubernetes Service): this is based on Kubernetes.
- ECS (Elastic Container Service): this is there long before Kubernetes came into picture.
Below is a generic diagram of Container Orchestrator:
AWS EKS: (Elastic Kubernetes Service)
This service would be required if you are currently using Kubernetes and want to migrate your Kubernetes clusters to AWS.
AWS ECS: (Elastic Container Service)
We can use Fargate(server less) or EC2 for this.
Below are the items that you need for the same:
Container: Here you have to choose an image. An running image is called a container.
Task: Task definition is the blueprint of your application. It is similar to Pod in Kubernetes. Here you choose the node as Fargate or EC2. Then specify the Container. Inside container specify the docker Image as well. After running this Task in a cluster, it will have an IP address, FYI, in Kubernetes, a Pod also has an IP address. If you delete an task, automatically another task is started by the service.
Service: Service allows you to run and maintain a specified number of Tasks in a Cluster.
Cluster: This is the group of services that ran for an application. If you are using Fargate then it would be a fully managed service from AWS.
Lets create an ECS Cluster on AWS.
Go to AWS Console and search for “ECS”. If there are no ECS clusters defined you will see just below page, but if there is some clusters defined then you will see this page.
Hit Get Started.
If you see, by default its choosing Fargate by this way.
Edit the container name and task name
make the Number of desired tasks to 2.
and finally the cluster name:
Review the configuration and hit “Create”. You will see below screen.
Just an advice when the below screen is running don’t go away from the screen, seems there is an bug in AWS, if you go away from this screen the clusters may not be created normally.
If you go to the Clusters page:
We had given the desired tasks to be 2.
Now just Stop one of the task. Can you guess what would happen ?
Well, in the begining I had stated that the Service ensures that the specified number of tasks should always run, so after sometime it will automatically start another task and finally you will get the desired number of task, and that is 2.
I had deleted one task and after the desired task is running successfully, I checked the Events tab :
If you go behind the scene and try to see what are the machines (EC2) used for this cluster, you will see 0 instances running, because its Fargate, you can’t see anything what is happening behind the scene, may be they would be using EC2 but you can’t see it.
OK… Till now you have seen how to create an ECS cluster using Fargate.
Now lets see how to create an Cluster with EC2 instances.
In AWS Console if you search- “ECS”, you will land up below page.
Click “Create Cluster”. You will see 3 options for creating ECS. First one is the Fargate way, but we will use the 2nd option EC2 Linux one.
Here you can give it a name, EC2 instance type, number of instances, etc. etc..
We are not going to create a EC2 cluster now. And yes don’t forget to terminate all your clusters, if you are doing it for learning, the charges are too high.