gpt4 book ai didi

docker - ECS Fargate/单个ALB/多个Docker容器

转载 作者:行者123 更新时间:2023-12-02 19:24:02 24 4
gpt4 key购买 nike

有没有人举过一个例子,说明如何使用单个应用程序负载平衡器将主机头请求转发到两个不同的Docker容器来构建ECS集群。

我想为一个单个ESC群集运行一个ALB,该群集同时运行我的 Angular 站点以及a.net Web服务。最终,我的目标是使用terraform编写脚本。

最佳答案

在不了解所有信息的情况下,我认为您正在寻找基于路径的路由,甚至更好的基于主机的路由。

地貌

每个主机/路径都需要一个 aws_lb_listener_rule (负载均衡器侦听器规则)。
每个ECS服务都需要一个 aws_alb_target_group ,并在资源aws_lb_listener_rule中引用正确的目标组。

一般

侦听器规则

Before you start using your Application Load Balancer, you must add one or more listeners. A listener is a process that checks for connection requests, using the protocol and port that you configure. The rules that you define for a listener determine how the load balancer routes request to the targets in one or more target groups. docs



在您的应用程序负载均衡器中使用基于路径的路由

https://docs.aws.amazon.com/en_us/elasticloadbalancing/latest/application/tutorial-load-balancer-routing.html

例子

基于主机的侦听器规则
resource "aws_lb_listener_rule" "host_based_routing" {
listener_arn = aws_lb_listener.front_end.arn
priority = 99

action {
type = "forward"
target_group_arn = aws_lb_target_group.static.arn
}

condition {
field = "host-header"
values = ["my-service.*.terraform.io"]
}
}

条件块定义必须发送请求的主机或模式(以下示例)。

基于路径的侦听器规则
resource "aws_lb_listener_rule" "static" {
listener_arn = aws_lb_listener.front_end.arn
priority = 100

action {
type = "forward"
target_group_arn = aws_lb_target_group.static.arn
}

condition {
field = "path-pattern"
values = ["/static/*"]
}
}

目标组
resource "aws_alb_target_group" "alb_target_group" {
name = "example-target-group"
protocol = "HTTP"
port = var.exposed_port
vpc_id = var.vpc_id
deregistration_delay = 30
health_check {
path = var.service_health_check_path
matcher = "200-399"
}
}

https://www.terraform.io/docs/providers/aws/r/lb_listener_rule.html
https://www.terraform.io/docs/providers/aws/r/lb_target_group.html

关于docker - ECS Fargate/单个ALB/多个Docker容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57677491/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com