AWS Autoscaling与负载均衡器

时间:2018-04-26 13:54:58

标签: amazon-web-services amazon-ec2 aws-ecs aws-load-balancer

我已经在1个EC2实例上部署了一个http侦听器容器化应用程序,方法是创建一个包含1个实例并在该实例上运行容器任务的集群。

我正在使用自动缩放EC2实例功能,最小实例为1,最大实例为4。

我面临的问题是。

  1. 由于更多的负载/ CPU利用率而创建新的EC2实例 - 在第一个实例上部署的容器不会在这些新实例上复制。

  2. 我想在这些EC2实例添加(或终止)时添加负载均衡器。由于实例需要已经注册到目标组 - 我将无法添加新实例,因为它们尚未创建。

  3. 非常感谢任何帮助。

1 个答案:

答案 0 :(得分:1)

您对ALB + ASG如何作为一项技术工作存在一些误解。

自动缩放组与目标组关联。因此,ASG中与ALB目标组关联的任何实例事实上都将成为ALB的可行目标 - 前提是实例是健康的。

I want to add load balancer in front of these EC2 instances as and
when they gets added (or terminated). As the instances needs to be
already registered to the target group - i will not be able to add
the new instances as they are not yet created.

将实例添加到ASG,目标组将ASG作为目标。创建ALB,为ALB创建目标组,创建ASG并将其分配给目标组。

关于你的第一个问题:

Once new EC2 instances are created due to more load/ CPU utilization -
the container which were deployed on first instance is not replicated
on these new instances.

ASG不克隆现有实例;它们从与原始实例相同的启动配置中生成一个新实例。您在原始实例上执行的任何手动设置都将出现在新实例上。您有两种解决方法:\

  1. 创建第一个实例的AMI,并更改ASG的启动配置以使用此新AMI
  2. 使用Userdata在启动实例时自动配置容器化服务。