ECS Service connect could not resolve host

0

【以下的问题经过翻译处理】 我正在研究在某个项目中使用ECS Service connect。我已经配置了具有Service connect功能的ECS服务,但是当我尝试从同一命名空间中的其他服务连接它时,会出现curl: (6) Could not resolve host: core的错误。

服务配置

"serviceConnectConfiguration": {
    "enabled": true,
    "namespace": "arn:aws:servicediscovery:us-east-1:***:namespace/ns-awd3wsdifs2nsrla",
    "services": [
        {
            "portName": "core",
            "discoveryName": "core",
            "clientAliases": [
                {
                    "port": 80,
                    "dnsName": "core"
                }
            ]
        }
    ]
},
"serviceConnectResources": [
    {
        "discoveryName": "core",
        "discoveryArn": "arn:aws:servicediscovery:us-east-1:***:service/srv-rirfgcxi4bpplqyj"
    }
]

Curl结果

curl -v http://core:80
* Could not resolve host: core
* Closing connection 0
curl: (6) Could not resolve host: core

curl -v http://core.skc:80
* Could not resolve host: core.skc
* Closing connection 0
curl: (6) Could not resolve host: core.skc

Source service配置

"serviceConnectConfiguration": {
    "enabled": true,
    "namespace": "arn:aws:servicediscovery:us-east-1:***:namespace/ns-awd3wsdifs2nsrla",
    "services": [
        {
            "portName": "admin",
            "discoveryName": "admin",
            "clientAliases": [
                {
                    "port": 77,
                    "dnsName": "admin"
                }
            ]
        }
    ]
},
"serviceConnectResources": [
    {
        "discoveryName": "admin",
        "discoveryArn": "arn:aws:servicediscovery:us-east-1:***:service/srv-niqcn3ec7jgsz27i"
    }
]

VPC 中DNS 和 DNS hostnames enabled 选项已经打开.

{
    "VpcId": "vpc-00bdb82e8d17a444a",
    "EnableDnsSupport": {
        "Value": true
    }
}

{
    "VpcId": "vpc-00bdb82e8d17a444a",
    "EnableDnsHostnames": {
        "Value": true
    }
}

还有其他我漏掉的吗?

profile picture
EXPERTE
gefragt vor 5 Monaten43 Aufrufe
1 Antwort
0

【以下的回答经过翻译处理】 实际上,我已经想清楚了。

事件序列:

  1. 部署 service1。
  2. 部署 service2。
  3. 连接到 ECS service1 中的容器,尝试 curl http://service2:80 - 结果返回 could not resolve host
  4. 连接到 ECS service2 中的容器,尝试 curl http://service1:80 - 这个请求可以成功。
  5. --force-new-deployment 重启 service1 并重复第3步 - 此时请求可以成功。

显然,ECS 会在 /etc/hosts 中添加与 ECS 服务连接相关的记录。该文 指出“服务连接配置任务自身的 DNS 名称,而不需要在托管区域中创建 DNS 记录”。

第三步时,service1 的 /etc/hosts 文件内容为:

127.0.0.1 localhost
10.0.20.61 ip-10-0-20-61.eu-west-2.compute.internal
127.255.0.1 service1
2600:f0f0:0:0:0:0:0:1 service1

第四步时,service2 的 /etc/hosts 文件内容为:

127.0.0.1 localhost
10.0.20.167 ip-10-0-20-167.eu-west-2.compute.internal
127.255.0.1 service1
2600:f0f0:0:0:0:0:0:1 service1
127.255.0.2 service2
2600:f0f0:0:0:0:0:0:2 service2

第五步时,service1 的 /etc/hosts 文件内容为:

127.0.0.1 localhost
10.0.20.13 ip-10-0-20-13.eu-west-2.compute.internal
127.255.0.1 service1
2600:f0f0:0:0:0:0:0:1 service1
127.255.0.2 service2
2600:f0f0:0:0:0:0:0:2 service2

看起来像是 当新的endpoints 被添加到 CloudMap namespace时, ECS 没有动态更新 /etc/hosts 文件.

profile picture
EXPERTE
beantwortet vor 5 Monaten

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen