带有两个负载均衡器的ECS服务用于同一端口:内部和面向互联网 [英] ECS service with two Load Balancers for same port: internal and internet-facing

查看:268
本文介绍了带有两个负载均衡器的ECS服务用于同一端口:内部和面向互联网的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试在ECS集群上应用修改时遇到麻烦。环境的特殊性:

I'm having trouble while trying to apply a modification on a ECS cluster. Particularities of the environment:


  • 集群有2种服务:蓝色和绿色。

  • 当前两种服务与暴露在Internet上的应用程序负载平衡器
    相关。

我想做的事:添加另一个ALB ,在这种情况下是内部的,用于接收来自VPC专用子网的相同服务(相同容器,相同端口)的请求。尝试应用这些修改时,出现以下错误:

What I want to do: add another ALB, in this case an internal one, to receive requests from private subnets in the VPC for the same service (same container, same port). When trying to apply those modifications I'm getting the following error:

CloudFormation cannot update a stack when a custom-named resource requires replacing. Rename [ClusterName|ServiceName] and update the stack again.

我正在使用yml文件描述这些新实体。值得一提的是,新的负载均衡器,其侦听器和目标组已成功创建(即使目标组未检测到EC2实例)。将LB添加到ECS服务时会出现问题。这正常吗?同一端口和相同容器名称的相同ECS服务是否可以有2个LB?是否有解决方法,而无需重命名群集?

I'm describing these new entities using yml files. It's worth to mention that the new load balancer, its listeners and target groups were created successfully (even though the target group is not detecting the EC2 instances). The problem occurs when adding the LB to the the ECS service. Is this normal? Is it possible to have 2 LBs for the same ECS service for same port and same container name? Is there a workaround for doing this without renaming the cluster?

编辑:我尝试创建一个带有2个负载均衡器的新ECS服务,但出现以下错误(

I tried creating a new ECS service with 2 load balancers associated to it and I got the following error (which is much more specific):

load balancers can have at most 1 items

因此,ECS服务不能与多个ALB关联。剩下的问题是:除了为私有子网创建新的ECS服务以外,还有其他解决方法吗?

So no, ECS services can't be associated to more than one ALB. The remaining question is: is there a workaround for this other than creating new ECS services for private subnet use?

谢谢。

推荐答案

2019年7月30日,Amazon ECS发布了对在ECS服务中使用多个负载均衡器/目标组的支持。来自他们的新博客文章

On the 30th of July 2019, Amazon ECS released support for working with multiple load balancers / target groups in an ECS service. From their What's New blog post:


Amazon ECS服务现在支持多个负载均衡器目标组

您现在可以将多个目标组附加到运行在Amazon EC2或AWS Fargate上的Amazon ECS服务

使用负载平衡器时,目标组
用于将请求路由到一个或多个注册目标。将多个目标组附加到
服务可以使您简化基础架构代码,降低成本并提高
增强ECS服务的可管理性。

You can now attach multiple target groups to your Amazon ECS services that are running on either Amazon EC2 or AWS Fargate. Target groups are used to route requests to one or more registered targets when using a load balancer. Attaching multiple target groups to your service allows you to simplify infrastructure code, reduce costs and increase manageability of your ECS services.

如文档中所述,这将启用不同的设置,包括与您在问题中提到的内部和外部负载平衡器集成。从 docs (重点是我):

As described in the docs, this enables different setups, including integration with internal and external load balancers as you mention in your question. From the docs (emphasis mine):


示例:内部外部
流量。

Example: Having separate load balancers for internal and external traffic.

在以下用例中,服务使用两个单独的负载
平衡器,一个用于内部流量,第二个用于负载面向相同容器和端口的面向Internet的
流量。

In the following use case, a service uses two separate load balancers, one for internal traffic and a second for internet-facing traffic, for the same container and port.



"loadBalancers":[
   //Internal ELB
   {  
      "targetGroupArn":"arn:aws:elasticloadbalancing:region:123456789012:targetgroup/target_group_name_1/1234567890123456",
      "containerName":"nginx",
      "containerPort":8080
   },
   //Internet-facing ELB
   {  
      "targetGroupArn":"arn:aws:elasticloadbalancing:region:123456789012:targetgroup/target_group_name_2/6543210987654321",
      "containerName":"nginx",
      "containerPort":8080
   }
]

有关AWS容器服务的公共路线图的github问题(现已关闭)在这里找到:

Related (and now closed) github issues from the public roadmap of the AWS container services are found here:

  • https://github.com/aws/containers-roadmap/issues/12
  • https://github.com/aws/containers-roadmap/issues/104

这篇关于带有两个负载均衡器的ECS服务用于同一端口:内部和面向互联网的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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