您对 ALB + ASG 作为一项技术的工作方式存在一些误解。
自动缩放组与目标组相关联。因此,与 ALB 目标组关联的 ASG 中的任何实例事实上都将成为 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 不会克隆现有实例;它们从与原始实例相同的启动配置中生成一个新实例。您在原始实例上所做的任何手动设置都不会出现在新实例上。你有两种方法来解决这个问题:\
- 创建您的第一个实例的 AMI,并更改 ASG 的启动配置以使用此新 AMI
- 利用 Userdata 在实例启动时自动配置您的容器化服务。