ECS Cluster Auto Scaling EC2 Instance with Application Load Balancer
AWS ECS Cluster is a logical grouping of tasks or services based on docker containers. It provides a shared resources to run and manage containers. This article is going to show you how to manage the resource, scale the instances and serve them behind an Application Load Balancer
The original system need to be scaled is many services run in different docker containers and served behind an nginx reverse proxy
To scale this system, we’re going to use Auto scaling group to scale the number of EC2 instances and serve all these EC2 instances through an Application Load Balancer
How does the above diagram work?
The idea of the above diagram is simply duplicate the whole EC2 instance and serve them behind one Application Load Balancer using Auto Scaling Group
What happen when ASG launches a new instance?
When the instance meets an AS policy (i.e Average CPU Utilization > 90% for 5 minutes), ASG will launch a new instance using the configuration from Launch Configuration.
In this step, we need to setup the Launch Configuration to run all necessary tasks in the new instance. This steps will be done using user-data scripts
What happen when we deploy new version of services
When we deploy new versions of services, we need to stop all running services and replace the task definition, then scale out to all instances. To do this, we use below scripts