Zha*_* Yi 1 amazon-web-services amazon-ecs
我正在 ECS (Fargate) 上创建一个任务,其中有 3 个容器,其中两个容器是必需的。而且我发现如果非必要的容器启动失败,整个任务就会失败。是预期的吗?
在任务定义https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_definition_parameters.html中,它说:
If the essential parameter of a container is marked as true, and that container fails or stops for any reason, all other containers that are part of the task are stopped. If the essential parameter of a container is marked as false, then its failure does not affect the rest of the containers in a task. If this parameter is omitted, a container is assumed to be essential.
Run Code Online (Sandbox Code Playgroud)
I have set essential to true in my major container and other containers as false. I wonder why this flag doesn't work in my ECS.
I know that in most cases people create one container per task. My in my case, I have multiple containers in one task. I don't consider an option to move my containers to separate tasks. I am asking my the essential in container doesn't work as expected.
Below is a screenshot of my task definition and you can see that the first container is not essential which means its failure shouldn't cause task failure.
更新:
如果您有两个容器,假设 - 容器 A - 容器 B
你认为A不需要容器B,如果B宕机了你不想重启A,你只需要设置
"essential": false,
Run Code Online (Sandbox Code Playgroud)
在B容器任务定义中。
这对我有用ECS agent 1.36.2
这是 ECS 在单个任务定义的情况下的预期行为,因为所有任务共享相同的任务定义,因此无论您扩大规模还是缩小一个容器,由于某种原因,所有容器都会缩小,如果您缩小一个,所有容器都会扩大向上。
通常,这是在容器中使用旧链接的方式,现在您已经有了服务发现,因此可以更好地使用服务发现并将容器放入单独的任务定义中。
此外,这不是建议的容器架构。
您的整个应用程序堆栈不需要存在于单个任务定义上,并且在大多数情况下也不应该存在。您的应用程序可以通过将相关容器组合到它们自己的任务定义中来跨越多个任务定义,每个任务定义代表一个组件。了解更多信息,
所以问题是何时应该将它们放入单个任务定义中
如果出现以下情况,则应将多个容器放入同一任务定义中:
容器共享共同的生命周期(即它们应该一起启动和终止)。
容器需要在同一底层主机上运行(即,一个容器在本地主机端口上引用另一个容器)。
您希望容器共享资源。
您的容器共享数据卷。
否则,您应该在单独的任务定义中定义容器,以便可以单独扩展、配置和取消配置它们。
| 归档时间: |
|
| 查看次数: |
3058 次 |
| 最近记录: |