简体   繁体   English

在AWS ECS中的任务定义之间链接容器?

[英]Linking containers between task definitions in AWS ECS?

I'm trying to setup a basic web application, which has an associated database, in AWS ECS. 我正在尝试在AWS ECS中设置一个具有关联数据库的基本Web应用程序。 Locally I have these setup in different containers, and on ECS, I'd like to have separate task definitions so that I may scale the two separately. 在本地我将这些设置放在不同的容器中,在ECS上,我希望有单独的任务定义,以便我可以单独扩展它们。

  1. I registered my first task definition as david_mongodb successfully in ECS. 我在ECS中成功地将我的第一个任务定义注册为david_mongodb It has a container named david_mongodb in it. 它有一个名为david_mongodb的容器。
  2. Then I attempted to register my second task definition as david_web , which has a container named david_web that links the database via david_mongodb:db . 然后我尝试将我的第二个任务定义注册为david_web ,它有一个名为david_web的容器,它通过david_mongodb:db链接数据库。
  3. When I click 'Create', it returns an error: 单击“创建”时,会返回错误:

     Unable to create Task Definition Linked container 'david_mongodb:db' doesn't exist. 

It seems like task definitions can't see container names in other task definitions? 似乎任务定义无法在其他任务定义中看到容器名称? I'm thinking putting both david_web and david_mongodb containers in the same task definition would work, but I don't want to do that: it would prevent me from scaling either web app or database separately. 我想将david_webdavid_mongodb容器放在同一个任务定义中会起作用,但我不想这样做:它会阻止我单独扩展Web应用程序或数据库。 This overview seems to confirm that my architecture is recommended... 这个概述似乎证实了我的架构是推荐的......

So how do I link containers that live in different task definitions? 那么如何链接生活在不同任务定义中的容器? Or is there another clever way of handling this? 还是有另一种聪明的方法来处理这个问题?

Links in an ECS task definition are analogous to Docker links and only work when the containers are part of the same task definition (containers that are part of a single task definition are placed together on the same host). ECS任务定义中的链接类似于Docker链接 ,仅当容器属于同一任务定义时才起作用(属于单个任务定义的容器一起放在同一主机上)。 In order to communicate between containers in different task definitions, you'll need a mechanism for discovering where the containers are located (what host) as well as the port for communication. 为了在不同任务定义中的容器之间进行通信,您需要一种机制来发现容器所在的位置(主机)以及通信端口。

ECS has integration with Elastic Load Balancing (Application Load Balancers, Network Load Balancers, and Classic Load Balancers) through the service feature, where tasks will be automatically registered in the ELB and deregistered in the ELB appropriately. ECS通过服务功能与Elastic Load Balancing(应用程序负载均衡器,网络负载均衡器和经典负载均衡器)集成,其中任务将自动在ELB中注册并在ELB中适当地注销。

ECS also has integration with Route 53 Auto Naming for DNS-based service discovery using A and SRV records. ECS还使用ASRV记录与Route 53自动命名集成,以进行基于DNS的服务发现。 Your service's tasks can be automatically entered into and removed from DNS records. 您的服务任务可以自动输入和删除DNS记录。

Service Discovery for Amazon ECS Using DNS describes a different approach where a Lambda function listens to the ECS event stream through CloudWatch Events and updates Route 53 DNS records. Amazon ECS的服务发现使用DNS描述了一种不同的方法,其中Lambda函数通过CloudWatch Events侦听ECS事件流并更新Route 53 DNS记录。 This method has been superceded by the Route 53 Auto Naming feature described above. 此方法已被上述Route 53自动命名功能取代。

If you want to avoid load balancers and DNS, another pattern might be an ambassador container (there's a sample called the ecs-task-kite that uses the ECS API) or you might be interested in an overlay network (Weave has a fairly detailed getting started guide for their solution). 如果你想避免负载均衡器和DNS,另一种模式可能是大使容器 (有一个名为ecs-task-kite的样本使用ECS API),或者你可能对覆盖网络感兴趣(Weave有一个相当详细的获取为他们的解决方案开始指导 )。

Nathan Peck is keeping track of a number of different subjects related to ECS, including service discovery, here . 弥敦道佩克是保持了许多有关ECS不同的主题,包括服务发现的轨道, 在这里

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

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