How to restart all deployments in namespace - Kubectl | Devops Junction

Restart Namespace all Deployments after k8s v1.15

You can simply use the kubectl rollout restart  command that takes care of restarting all the deployments in a namespace

If you specify only the namespace and not a specific deployment, all the deployments in the namespace would be restarted

kubectl rollout restart deployment -n <namespace>

Restart all deployments in Namespace - before k8s v1.15

Instead of manually selecting each deployment in a namespace. you can use this single command to restart all the deployments under the namespace

kubectl get deployments -n <NameSpace Name> -o custom-columns=NAME:.metadata.name|grep -iv NAME|while read LINE; do kubectl rollout restart deployment $LINE -n <NameSpace Name> ; done;

You just have to replace the Namespace value after -n in the command

it would traverse through the list of deployments in the namespace and restart them for you.

If you want to restart all the pods in the namespace. You can do the same approach as restarting the deployment is the right way to restart the pods

This is how it looks like during the execution

restart deployment namespace

Hope this helps

Thanks
Sarav AK

Follow me on Linkedin My Profile
Follow DevopsJunction onFacebook orTwitter
For more practical videos and tutorials. Subscribe to our channel

Buy Me a Coffee at ko-fi.com

Signup for Exclusive "Subscriber-only" Content

Loading