kubectl rollout restart

How to restart a deployment in Kubernetes

Kubernetes has no "restart pod" command: it replaces pods. The right way to restart an application is rollout restart, which creates new pods gradually, following the Deployment’s strategy, without taking everything down at once.

1. Restart

kubectl rollout restart deployment/<name> -n <namespace>
kubectl rollout restart statefulset/<name> -n <namespace>
kubectl rollout restart daemonset/<name> -n <namespace>

2. Follow it

status waits until all new pods are ready, or shows where it got stuck:

kubectl rollout status deployment/<name> -n <namespace>
kubectl get pods -n <namespace> -w

What rollout restart does

It writes the kubectl.kubernetes.io/restartedAt annotation to the pod template. The template changes, the Deployment creates a new ReplicaSet and replaces the pods respecting maxSurge, maxUnavailable and the readiness probes. If the new pods do not become ready, the old ones keep serving.

When a restart helps

  • After changing a ConfigMap or Secret used as environment variables: the pod only reads them at startup.
  • To pull a new image with the same tag, when imagePullPolicy is Always.
  • To unstick an app that lost a connection and does not recover on its own. If you need this often, a liveness probe is missing.

The other ways, and why to avoid them

  • kubectl delete pod <pod>: the ReplicaSet creates another one right away. Fine for a single pod, but deleting all of them at once takes the service down.
  • kubectl scale --replicas=0 and back: takes everything down until the new pods come up. Only when the app cannot run two versions side by side.

Roll back if it goes wrong

kubectl rollout undo deployment/<name> -n <namespace>
kubectl rollout history deployment/<name> -n <namespace>

Without a terminal, in Kubepier

On Kubepier’s Pro plan, the Restart button does the same as kubectl rollout restart for Deployments, StatefulSets and DaemonSets, and the pod list shows the new ones coming up, from any cluster, in the browser or on your phone.

Start for free