Skip to content

Instantly share code, notes, and snippets.

@ripper2hl
Forked from schneefisch/restart_pods.md
Created December 28, 2022 07:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ripper2hl/3adaf3ce82b29b1270cf57c6850237ac to your computer and use it in GitHub Desktop.
Save ripper2hl/3adaf3ce82b29b1270cf57c6850237ac 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