我正在寻找一种方法来将两个目标组附加到单个ECS服务,而在另一个我的容器中暴露了两个端口,但我只能将一个端口与我的服务映射到LB。
到目前为止,我能够创建一个新的侦听器和目标组,但是在目标组创建之后,我可以看到一切按预期进行,但目标组显示There are no targets registered to this target group。

下面是我的目标组和侦听器配置
target_group:
resource "aws_lb_target_group" "e_admin" {
name = "${var.env_prefix_name}-admin"
port = 5280
protocol = "HTTP"
vpc_id = "${aws_vpc.VPC.id}"
health_check {
path = "/admin"
healthy_threshold = 2
unhealthy_threshold = 10
port = 5280
timeout = 90
interval = 100
matcher = "401,200"
}
}侦听器:‘
resource "aws_lb_listener" "admin" {
load_balancer_arn = "${aws_lb.admin_lb.arn}"
port = "5280"
protocol = "HTTP"
default_action {
target_group_arn = "${aws_lb_target_group.e_admin.id}"
type = "forward"
}
}我的问题是如何添加ECS集群自动标度组,或者如何将ECS集群中运行的所有实例添加到这个目标组?
发布于 2019-08-01 07:25:03
最近宣布支持一个ECS服务的多个目标组。
目前尚未发布的2.22.0版本的AWS提供程序通过向2.22.0版本的AWS提供程序资源添加更多的load_balancer块来包含对此的支持。来自验收试验的示例
resource "aws_ecs_service" "with_alb" {
name = "example"
cluster = "${aws_ecs_cluster.main.id}"
task_definition = "${aws_ecs_task_definition.with_lb_changes.arn}"
desired_count = 1
iam_role = "${aws_iam_role.ecs_service.name}"
load_balancer {
target_group_arn = "${aws_lb_target_group.test.id}"
container_name = "ghost"
container_port = "2368"
}
load_balancer {
target_group_arn = "${aws_lb_target_group.static.id}"
container_name = "ghost"
container_port = "4501"
}
depends_on = [
"aws_iam_role_policy.ecs_service",
]
}发布于 2019-07-19 16:22:16
与https://docs.aws.amazon.com/AmazonECS/latest/developerguide/service-load-balancing.html相适应,
每个服务有一个负载均衡器或目标组的限制。
如果要将自动标号组附加到目标组,请使用aws_autoscaling_attachment、attachment.html
resource "aws_autoscaling_attachment" "asg_attachment_bar" {
autoscaling_group_name = "${aws_autoscaling_group.your_asg.id}"
alb_target_group_arn = "${aws_alb_target_group.e_admin.arn}"
}发布于 2022-11-10 10:29:19
可以使用load_balancer块为同一个ecs服务添加多个定义多个目标组。
resource "aws_ecs_service" "ecs_service_1" {
name = "service-1"
cluster = aws_ecs_cluster.ecs_cluster_prod.id
task_definition = aws_ecs_task_definition.ecs_task_definition_1.arn
desired_count = 1
launch_type = "FARGATE"
enable_execute_command = true
# Target group 1
load_balancer {
target_group_arn = aws_lb_target_group.lb_tg_1.arn
container_name = "app"
container_port = 8080
}
# Target group 2
load_balancer {
target_group_arn = aws_lb_target_group.lb_tg_2.arn
container_name = "app"
container_port = 8080
}
network_configuration {
subnets = [aws_subnet.subnet_a.id, aws_subnet.subnet_b.id]
security_groups = [aws_security_group.sg_internal.id]
assign_public_ip = true
}
tags = {
Name = "service-1"
ManagedBy = "terraform"
Environment = "prod"
}
}如果有外部负载均衡器和内部负载均衡器,则可以将相同的容器和港口映射到两个目标组。
https://stackoverflow.com/questions/57115182
复制相似问题