我有一个问题,我想为我的 ECS 设置任务,但出现以下错误。
错误:创建 ECS 任务定义 (project-datadog):ClientException:Fargate 兼容任务定义不支持 sourcePath
我的 TF 文件:
resource "aws_ecs_task_definition" "datadog" {
family = "project-datadog-ecs"
requires_compatibilities = ["FARGATE"]
network_mode = "awsvpc"
cpu = "2048"
memory = "8192"
execution_role_arn = aws_iam_role.ecs_tasks_execution_role.arn
container_definitions = file("${path.module}/datadog-agent-ecs-logs.json")
volume {
host_path = "/var/run/docker.sock"
name = "docker_sock"
}
volume {
host_path = "/proc/"
name = "proc"
}
volume {
host_path = "/sys/fs/cgroup/"
name = "cgroup"
}
volume {
host_path = "/opt/datadog-agent/run"
name = "pointdir"
}
volume {
host_path = "/var/lib/docker/containers/"
name = "containers_root"
}
tags = local.mandatory_tags
}
resource "aws_ecs_service" "datadog" {
name = "project-datadog"
cluster = module.ecs_cluster.cluster_id
task_definition = aws_ecs_task_definition.datadog.arn
desired_count = 1
tags = local.mandatory_tags
}
JSON 文件(datadog-agent-ecs-logs.json):
[
{
"name": "datadog-agent",
"image": "public.ecr.aws/datadog/agent:latest",
"cpu": 100,
"memory": 512,
"essential": true,
"healthCheck": {
"retries": 3,
"command": ["CMD-SHELL","agent health"],
"timeout": 5,
"interval": 30,
"startPeriod": 15
},
"mountPoints": [
{
"containerPath": "/var/run/docker.sock",
"sourceVolume": "docker_sock",
"readOnly": null
},
{
"containerPath": "/host/sys/fs/cgroup",
"sourceVolume": "cgroup",
"readOnly": null
},
{
"containerPath": "/host/proc",
"sourceVolume": "proc",
"readOnly": null
},
{
"containerPath": "/opt/datadog-agent/run",
"sourceVolume": "pointdir",
"readOnly": false
},
{
"containerPath": "/var/lib/docker/containers",
"sourceVolume": "containers_root",
"readOnly": true
}
],
"environment": [
{
"name": "DD_API_KEY",
"value": "API"
},
{
"name": "DD_SITE",
"value": "SITE"
},
{
"name": "DD_LOGS_ENABLED",
"value": "true"
},
{
"name": "DD_LOGS_CONFIG_CONTAINER_COLLECT_ALL",
"value": "true"
}
]
}
]
当我删除requires_compatibility = [“FARGATE”]时,我遇到了这个问题
任务定义不支持launch_type FARGATE。
有人已经遇到这个问题了吗?
您正在尝试将卷映射到映射到主机服务器上的路径的 Fargate 容器中。当您使用 Fargate 进行部署时,主机服务器完全不可用,因此您无法将指定
host_path
值的卷映射到 Fargate 容器。