gpt4 book ai didi

amazon-web-services - "Network bindings - not configured"使用 AWS Fargate 运行服务时

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

我正在尝试使用 ECS Fargate 设置几个服务,这些服务通过 Terraform 进行配置。它们使用相同的模块,只是镜像、ALB 目标组、环境变量和端口映射不同。

2 out 3 个服务成功启动他们的任务只有一个(不幸的是主服务),不想启动并显示 Network bindings - not configured对于容器。我使用的端口是80。

任务定义具有正确的端口映射。

我试过更改端口(到 8080),使用多个端口映射并多次重新创建服务都没有效果。

当然,由于运行状况检查失败,该任务会被负载均衡器终止。

任何指针可能是错误的?我从 2017 年开始发现了一些与此相关的 Github 问题,但在 EC2 支持的 ECS 实例上,据称已修复。

作为引用,这里是任务定义 JSON:

{
"ipcMode": null,
"executionRoleArn": "ROLE_ARN",
"containerDefinitions": [
{
"dnsSearchDomains": null,
"logConfiguration": {
"logDriver": "awslogs",
"secretOptions": null,
"options": {
"awslogs-group": "/drone",
"awslogs-region": "eu-central-1",
"awslogs-stream-prefix": "drone-server/"
}
},
"entryPoint": null,
"portMappings": [
{
"hostPort": 80,
"protocol": "tcp",
"containerPort": 80
}
],
"command": null,
"linuxParameters": null,
"cpu": 256,
"environment": [...],
"resourceRequirements": null,
"ulimits": null,
"dnsServers": null,
"mountPoints": [],
"workingDirectory": null,
"secrets": [...],
"dockerSecurityOptions": null,
"memory": 512,
"memoryReservation": 512,
"volumesFrom": [],
"stopTimeout": 30,
"image": "drone/drone:1",
"startTimeout": null,
"dependsOn": null,
"disableNetworking": null,
"interactive": null,
"healthCheck": null,
"essential": true,
"links": null,
"hostname": null,
"extraHosts": null,
"pseudoTerminal": null,
"user": null,
"readonlyRootFilesystem": false,
"dockerLabels": null,
"systemControls": null,
"privileged": null,
"name": "drone-server"
}
],
"placementConstraints": [],
"memory": "512",
"taskRoleArn": "ROLE_ARN",
"compatibilities": [
"EC2",
"FARGATE"
],
"taskDefinitionArn": "TASK_DEFINITION_ARN",
"family": "drone-server",
"requiresAttributes": [
{
"targetId": null,
"targetType": null,
"value": null,
"name": "com.amazonaws.ecs.capability.logging-driver.awslogs"
},
{
"targetId": null,
"targetType": null,
"value": null,
"name": "ecs.capability.execution-role-awslogs"
},
{
"targetId": null,
"targetType": null,
"value": null,
"name": "com.amazonaws.ecs.capability.docker-remote-api.1.19"
},
{
"targetId": null,
"targetType": null,
"value": null,
"name": "com.amazonaws.ecs.capability.docker-remote-api.1.21"
},
{
"targetId": null,
"targetType": null,
"value": null,
"name": "com.amazonaws.ecs.capability.task-iam-role"
},
{
"targetId": null,
"targetType": null,
"value": null,
"name": "ecs.capability.container-ordering"
},
{
"targetId": null,
"targetType": null,
"value": null,
"name": "ecs.capability.secrets.ssm.environment-variables"
},
{
"targetId": null,
"targetType": null,
"value": null,
"name": "com.amazonaws.ecs.capability.docker-remote-api.1.18"
},
{
"targetId": null,
"targetType": null,
"value": null,
"name": "ecs.capability.task-eni"
}
],
"pidMode": null,
"requiresCompatibilities": [
"FARGATE"
],
"networkMode": "awsvpc",
"cpu": "256",
"revision": 14,
"status": "ACTIVE",
"proxyConfiguration": null,
"volumes": []
}```

最佳答案

使用 EC2 上的 ECS,您的容器端口(如 80)将映射到主机上的动态端口(如 35467),然后将该端口注册到类型为“instance”的 TargetGroup。 (从技术上讲,如果您发送零作为主机端口映射到容器上的端口 80,就会发生这种情况。AWS 将此视为“在主机上动态分配端口”)

Fargate 的最大区别在于它使用附加到任务的 ENI 进行网络连接,并且每个任务都有自己的私有(private) IP 地址(如果需要,也可以是公开的)。

然后,使用该唯一 IP 地址(与实例唯一端口相反)
将端口 80 的唯一 IP 地址注册到类型为“ip”的 TargetGroup。

所以有两件事可能会出错......首先,在 Fargate 上,您的任务必须具有相同的主机端口和容器端口(例如 80:80),并且您必须确保它以“ip”类型注册到 TargetGroup .

我不是 terraform 用户,因此不确定其中有多少在您的控制范围内,但我怀疑这两件事之一是不正确的,并导致您的 Web 服务/任务无法正确启动。

作为引用,这里是任务定义 JSON:

{
"ipcMode": null,
"executionRoleArn": "ROLE_ARN",
"containerDefinitions": [
{
"dnsSearchDomains": null,
"logConfiguration": {
"logDriver": "awslogs",
"secretOptions": null,
"options": {
"awslogs-group": "/drone",
"awslogs-region": "eu-central-1",
"awslogs-stream-prefix": "drone-server/"
}
},
"entryPoint": null,
"portMappings": [
{
"hostPort": 80,
"protocol": "tcp",
"containerPort": 80
}
],
"command": null,
"linuxParameters": null,
"cpu": 256,
"environment": [...],
"resourceRequirements": null,
"ulimits": null,
"dnsServers": null,
"mountPoints": [],
"workingDirectory": null,
"secrets": [...],
"dockerSecurityOptions": null,
"memory": 512,
"memoryReservation": 512,
"volumesFrom": [],
"stopTimeout": 30,
"image": "drone/drone:1",
"startTimeout": null,
"dependsOn": null,
"disableNetworking": null,
"interactive": null,
"healthCheck": null,
"essential": true,
"links": null,
"hostname": null,
"extraHosts": null,
"pseudoTerminal": null,
"user": null,
"readonlyRootFilesystem": false,
"dockerLabels": null,
"systemControls": null,
"privileged": null,
"name": "drone-server"
}
],
"placementConstraints": [],
"memory": "512",
"taskRoleArn": "ROLE_ARN",
"compatibilities": [
"EC2",
"FARGATE"
],
"taskDefinitionArn": "TASK_DEFINITION_ARN",
"family": "drone-server",
"requiresAttributes": [
{
"targetId": null,
"targetType": null,
"value": null,
"name": "com.amazonaws.ecs.capability.logging-driver.awslogs"
},
{
"targetId": null,
"targetType": null,
"value": null,
"name": "ecs.capability.execution-role-awslogs"
},
{
"targetId": null,
"targetType": null,
"value": null,
"name": "com.amazonaws.ecs.capability.docker-remote-api.1.19"
},
{
"targetId": null,
"targetType": null,
"value": null,
"name": "com.amazonaws.ecs.capability.docker-remote-api.1.21"
},
{
"targetId": null,
"targetType": null,
"value": null,
"name": "com.amazonaws.ecs.capability.task-iam-role"
},
{
"targetId": null,
"targetType": null,
"value": null,
"name": "ecs.capability.container-ordering"
},
{
"targetId": null,
"targetType": null,
"value": null,
"name": "ecs.capability.secrets.ssm.environment-variables"
},
{
"targetId": null,
"targetType": null,
"value": null,
"name": "com.amazonaws.ecs.capability.docker-remote-api.1.18"
},
{
"targetId": null,
"targetType": null,
"value": null,
"name": "ecs.capability.task-eni"
}
],
"pidMode": null,
"requiresCompatibilities": [
"FARGATE"
],
"networkMode": "awsvpc",
"cpu": "256",
"revision": 14,
"status": "ACTIVE",
"proxyConfiguration": null,
"volumes": []
}```

关于amazon-web-services - "Network bindings - not configured"使用 AWS Fargate 运行服务时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57431324/

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