如何根据ECS群集资源可用性扩展/扩展EC2实例? [英] How to scale in/out EC2 instances based on ECS cluster resources availability?

查看:96
本文介绍了如何根据ECS群集资源可用性扩展/扩展EC2实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的ECS群集中正在运行多个服务。每个服务都包含一个或多个基于CPU利用率或多个用户的任务。
我已经使用EC2启动类型部署了这些容器。
现在,我想基于集群中的可用资源来增加/减少EC2实例的数量。
假设在两个m5.large实例中有四个ECS任务正在运行。



现在,如果ECS服务增加了任务数量并且没有群集中有足够的可用资源,如何启动实例并添加到群集中?



反之亦然。如果其中运行的实例中没有ecs任务,该如何自动销毁它?



PS-我使用的是Fargate。由于费用很高,因此我移至EC2实例。

解决方案

您需要像@Nitesh所说的那样在ASG中设置ecs集群实例,其次您需要设置cloudwatch警报基于ecs的关键指标,这很复杂,因为您需要设置两个自动伸缩策略,一个由服务提供,另一个由服务来扩展实例,对于ec2,您可以使用的指标是群集CPU预留和/或群集内存预留。 / p>

该方案的工作方式如下:您的服务使用服务的关键指标通过自动缩放规则增加所需容器的数量,例如CPU使用率或请求数量在负载均衡器中,因此,群集CPU预留的增加会触发cloudwatch警报,而您的ASG会增加instaces的数量。



一些技巧可以快速放大,而缩小



对于容器,可以通过设置警报时间来降低速度矿石信息,请参见



https://docs.aws.amazon.com/AmazonECS/latest/developerguide/cloudwatch-metrics.html#cluster_reservation



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



> https://aws.amazon.com/blogs/compute/automatic-scaling-with-amazon-ecs/



我希望这项帮助



致谢


I have multiple services running in my ECS cluster. Each service contains one or more tasks based on CPU utilization or a number of users. I have deployed these containers with EC2 launch type. Now, I want to increase/decrease the number of EC2 instances based on available resources in the cluster. Let's say there are four ECS tasks running in two m5.large instances.

Now, if an ECS service increases the number of tasks and there aren't enough resources available in the cluster, how can I spin up an instance and add to the cluster?

And same goes for vice versa. If there is instance running with no ecs task in it, how can I destroy it automatically?

PS - I was using Fargate. Since it's cost is very high, I moved to EC2 instances.

解决方案

you need to setup your ecs cluster instances in a ASG as @Nitesh says, second you need to set up a cloudwatch alert based in a key metric, with ecs is complex because you need to set up two autoscaling policies one by service another one to scale up your instances, for ec2 the metric that you could use is Cluster CPU reservation and /or Cluster memory reservation.

The scheme works like this your service increases the number of the desired container by an autoscaling rule using a key metric for your service as could be de CPU usage or the number the request in a load balancer and in consequence the Cluster CPU reservation increase this triggers the cloudwatch alert and your ASG increase the number of instaces.

Some tips scale up fast, and scale down slow this could by handle by setting up the time of the alerts

For the containers use Service Auto Scaling and Target tracking policies for more info see

https://docs.aws.amazon.com/AmazonECS/latest/developerguide/cloudwatch-metrics.html#cluster_reservation

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

https://aws.amazon.com/blogs/compute/automatic-scaling-with-amazon-ecs/

I hope this help

Regards

这篇关于如何根据ECS群集资源可用性扩展/扩展EC2实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆