How's everyone doing? This section I have to admit is the one that I found the most difficult to understand all of the concepts within ECS so I hope that my notes will help explaining it in a simple way. Let's get started.
ECS
What AWS ECS (Elastic Container Service)?
- ECS is Amazon's platform for managing Docker containers.
- ECS clusters are groups of EC2 instances that run the ECS agent for Docker containers which then register the instance to the cluster.
- EC2 instances run an AMI designed for ECS
ECS Task Definitions, Services and Clusters
Task Definitions
Task Definitions are metadata in JSON format that give instructions to ECS on how to run a Docker container.
The contain crucial information about image names, port bindings for container and host, memory and cpu required, environment variables and networking information
ECS Services
We can configure the way tasks run and also how many should run and spread them amongst your EC2 instances and can also be linked to load balancers
Clusters
We need to create an ECS Cluster in which we add services and task definitions
Clusters can be of type EC2 or Fargate. For EC2 Clusters the corresponding EC2 instance are automatically created along with an autoscaling group
- A task definition depends on an ECS service in order to run
- Creating an ECS service also adds a Docker container image for it inside the EC2 instances
- We can update the number of tasks in the ECS service and corresponding ASG group if we want to scale
ECR
Let's talk about AWS ECR (Elastic Container Registry) which is a private repo for storing our Docker images
It is used for creating custom images locally and then push them to ECR so that they are available to use in ECS
To create a repo, in our CLI we need to
- Authenticate our Docker client to the ECR registry
- Build our Docker images
- Tag the image
- Push the image into ECR
Fargate
Let's talk about AWS ECS with Fargate
Fargate is a Serverless way of launching ECS Clusters
We only create the task definitions and AWS will run our containers. To scale we only increase the task number
We don't have to worry about managing EC2 instances anymore
ECS Task placement
Let's talk about ECS tasks placement
Task placement strategy: Determine where to place newly launched EC2 type tasks. Task placement constraints: Based on CPU, memory and available port. The same logic constraints also apply when scaling in and need to terminate tasks
Now about Task placement strategies we have
- Binpack: Based on the least available amount of memory or CPU which is great for cost savings
- Random: without any logical order
- Spread: Based on specified value like instanceId
- Mix them together
Summary
Most of these concepts mentioned above may not make perfect sense if you don't see them being applied on the AWS console but still they are good theory to know. Maybe that can be a future version of this sets of tutorials :)
Next week we're talking about Elastic Beanstalk where things start getting more interesting as we can see combination of several services.
Top comments (0)