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. How can I make sure that the gracefully deleted pod is completely gone before the new pod starts up?
Things I've tried: 1. Rolling Update with maxSurge: 0 and 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.
Same as 1, except using percents instead of integers
Using Recreate instead of Rolling Update
strategy:
type: Recreate
Result: same as 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.?
When gracefully deleting the pod, another instance immediately starts up
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
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.