Skip to content

Instantly share code, notes, and snippets.

@schneefisch
Last active April 19, 2024 08:32
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save schneefisch/41be9eabc369bb13745b05b4e21d0628 to your computer and use it in GitHub Desktop.
Save schneefisch/41be9eabc369bb13745b05b4e21d0628 to your computer and use it in GitHub Desktop.
How to restart all pods in a statefulset or deployment

Various ways to restart pods

Restart deployment

The most gracefull way is to trigger a restart for the deployment. In this case, a pod will only be terminated once the new pod is ready. It will slowly replace all pods one after the other.

kubectl rollout restart deployment <deployment-name>

Restart pods in a statefulset

This is similar to restarting a deployment but for stateful sets:

kubectl rollout restart statefulset <statefulset-name>

Hard / Forcefully restart a pod

Since pods are defined in a deployment, if one pod crashes or is killed, the deployment will automatically reschedule a new pod.

The effect is, that the pod will be sent to termination first and only then the new instance will be scheduled. This will lead to a gap where this instance is missing.

kubectl delete pod <pod-name>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment