gpt4 book ai didi

amazon-web-services - 在 ECS fargate 任务中解析服务主机名

转载 作者:行者123 更新时间:2023-12-04 07:14:17 25 4
gpt4 key购买 nike

我正在尝试使用 terraform 自动化我的 ECS fargate 集群制作。
我有一个带有容器化微服务的 SpringBoot 项目,我将这些图像放在后端 ECS 服务的单个任务定义中。
ECS 集群最初正在运行,但 Kafka 因错误而停止:

ERROR Unable to resolve address: zookeeper:2181
(org.apache.zookeeper.client.StaticHostProvider)
我已经为zookeeper(bitnami)提供了图像并使用了 KAFKA_CFG_ZOOKEEPER_CONNECT 环境变量。
编辑:我的任务定义:
resource "aws_ecs_task_definition" "this" {
family = local.application_name
requires_compatibilities = [local.launch_type]
execution_role_arn = data.aws_iam_role.ecs_task_execution_role.arn
network_mode = "awsvpc"
cpu = "4096"
memory = "30720"
container_definitions = jsonencode([
{
name = "zookeeper"
image = "docker.io/bitnami/zookeeper:latest"
essential = true
cpu = 512
memory = 1024
portMappings = [
{
containerPort = 2181
hostPort = 2181
}
]
"environment" : [
{ "name" : "ALLOW_ANONYMOUS_LOGIN", "value" : "yes" },
{ "name" : "ZOO_LISTEN_ALLIPS_ENABLED", "value" : "yes" }
]
},
{
name = "kafka-server"
image = "docker.io/bitnami/kafka:latest"
essential = true
cpu = 512
memory = 1024
portMappings = [
{
containerPort = 9092
hostPort = 9092
}
]
depends_on = [
"zookeeper"
]
"environment" : [
{ "name" : "KAFKA_CFG_ZOOKEEPER_CONNECT", "value" : "zookeeper:2181" },
{ "name" : "ALLOW_ANONYMOUS_LOGIN", "value" : "yes" },
{ "name" : "ALLOW_PLAINTEXT_LISTENER", "value" : "yes" }
],
},
{
name = "email-service"
image = "my-email-image"
essential = true
cpu = 512
memory = 1024
portMappings = [
{
containerPort = 8090
hostPort = 8090
}
]
"environment" : [
{ "name" : "EMAIL_URL", "value" : "email-service" },
{ "name" : "EMAIL_PORT", "value" : "8090" },
{ "name" : "KAFKA_URL", "value" : "kafka-server" },
{ "name" : "KAFKA_PORT", "value" : "9092" },
]
}
])
}

最佳答案

AS写在documentation :

Additionally, containers that belong to the same task can communicate over the localhost interface.


所以我的建议是使用 localhost 而不是服务名称。例如,您希望为 Kafka 以及其他所有服务(例如电子邮件服务)执行此操作。
{ "name" : "KAFKA_CFG_ZOOKEEPER_CONNECT", "value" : "localhost:2181" },

关于amazon-web-services - 在 ECS fargate 任务中解析服务主机名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68880004/

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