amazon-web-services - AWS - 在 Terraform 中运行带有 ALB 和超过 5 个端口的 ECS EC2 集群运行容器
问题描述
我正在运行一个包含大约 20 个容器的 ECS 集群。我有一个在 1 个容器上运行的大型单体应用程序,需要监听 10 个端口。
然而,AWS 要求一个 ECS 服务中最多有 5 个负载均衡器目标组链接。
任何想法如何克服这个(如果可能的话)?这是我尝试过的:
- 定义 10 多个目标群体,每个群体有 1 个听众。不起作用,因为 AWS 在 aws_ecs_service 中最多需要 5 个负载均衡器定义 - 供参考 - 此处:https ://docs.aws.amazon.com/AmazonECS/latest/developerguide/service-load-balancing.html如所述在“服务负载平衡注意事项”下的第二个项目符号中
- 定义 10 多个具有 1 个目标组的侦听器 - 但是所有侦听器都转发到容器上的单个端口...
- 尝试在 aws_ecs_service 的 load_balancer 定义中未指定端口,但 AWS 抱怨缺少参数
- 尝试未在 aws_lb_target_group 中指定端口,但 AWS 抱怨目标类型为“ip”,因此需要端口...
这是我当前的代码:
resource "aws_ecs_service" "service_app" {
name = "my_service_name"
cluster = var.ECS_CLUSTER_ID
task_definition = aws_ecs_task_definition.task_my_app.arn
desired_count = 1
force_new_deployment = true
...
load_balancer { # Note: I've stripped the for_each to simplify reading
target_group_arn = var.tga
container_name = var.n
container_port = var.p
}
}
resource "aws_lb_target_group" "tg_mytg" {
name = "Name"
protocol = "HTTP"
port = 3000
target_type = "ip"
vpc_id = aws_vpc.my_vpc.id
}
resource "aws_lb_listener" "ls_3303" {
load_balancer_arn = aws_lb.my_lb.id
port = "3303"
protocol = "HTTP"
default_action {
type = "forward"
target_group_arn = aws_lb_target_group.tg_mytg.arn
}
}
...
解决方案
推荐阅读
- php - 正确计算 PHP 生成页面所需的时间
- sql - 将一列转换为列标题
- android - 是否可以从另一个应用程序访问真实数据库?
- javascript - 在 Node 中转换 TypeScript 的最快方法
- node.js - 快速回调不在会话中存储值
- mysql - SQL 查询需要很长时间才能运行
- c# - 使用 XDocument 从带有重复键的 XML 中读取
- java - 使用 Vaadin Designer 时 Vaadin 8 绑定到 Pojo
- oracle - ORA-06550:第 5 行,第 16 列:PLS-00103:在预期以下情况之一时遇到符号“SELECT”:
- c - 如何从结构数组中删除结构并使用 fwrite() 正确覆盖文件