gpt4 book ai didi

amazon-web-services - Aws ecs fargate 可用性区如何工作?

转载 作者:行者123 更新时间:2023-12-03 08:29:45 27 4
gpt4 key购买 nike

关于 terraform 代码的主要两个问题。

  1. Alb for Ecs fargate 用于路由到另一个可用区?或路由到容器
  2. 如果我根据可用区编号(us-east-2a、2b、2c,因此编号为 3,创建 3 个子网)创建子网并将其映射到带有 alb 的 ecs 集群,可用区是否适用?

我正在尝试构建如下图所示的基础设施 enter image description here

resource "aws_vpc" "cluster_vpc" {
tags = {
Name = "ecs-vpc"
}
cidr_block = "10.30.0.0/16"
}

data "aws_availability_zones" "available" {

}

resource "aws_subnet" "cluster" {
vpc_id = aws_vpc.cluster_vpc.id
count = length(data.aws_availability_zones.available.names)
cidr_block = "10.30.${10 + count.index}.0/24"
availability_zone = data.aws_availability_zones.available.names[count.index]
tags = {
Name = "ecs-subnet"
}
}


resource "aws_internet_gateway" "cluster_igw" {
vpc_id = aws_vpc.cluster_vpc.id

tags = {
Name = "ecs-igw"
}
}

resource "aws_route_table" "public_route" {
vpc_id = aws_vpc.cluster_vpc.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.cluster_igw.id
}

tags = {
Name = "ecs-route-table"
}
}

resource "aws_route_table_association" "to-public" {
count = length(aws_subnet.cluster)
subnet_id = aws_subnet.cluster[count.index].id
route_table_id = aws_route_table.public_route.id
}
resource "aws_ecs_cluster" "staging" {
name = "service-ecs-cluster"
}

resource "aws_ecs_service" "staging" {
name = "staging"
cluster = aws_ecs_cluster.staging.id
task_definition = aws_ecs_task_definition.service.arn
desired_count = 1
launch_type = "FARGATE"

network_configuration {
security_groups = [aws_security_group.ecs_tasks.id]
subnets = aws_subnet.cluster[*].id
assign_public_ip = true
}

load_balancer {
target_group_arn = aws_lb_target_group.staging.arn
container_name = var.app_name
container_port = var.container_port
}

resource "aws_lb" "staging" {
name = "alb"
subnets = aws_subnet.cluster[*].id
load_balancer_type = "application"
security_groups = [aws_security_group.lb.id]

access_logs {
bucket = aws_s3_bucket.log_storage.id
prefix = "frontend-alb"
enabled = true
}

tags = {
Environment = "staging"
Application = var.app_name
}
}

... omit like lb_target, or specific components

最佳答案

Alb for Ecs fargate is for routing to another avaliablity zones? or routing to containers

不是真的。它是为您的 ECS 服务提供单个固定端点 (url)。 ALB 将自动在您的 ECS 服务之间分配来自 Internet 的传入连接。它们可以位于一个或多个可用区。在您的情况下,由于您使用的是desired_count = 1,因此只有1个可用区。这意味着您在单个可用区中将只有 1 个 ECS 服务。

If I create a subnet based on the availability zone number (us-east-2a, 2b, 2c, so number is 3 and create 3 subnets) and map it to an ecs cluster with alb, does the availability zone apply?

是的,因为您的 ALB 通过 aws_subnet.cluster[*].id 为与 ECS 服务相同的子网启用。但正如第一个问题中所解释的,您在一个可用区中只有 1 个服务。

my intent is to build infra which has three availability zone and also deploy aws fargate on three availablity zone.

如前所述,您的 desired_count = 1 因此您将不会拥有跨 3 个可用区的 ECS 服务。

此外,您仅创建公共(public)子网,而您的示意图显示 ECS 服务应位于私有(private)子网中。

关于amazon-web-services - Aws ecs fargate 可用性区如何工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65506279/

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