Would you like to run and orchestrate Docker containers automatically on AWS? Do your applications need to scale up or down continuously, based on different metrics? Do you have microservices applications running on Docker containers? Would you like to free up compute resources after jobs or applications finish processing?
If so, this blog is for you. We’ll take a look at ECS, Amazon’s container management system, and its task placement strategies, to help you improve scalability and efficiency.
Amazon Elastic Container Service (Amazon ECS) is a fast, highly scalable, high-performance service that manages Docker container orchestration using the compute capabilities of Amazon. It eliminates the need to install and operate your own container orchestration software, manage and scale a cluster of virtual machines, or schedule containers on those virtual machines. Amazon ECS uses Amazon Elastic Container Registry (Amazon ECR) to store the images needed to run the containers, but it can also retrieve images directly from Docker Hub. Docker daemon is used to run the containers inside an Amazon ECS Cluster.
Amazon ECS enables you to:
Within a cluster, an Amazon ECS task is the instantiation of a task definition (the configuration that a Docker container will use when it is created by an ECS service such as image, volumes, environment variables, memory, CPU, etc.). After you have created a task definition for your application within Amazon ECS, you can specify the number of tasks that will run on your cluster.
When a task is launched, Amazon ECS determines where to place it based on the requirements specified in the task definition. When the number of tasks is scaled down, Amazon ECS determines which tasks to terminate.
Task placement strategies (logic to fine-tune task placement or tasks for termination) and constraints (task placement hard limits) enable you to:
Service task placement strategies cannot be updated. If updating is required, the service will need to be recreated. Adding task placement strategies and constraints in AWS CloudFormation will cause a resource recreation instead of an updation.
Binpack places tasks on the instance which can fulfill the least requirements of memory and CPU, perfect for saving instance costs.
Spread allocates tasks evenly across instances to achieve high availability.
Random places tasks randomly across the cluster.
You can chain together multiple task placement strategies with their respective attributes, up to five strategy rules per service.
Let’s say you have a requirement to spread your tasks across availability zones while also minimizing the usage of memory and saving instance costs. You can chain the spread and binpack placement strategies to first spread the tasks across availability zones and then place them in a binpack configuration based on memory utilization.
It should look something like the following:
placementStrategy": [
{
"field": "attribute:ecs.availability-zone",
"type": "spread”
},
{
"field": "memory",
"type": "binpack"
}
]
"placementConstraints": [
{
"type": "distinctInstance"
}
]
We recommend that you use ECS Task Placement Strategies to:
Need help with containers? The nClouds team is here to help with that and all your AWS infrastructure requirements.
Top takeaways: AWS Managed Microsoft AD and Microsoft Active Directory
2022-12-05 15:25:16