简体   繁体   English

如何设置 ECS 自动缩放?

[英]How do i setup ECS autoscaling?

I'm using ECS through ecs-cli to deploy my API.我正在通过ecs-cli使用 ECS 来部署我的 API。

I start by launching a cluster of spot instances using this command:我首先使用以下命令启动一个 Spot 实例集群:

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:然后,使用以下 docker-compose.yml 和 ecs-params.yml 文件:

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:因此,当我的 API 承受大量负载时(当它开始通知我 API 正在下降时)我通过使用以下命令进行缩放来添加其他实例:

# 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.如您所见,任务和 ec2 实例的数量是相同的,因为每个容器都可以处理单个任务。

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. ECS 本身不会自动缩放。 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您需要使用常规 aws CLI 并调用 register-scalable-target,然后创建扩展策略

https://docs.aws.amazon.com/AmazonECS/latest/developerguide/service-auto-scaling.html 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/register-scalable-target.html

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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