无法使AWS ECS服务通过服务发现进行通信 [英] Not able to make AWS ECS services communicate over service discovery
问题描述
我正在尝试使2个服务通过AWS ECS服务中的服务发现终端节点进行通信.
I am trying to make 2 services communicate over service discovery endpoint in AWS ECS service.
示例:
Example:
Service1 :运行任务定义以运行nginx和phpfpm
Service1: runs the Task Definition to run nginx and phpfpm
Service2 :运行任务定义以运行Redis
Service2: runs the Task Definition to run redis
现在,我需要使service1容器与service2进行通信 容器
Now, I need to make service1 container communicate to service2 container
根据Internet上的文档和资源.这是我所做的,无法满足需要.
As per the documentations and resource found on internet. This is what I have done and not able to achieve the need.
- 我们需要打开服务发现(完成)
- 设置适当的服务名称和名称空间,以用作服务发现端点(完成)
- 创建任务定义并使用上述属性集(完成)创建服务
- 现在,AWS将在Route53上生成SRV记录(确定)
- We need to turn on service discovery (Done)
- Set proper service name and namespace which will work as service discovery endpoint (Done)
- Create task definition and create service with above property set (done)
- Now AWS will generate a SRV records on the Route53 (OK)
现在,在使用通常采用以下格式的服务发现端点时
service_discovery_service_name.service_discovery_namespace.
Now, when using the service discovery endpoint which is generally in format
service_discovery_service_name.service_discovery_namespace.
错误日志显示,无法解析名称.
The error logs shows , It's not able to resolve the name.
推荐答案
根据我们的对话,以下是正在发生的事情的摘要.
As per our conversation, here is bit summary of what's happening.
- 如果 Service1 (在您的情况下为
nginx
)需要与具有AWS ServiceDiscovery选项并使用Service2 ( redis
)进行交互://anders.com/cms/263/Tutorial/SIP/DNS/SRV/djbdns"rel =" noreferrer> SRV 记录,然后 Service1 需要知道它需要执行DNSSRV
查找,而不是DNSA
(地址)查找. -
您在这里有多个选择.首先,如果要继续使用
SRV
记录,请使用客户端 nginx 需要使用service
和resolve
选项(高级版本中可用.在答案的底部检查我已经测试过的示例nginx配置.
- If Service1(
nginx
in your case) needs to interact with Service2(redis
) with AWS ServiceDiscovery option and use of SRV records then Service1 needs to be aware that it needs to perform DNSSRV
lookup instead of DNSA
(Address) lookup. You have multiple options here. First, if you want to continue to use the
SRV
records use then your client nginx needs to proxy redis upstream server with options ofservice
andresolve
which are available only in premium version of nginx. Check my sample nginx configuration I have tested at the bottom of the answer which works.
还请确保您创建的前缀为_http._tcp
的AWS Service发现名称,否则,我在没有前缀的nginx配置中遇到了配置SRV resolve/service
选项的问题.
Also make sure, you create the AWS Service discovery name with prefix _http._tcp
otherwise, I had issues configuration SRV resolve/service
option in nginx configuration without the prefix.
- 其他选项,如果您不想依赖
SRV
记录,但要进行标准的A
记录查找,则必须对容器使用awsvpc
模式,然后选择A
选项.
- Other option, If you do not want to rely on
SRV
records but go to standardA
record lookup then you will have to useawsvpc
mode for containers and selectA
option.
- 使用DNS A选项,则您对
service_discovery_service_name.service_discovery_namespace
的查询将正常工作. - 使用DNS A选项时,存在一些限制.由于ENI的数量限制取决于EC2实例家族,因此您无法在同一EC2实例上为给定服务创建多个任务,所以我只希望使用SRV记录.
- With DNS A option then your query of
service_discovery_service_name.service_discovery_namespace
will work fine. - With DNS A option, there are some constraints. You cannot create multiple tasks for a given service on same EC2 instance due to number of ENIs limit depending EC2 instance family so I would prefer SRV records only.
示例nginx DNS SRV选项配置:
Sample nginx DNS SRV Options configuration:
stream {
resolver 172.31.0.2;
upstream redis {
zone tcp_servers 64k;
server redisservice.local service=_http._tcp resolve;
}
server {
listen 12345;
status_zone tcp_server;
proxy_pass redis;
}
}
一些参考-
https://aws.amazon.com/blogs/aws/amazon-ecs-service-discovery/ https://docs.aws.amazon.com/AmazonECS/latest/developerguide/create-service-discovery.html
这篇关于无法使AWS ECS服务通过服务发现进行通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!