Skip to content

How to restart Kubernetes pods using kubectl?

In this post we will see how to restart your running pods with kubectl. We recommend two methods – rollout restart and scaling your replicas.

Rollout Restart

The simplest way to restart your kubernetes pods would be to use the rollout restart command. This can be used to restart all pods from deployment in sequence. This is the most recommended strategy as it will not result in a service outage.

Advertisements

Syntax

kubectl rollout restart deployment <name> -n <namespace>

Deployment name is mandatory here. If you don’t provide namespace it would use the ‘default‘ namespace. If you want to restart pods from all namespaces, you can pass namespace as –all-namespaces

Example

kubectl rollout restart deployment poopcode-app-backend -n poopcode

Another way is to scale your pods by changing the replicas.

Scale replicas

Second strategy for restarting pods is to scale the number of deployment replicas to zero and scaling them back up to the desired number. This strategy will cause an outage and your pods will temporarily be not available as this command stops, terminates and recreates your pods.

Advertisements

Syntax

kubectl scale deployment <name> --replicas=<num> -n <namespace>

Example

kubectl scale deployment poopcode-apps --replicas=0 -n poopcode
kubectl scale deployment poopcode-apps --replicas=1 -n poopcode
See also  Install Kubernetes Kompose in CentOS

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.