使用ECS Fargate发现服务

问题描述 投票:0回答:1

我在ECS Fargate内有2个服务在运行,我已经用私有的dns命名空间设置了服务发现,因为我的所有服务都在私有子网内。

我已经设置了服务发现与私人DNS命名空间,因为我所有的服务都在一个私人子网内。

enter image description here

当我试图从另一个容器中访问我的配置容器时,我得到了以下错误。

http:/config.qcap-prod:50050config 获取"http:/config.qcap-prod:50050config。": dial tcp: lookup config.qcap-prod on 10.0.0.2:53: no such host (没有这样的主机)

以下是我的Terraform

resource "aws_service_discovery_service" "config" {
  name = "config"

  dns_config {
    namespace_id = aws_service_discovery_private_dns_namespace.qcap_prod_sd.id

    dns_records {
      ttl  = 10
      type = "A"
    }
  }

  health_check_custom_config {
    failure_threshold = 1
  }
}

我是否还需要做另一个步骤来允许我在ECS内使用Fargate从另一个容器打到我的容器?

我的命名空间的terraform代码是。

resource "aws_service_discovery_private_dns_namespace" "qcap_prod_sd" {
  name        = "qcap.prod"
  description = "Qcap prod service discovery"
  vpc         = module.vpc.vpc_id
}
amazon-web-services terraform amazon-ecs aws-fargate service-discovery
1个回答
0
投票

这个问题的解决方法是添加

module "vpc" {
  enable_dns_support = true
  enable_dns_hostnames = true
}

在vpc模块内的模块块中,允许DNS主机名在我的VPC中被解析。

© www.soinside.com 2019 - 2024. All rights reserved.