无法让 AWS ECS 服务通过服务发现进行通信 [英] Not able to make AWS ECS services communicate over service discovery

查看:25
本文介绍了无法让 AWS ECS 服务通过服务发现进行通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让 2 个服务通过 AWS ECS 服务中的服务发现端点进行通信.

示例:

Service1:运行任务定义来运行nginx和phpfpm

Service2:运行任务定义来运行redis

<块引用>

现在,我需要让 service1 容器与 service2 通信容器

根据互联网上的文档和资源.这是我所做的,无法实现需求.

  1. 我们需要开启服务发现(完成)
  2. 设置适当的服务名称和命名空间,作为服务发现端点(完成)
  3. 使用上述属性集创建任务定义并创建服务(完成)
  4. 现在 AWS 将在 Route53 上生成 SRV 记录 (OK)

现在,当使用通常采用格式的服务发现端点时service_discovery_service_name.service_discovery_namespace.

错误日志显示,无法解析名称.

解决方案

根据我们的对话,这里是正在发生的事情的一些摘要.

  • 如果 Service1(在您的情况下为 nginx)需要通过 AWS ServiceDiscovery 与 Service2(redis)交互选项和使用

    • 其他选项,如果您不想依赖 SRV 记录而是转到标准 A 记录查找,则必须使用 awsvpc 容器模式并选择 A 选项.

    • 使用 DNS A 选项,您对 service_discovery_service_name.service_discovery_namespace 的查询将正常工作.
    • 对于 DNS A 选项,有一些限制.由于 ENI 数量限制取决于 EC2 实例系列,因此您无法为同一 EC2 实例上的给定服务创建多个任务,因此我更喜欢仅使用 SRV 记录.

    示例 nginx DNS SRV 选项配置:

    stream {解析器 172.31.0.2;上游 redis {区域 tcp_servers 64k;服务器 redisservice.local service=_http._tcp 解析;}服务器 {听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

    I am trying to make 2 services communicate over service discovery endpoint in AWS ECS service.

    Example:

    Service1: runs the Task Definition to run nginx and phpfpm

    Service2: runs the Task Definition to run redis

    Now, I need to make service1 container communicate to service2 container

    As per the documentations and resource found on internet. This is what I have done and not able to achieve the need.

    1. We need to turn on service discovery (Done)
    2. Set proper service name and namespace which will work as service discovery endpoint (Done)
    3. Create task definition and create service with above property set (done)
    4. Now AWS will generate a SRV records on the Route53 (OK)

    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.

    • 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 DNS SRV lookup instead of DNS A(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 of service and resolve 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.

    • 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.

    • Other option, If you do not want to rely on SRV records but go to standard A record lookup then you will have to use awsvpc mode for containers and select A option.

    • 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.

    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;
        }
    }
    

    Some references -

    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屋!

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