ECS - 目标类型 ip 与任务定义中指定的桥接网络模式不兼容

mon*_*mon 3 nlb amazon-web-services amazon-ecs terraform-provider-aws

问题

尝试使用目标组使用 IP 作为目标类型的现有 NLB 创建 ECS 服务时,获取目标类型ip,与桥接网络模式不兼容错误。

该错误来自 Terraform,因为它使用它来创建所有 AWS 资源。

错误:InvalidParameterException:提供的目标组 arn:aws:elasticloadbalancing:$REGION:$ACCOUNT:targetgroup ... 具有目标类型 ip,与任务定义中指定的桥接网络模式不兼容。

如果 Terraform(或其消息)正确的话, Terraform Github问题 #11719的TF_DEBUG输出似乎表明这是限制。

2020-01-22T20:04:46.819Z [DEBUG] plugin.terraform-provider-aws_v2.45.0_x4: 2020/01/22 20:04:46 [DEBUG] [aws-sdk-go] {"__type":"InvalidParameterException","message":"The provided target group arn:aws:elasticloadbalancing:us-east-1:xxx:targetgroup/llprd20200122052638603300000006/a0a2d775807f6620 has target type ip, which is incompatible with the bridge network mode specified in the task definition."}
Run Code Online (Sandbox Code Playgroud)

问题

请告知这是否是 AWS 的限制。据我到目前为止查看的AWS文档,没有任何信息表明IP目标类型不能用于桥接网络模式。不过,想百分百确定。

  • ECS服务-创建网络负载均衡器-配置路由
    1. 对于目标类型,选择是否使用实例 ID 或 IP 地址注册目标

      重要
      如果您的服务的任务定义使用 awsvpc 网络模式(Fargate 启动类型需要该模式),您必须选择 ip 作为目标类型,而不是实例。这是因为使用 awsvpc 网络模式的任务与弹性网络接口关联,而不是与 Amazon EC2 实例关联。

      如果实例具有以下实例类型,则无法通过实例 ID 注册实例:C1、CC1、CC2、CG1、CG2、CR1、G1、G2、HI1、HS1、M1、M2、M3 和 T1。您可以通过 IP 地址注册这些类型的实例。

地形

resource "aws_lb_target_group" "this" {
  count = length(var.listeners)
  name_prefix           = "${substr("${var.name}", 0, 6)}"
  vpc_id                = "${var.vpc_id}"
  target_type           = "ip"
  port                  = 8080
  protocol              = "tcp"
  ...
}
Run Code Online (Sandbox Code Playgroud)

我没有在aws_ecs_task_definition资源配置中指定network_mode,因此使用默认的“bridge”。

TF_DEBUG

...
2020-03-03T18:54:10.301+1100 [DEBUG] plugin.terraform-provider-aws_v2.50.0_x4: 2020/03/03 18:54:10 [DEBUG] [aws-sdk-go] {"__type":"InvalidParameterException","message":"The provided target group arn:aws:elasticloadbalancing:us-east-2:ACCOUNT:targetgroup/****/4689fc19ff99ca57 has target type ip, which is incompatible with the bridge network mode specified in the task definition."}
2020-03-03T18:54:10.301+1100 [DEBUG] plugin.terraform-provider-aws_v2.50.0_x4: 2020/03/03 18:54:10 [DEBUG] [aws-sdk-go] DEBUG: Validate Response ecs/CreateService failed, attempt 0/25, error InvalidParameterException: The provided target group arn:aws:elasticloadbalancing:us-east-2:ACCOUNT:targetgroup/****/4689fc19ff99ca57 has target type ip, which is incompatible with the bridge network mode specified in the task definition.
...
Run Code Online (Sandbox Code Playgroud)

环境

  • ECS 类型是 EC2,而不是 Fargate
  • 使用在 Ubuntu“18.04.4 LTS(Bionic Beaver)”上运行的 Terraform v0.12.20

jac*_*ops 8

如AWS 服务发现指南中所述,您无法bridge使用 IP 引用具有网络模式的 ECS 容器。事实上,您只能为此类服务指定 SRV DNS 记录。

这里的选项是将任务定义网络模式更改为awsvpc或将 target_type 更改为instance

就我个人而言,我只经历过awsvpc网络模式。