Reading Time: < 1 minute

Kubernetes: Recreating Pods

Sometimes it’s practical to re-create a pod because it needs to re-load configuration or restart. Here are some tricks to deleting and re-creating pods.

Delete All Pods By Label

To get the labels of a pod run this command on the appropriate namespace.

kubectl get pods -o wide

kubectl delete pods -l app=kubernetes-tutorial -n mrjamiebowman

Delete Each Pod Individually

The key thing here is to leave one running and delete the others.

kubectl delete pod/podname -n mrjamiebowman

Scale to 0…3

kubectl scale deployment kubernetes-tutorial -n mrjamiebowman --replicas=0

then scale back up…

kubectl scale deployment kubernetes-tutorial -n mrjamiebowman --replicas=3

Rolling Restart (Production)

A more production-friendly way of doing this would be to configure the Deployment to handle a rolling restart. That is for another tutorial in another day. I just want people to be aware of this.

kubectl rollout restart deployment kubernetes-tutorial