我正在使用 Terraform 创建一个 ECS 集群、一个任务定义和一个服务。
对于任务定义,这段代码如下所示:
resource "aws_ecs_task_definition" "postgres" {
container_definitions = ...
family = "Postgres"
requires_compatibilities = ["EC2"]
network_mode = "bridge"
volume {
name = "PreCreatedEBSVolume"
docker_volume_configuration {
scope = "task"
autoprovision = false
driver = "rexray/ebs"
}
}
}
我特意设置了autoprovision
至 false
确保新卷是 不是 创建。但是,当服务运行时,会使用 16GiB(我假设这是默认大小)创建一个新卷,并使用它而不是使用“PreCreatedEBSVolume”。我查了
docker volume ls
在实例中,果然,我看到列出的 EBS 卷。如果我运行一个安装了这个卷的新实例,它会按预期安装。有没有办法让 REX-Ray 使用现有的块存储?
最佳答案
我发现了这个问题。
问题是“范围”属性。文档中有以下内容:
The scope for the Docker volume that determines its lifecycle. Docker volumes that are scoped to a task are automatically provisioned when the task starts and destroyed when the task stops. Docker volumes that are scoped as shared persist after the task stops.
所以,我只需要将它从“任务”更改为“共享”,以使其使用现有的 EBS 卷。
关于amazon-web-services - 在 ECS 上使用带有 Docker REX-Ray 插件的现有 EBS 卷,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62858443/