哪种方法更适合发现容器就绪情况?

Which approach is better for discovering container readiness?

这个问题已被讨论过很多次,但我想听听一些使用以下每种方法的最佳实践和真实示例:

  1. 设计能够检查依赖服务健康状况的容器。简单脚本 whait-for-it 对这种开发容器很有用,但不适合更复杂的部署。例如,数据库可以接受连接,但尚未应用迁移。

  2. 使容器能够 post 在 Consul/etcd 中拥有状态。所有依赖服务将轮询包含所需服务状态的特定端点。看起来不错,但似乎多余,不是吗?

  3. 通过外部调度程序管理容器的启动顺序。

在交付过程中 absence/presence 协调器(如 Swarm/Kubernetes/etc)的上下文中,上述哪种方法更可取?

我可以从 kubernetes 的角度看一下这些。

Designing containers which are able to check the health of dependent services. Simple script whait-for-it can be useful for this kind of developing containers, but aren't suitable for more complex deployments. For instance, database could accept connections but migrations aren't applied yet.

这听起来像是您想区分活跃度和就绪度。 Kubernetes 允许 both types of probes 这些,你可以用它来检查健康状况并在服务任何流量之前等待。

Make container able to post own status in Consul/etcd. All dependent services will poll certain endpoint which contains status of needed service. Looks nice but seems redundant, don't it?

我同意。必须单独维护状态不是首选。然而,在绝对必要的情况下,如果你真的想存储资源的状态,可以使用 third party resource.

Manage startup order of containers by external scheduler.

这似乎主要与讨论无关。但是,Pet Sets, soon to be replaced by Stateful Sets in Kubernetes v1.5, give you deterministic order of initialization of pods. For containers on a single pod, there are init-containers 运行 在主容器 运行 之前按顺序排列。