Container Orchestration on AWS: ECS, EKS, Fargate, and ECR
As Tech World is progressing from Monolith architecture to Microservice-based Architecture it is important to the concepts of Container Orchestration. Hence this guide will introduce you to the containerization options provided by Amazon Web Services.
In a Microservices-based Architecture, the whole application is broken down into small units. Each unit sticks to a specific section of the processing required by the application. In a microservice-based architecture, high cohesion and loose coupling are primary objectives. These tiny units are developed and contained in containers.
Now a high-level concept simply states that
- Each microservice takes an input, performs some processing function, and then releases the output either to be processed by another microprocessor or consumed by the customer themselves.
- Microservices are encapsulated in containers. These containers provide a virtual running environment to the code and they are scaled as per requirement.
Now in order to deploy these containers a host environment is required. Some companies host these containers on-premise data centers and some host them in the cloud, which depends on the deployment models they are using. Amazon Web Services provides a comprehensive set of services that can be used to host and manage micro-services based architecture on their virtual environment for container orchestration.
Note: If you are migrating your architecture to containers which was previously based on a monolith architecture. I Suggest your first step should be Re-architecting your application rather than just Refactoring or Re-platforming. Your code must be broken down into small units before it is hosted on containers.
Containers on AWS
Containers on EC2
If you are migrating your containerized application from an on-premise setup to Cloud the first and most primitive option that you can use is EC2 instances. Just as deployed on-premise your containerized application can be deployed on EC2 instances that have docker installed on them.
Yet the question that arises at this point will be about container management. How are you going to manage these containers? Because the only difference that you are going to observe in this on-premise vs cloud based deployment is a virtually available server. For an application that is in its initial stages of development it might be the right option for you to deploy your containers on an EC2 instance. Or may be an application that is not live yet is merely in the development and testing stage. But for a full fledged application that requires scaling from time to time due to increased incoming traffic AWS managed Containerization services are a must. AWS provides following services that can help with Container Orchestration.
Why go for AWS Container Orchestration if you have EC2?
- Maintenance: Just like any resource containers are required to be managed. Continuous monitoring is required to tell the remaining resource capacity and current container health situation. Operations such as maintenance and troubleshooting are tedious tasks. Hence some of the load needs to be taken away from the end user if the hosted application has a greater scope or impact.
- Scaling Infrastructure vs Scaling Containers: How can you tell how many instances are required to support the traffic hitting your application. Hence scaling EC2 instances becomes a difficult task. And Scaling the containers would be another job since you’ll have to manually create and dispose of containers every time you are required to do so.
- Cost: EC2 instances are not a cost effective option for containerized applications since you will be paying for the whole server even if you are not using it.
Container Orchestration Tool
A container orchestration tool helps you automate tedious operations of Container:
Of-course there are tools that you can use for container orchestration and some of them include Kubernetes, Docker Swarm, HashiCorp Nomad and an AWS managed service called Elastic Container Service (ECS).
AWS Elastic Container Service (ECS)
Elastic Container Services as a container orchestration tool automates the daily operations like Container lifecycle Management that decides when a container will be :
- Load Balanced
How to use ECS for Container Orchestration?
- Container Orchestration: Simply create an ECS Cluster which acts as a Control Center. ECS includes services that are required to manage the whole LifeCycle of your Containers.
- Hosting: In order to host these containers you still need an underlying infrastructure so for that AWS provides its EC2 instances.
How is this setup different from the previous one?
- ECS Agents will be installed on these EC2 instances to help you manage and monitor the containers.
- EC2 instances act as an underlying architecture and you are partially responsible for managing these instances. These instances have Docker Agent installed on them so that they can host your containers.
What hasn’t changed?
ECS Agent just takes control of the Docker side management and EC2 still remains your responsibility.
- You’ll have to make the EC2 instance part of the ECS cluster whenever a new instance is created.
- Also that you are responsible for scaling your EC2 instances so that you have enough resources to scale your Containers.
- You are still responsible for maintenance, upgradation and patching these EC2 instances.
Fargate managed ECS
So far ECS is handling your Container Orchestration and Infrastructure (EC2 instances) falls under your jurisdiction. Now, If you don’t want this headache of Hosting Infrastructure Management either and want to delegate this operation to AWS. AWS provides this amazing service called AWS Fargate which is based on the concept of serverless technology.
AWS Fargate is simply an engine that takes away the headache of provisioning and managing EC2 instances for your Containers. AWS Fargate is proved to be the fastest way of scaling your Containers. AWS Fargate acts similarly as Autoscaling does in case of EC2. Depending upon the requirement for containers to scale AWS Fargate scales hosting VMs as well.
How does it work?
You are simply responsible for providing the container to AWS Fargate engine which automatically scales after analyzing the resource requirement of your container.
- You pay as you go.
- You don’t have to manage infrastructure and scaling becomes easy.
- Maximum Utilization of resources you are paying for.
Other AWS Services that you can Integrate with ECS:
- Monitoring: Cloud Watch
- Elastic Load Balancer
- Virtual Private Cloud
- Web Application Firewall etc.
AWS Managed Elastic Kubernetes Service (EKS)
AWS managed Elastic Kubernetes Service allows you to use Kubernetes as your primary container Orchestration Tool. AWS manages Kubernetes Clusters for you just like ECS helps with managing Containers running on EC2 instances. If your organization is already using Kubernetes Clusters to scale and manage micro-services then EKS is your AWS hosted solution. A huge advantage of hosting your Kubernetes Clusters on AWS is that Master nodes become responsible for AWS.
How does it work?
- You create an EKS Cluster where the Master nodes are managed by AWS and you just manage Worker nodes.
- Master Nodes already has Kubernetes Master Services installed on these nodes and automatically these master nodes are replicated across multiple availability zones for availability.
- The Etcd storage used to store Cluster Configuration is also managed by AWS
- As for Worker nodes similar to ECS you are responsible for creating EC2 instance based Compute Fleet which will host your Kubernetes Clusters. Unlike ECS although EKS provides a partially managed approach to manage your EC2 instances. Instances are scaled up or down for you yet configuration remains your responsibility.
EKS vs ECS
The following comparison between both ECS and EKS shows when you should choose ECS and when EKS will be your best option. This comparison is not targeting pros vs cons.
- If you’re already using Kubernetes then EKS will be a familiar choice for you. In case you are just getting started with container based architecture ECS gives you a safe playground to start.
- An EKS based architecture allows you to keep your options open for migration which is not an option in case of ECS which is a proprietary solution of AWS. In case your EKS Cluster is using other AWS Services then it is still going to be difficult to migrate.
Fargate managed EKS
Similarly as Fargate managed ECS in this setup AWS completely manages your EKS Cluster for you.
AWS Elastic Container Registry (ECR)
ECR as the name indicates is a Container Registry Service that acts simply as a replacement of DockerHub for companies that are reluctant to share their docker images online.