Kubernetes Commands Cheat Sheet

This is part of my Kubernetes cheat sheet.

How to restart a Pod in Kubernetes

I often want to restart pods without actually having to deploy anything. It can be done quite easily with the kubectl command.

To restart a Kubernetes pod, you just need to:

kubectl rollout restart deployment  <DEPLOYMENT_NAME> -n <NAMESPACE>

How to delete evicted Pods from a namespace

This command is handy when you want to remove terminated, failed or evicted pods from a namespace. The reason you might want to do that is to keep things tidy. So as a first option, you can easily run this command. Make sure that you adjust the pods status to your needs:

kubectl --namespace=<NAMESPACE> get pods | grep -E 'NodeShutdown|Terminated|Evicted' | awk '{print $1}' | xargs kubectl --namespace=<NAMESPACE> delete pod -o name