当 replica 大于 1 时,一次启动一个 pod

Start one pod at a time when replica is greater than one

有没有办法确保 pods 在设置副本大于一个时一次缩放一个?

示例:副本设置为 3

  1. Pod 1 - 正在初始化,Pod 2 - 正在等待,Pod 3 - 正在等待
  2. Pod 1 - 运行,Pod 2 - 初始化,Pod 3 - 等待
  3. Pod 1 - 运行,Pod 2 - 运行,Pod 3 - 正在初始化
  4. 连播机 1 - 运行,连播机 2 - 运行,连播机 3 - 运行

您可以使用 StatefulSets 完成此行为。从 Kubernetes docs

开始
  • For a StatefulSet with N replicas, when Pods are being deployed, they are created sequentially, in order from {0..N-1}.
  • When Pods are being deleted, they are terminated in reverse order, from {N-1..0}.
  • Before a scaling operation is applied to a Pod, all of its predecessors must be Running and Ready.
  • Before a Pod is terminated, all of its successors must be completely shutdown.

所以,正如您在此处看到的,新的 pod 在前一个 pod 初始化之前不会启动。

注意: 当使用 OrderedReady pod 管理策略(默认)时,Kubernetes 保证此行为。