How have the tutorials for docker been coming along?. So far we have simplified how to learn Docker using two files, we have learned how to push images to AWS ECR or Docker Hub.
For production, we will need to manage our containers. This is where AWS ECS comes along.
Amazon Elastic Container Service (ECS) is a highly scalable, high-performance container management service that supports Docker containers and allows you to easily run applications on a managed cluster of Amazon EC2 instances. Amazon ECS eliminates the need for you to install, operate, and scale your own cluster management infrastructure.
- Application first with Capacity Providers
- Performance at scale
- Optimized for cost
- Hybrid Development
- Batch processing
- Machine Learning
- Web Applications
There are two different charge models for Amazon Elastic Container Service (ECS).
Fargate launch Type Model
With Fargate, you pay for the amount of vCPU and memory resources that your containerized application requests. Read more about the pricing of Fargate https://aws.amazon.com/fargate/pricing/
EC2 launch Type Model
There is no additional charge for EC2 launch type. You pay for AWS resources (e.g. EC2 instances or EBS volumes) you create to store and run your application. Read more about the pricing of EC2 https://aws.amazon.com/ec2/pricing/
Now that we have a brief explanation of what AWS ECS is let us get practical and learn how to deploy our containers on AWS ECS.
With ECS there are three components that will simplify your understanding in working with AWS ECS.
A task definition is like a blueprint for your application. Each time that you launch a task in Amazon ECS, you specify a task definition. The service then knows which Docker image to use for containers, how many containers to use in the task, and the resource allocation for each container.
An Amazon ECS cluster is a logical grouping of tasks, services, and container instances. When creating a cluster using the console, Amazon ECS creates an AWS CloudFormation stack that takes care of the Amazon EC2 instance creation, networking, and IAM configuration for you.
An Amazon ECS service enables you to run and maintain a specified number of instances of a task definition simultaneously in an Amazon ECS cluster. If any of your tasks should fail or stop for any reason, the Amazon ECS service scheduler launches another instance of your task definition to replace it in order to maintain the desired number of tasks in the service.
The steps for deploying your images to ECS will be you need to create a cluster, a Task definition with all the configuration, and a service.
In our previous tutorial, we learned how to push our images to AWS ECR and Docker Hub https://dev.to/kevin_odongo35/aws-ecr-or-docker-hub-4m7o.
We have a default Vue application. We built an image and pushed it to AWS ECR. We will deploy this to the ECS cluster.
- Once we have our image in ECR then we can go ahead and deploy our cluster. Search for ECS and click get started.
- Get the image URI from AWS ECR and configure the custom section then click next.
- In the next section select Application Load Balance.
In AWS we will an Application Load Balancer to direct traffic to each container. With ALB we can define different target groups and assign them to different clusters.
Target group is used to route requests to one or more registered targets.
Read more about Application Load Balance target groups https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-target-groups.html.
Once done review and click create.
Once deployed go to EC2 Dashboard and search for Load Balancers. Get the DNS Record. Your application should be running.
How to create a new version.
Assume you have changed your website and would like to deploy a new version. Build a new image with the new version and tag it then push it to AWS ECS. In below image you can see i have two versions in my ECR.
Use the image to create a new task definition and update the service.
This is just a quick way to get started with AWS ECS. In a large production, you need to understand how to use Application Load Balance especially configuring target groups because that is the way traffic to your containers will be routed. Just as Nginx does.
I hope this will be helpful to someone who wants to get started with ECS. In my own opinion using ECS is easy to get you started with container orchestration.