简体   繁体   English

在 Kubernetes 中,如何等待一个 pod 完成删除后再开始新的

[英]In Kubernetes, how to wait for a pod to finish deleting before starting new one

I have a deployment where I need just one instance to be up at a time.我有一个部署,我一次只需要一个实例即可。 When gracefully shutting down the pod, another starts up immediately -- without waiting for the pod to finish exiting.当优雅地关闭 pod 时,另一个会立即启动——无需等待 pod 完成退出。 How can I make sure that the gracefully deleted pod is completely gone before the new pod starts up?如何确保在新 pod 启动之前正常删除的 pod 完全消失?

Things I've tried: 1. Rolling Update with maxSurge: 0 and maxUnavailable: 1我尝试过的事情:1. 使用 maxSurge: 0 和 maxUnavailable: 1 滚动更新

  strategy:
    rollingUpdate:
      maxSurge: 0
      maxUnavailable: 1
    type: RollingUpdate

Result: When gracefully deleting the pod, another instance immediately starts up, so there are two pods running at the same time, seemingly ignoring the maxSurge value.结果:优雅删除 pod 时,另一个实例立即启动,所以有两个 pod 同时运行,貌似忽略了 maxSurge 值。

  1. Same as 1, except using percents instead of integers与 1 相同,但使用百分比而不是整数

  2. Using Recreate instead of Rolling Update使用重新创建而不是滚动更新

strategy:
    type: Recreate

Result: same as 1结果:同1

Is there a way to get the desired behavior directly in Kubernetes, or do you have to do something like add an init container with a delay, etc.?有没有办法直接在 Kubernetes 中获得所需的行为,或者你必须做一些事情,比如添加一个延迟的初始化容器等?

Use StatefulSets使用有状态集

StatefulSets are valuable for applications that require one or more of the following.

 - Stable, unique network identifiers. 
 - Stable, persistent storage.
 - Ordered, graceful deployment and scaling. 
 - Ordered, automated rolling updates.

When gracefully deleting the pod, another instance immediately starts up当优雅地删除 pod 时,另一个实例会立即启动

Recreate deployments wait for the termination of an old version only during a deployment upgrade.重新创建部署仅在部署升级期间等待旧版本的终止。 Except deployment upgrade it cannot ensure consistency.除了部署升级,它不能保证一致性。

Ref: https://github.com/kubernetes/kubernetes/issues/27362#issuecomment-524664492参考: https://github.com/kubernetes/kubernetes/issues/27362#issuecomment-524664492

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM