简体   繁体   中英

How do i setup ECS autoscaling?

I'm using ECS through ecs-cli to deploy my API.

I start by launching a cluster of spot instances using this command:

sudo ecs-cli up --region MY REGION --keypair MY KEY PAIR --instance-type t2.micro --capability-iam --size 1 --cluster MY CLUSTER NAME --spot-price 0.01

Then, using the following docker-compose.yml and ecs-params.yml files:

version: '3'

services:
  selenium:
    image: selenium/standalone-chrome
    ...etc

  api:
    image: myapithatusesselenium/myapithatusesselenium
    ports:
      - 3000:3000
    links:
      - selenium
    ...etc
version: 1
task_definition:
  task_execution_role: ROLE ID
  services:
    selenium:
      cpu_shares: 600
      mem_limit: 700000000
    api:
      repository_credentials:
        credentials_parameter: REPO CREDENTIALS
      cpu_shares: 400
      mem_limit: 300000000

I'm deploying a service with a load balancer using this command:

sudo ecs-cli compose --file docker-compose.yml --ecs-params ecs-params.yml --project-name MY PROJECT NAME service up --cluster MY CLUSTER NAME --target-group-arn LOAD BALANCER RESSOURCE ID --container-name api --container-port 3000

So, When my API is under a lot of load (When it starts notifying me that the API is going down) I add additional instances by scaling using these commands:

# 1 - scale the number of ec2 instances in the cluster
sudo ecs-cli scale --size 3 --capability-iam
# 2 - scale the number of tasks
sudo ecs-cli compose --file docker-compose.yml --project-name MY PROJECT NAME service scale 3

As you can see the number of tasks and ec2 instances is the same because each container can handle a single task.

When there isn't a lot of load I reduce the size again.

What I need right now is a way to make this automatic (Auto scaling in and out). I can't figure out how to do that.

Thank you !

ECS doesn't nativly autoscaling. You have to use the application autoscaling service for that. You'll need to use the regular aws CLI and call register-scalable-target, and then create a scaling policy

https://docs.aws.amazon.com/AmazonECS/latest/developerguide/service-auto-scaling.html

https://docs.aws.amazon.com/cli/latest/reference/application-autoscaling/register-scalable-target.html

https://docs.aws.amazon.com/cli/latest/reference/application-autoscaling/put-scaling-policy.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM