Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to rolling restart pods without changing deployment yaml in kubernetes?

Tags:

kubernetes

In kubernetes there is a rolling update (automatically without downtime) but there is not a rolling restart, at least i could not find. We have to change deployment yaml. Is there a way to make rolling "restart", preferably without changing deployment yaml?

like image 317
muratcavus Avatar asked Aug 19 '19 15:08

muratcavus


People also ask

How do you restart a pod in Kubernetes without deployment?

Restart Pods in Kubernetes with the rollout restart CommandBy running the rollout restart command. Run the rollout restart command below to restart the pods one by one without impacting the deployment ( deployment nginx-deployment ). Now run the kubectl command below to view the pods running ( get pods ).

How do you use the rolling reboot pod in Kubernetes?

Another way to restart the pod is to reduce the number of replicas to 0 and scale back to the proper state. This requires all existing pods to exit, and a new pod is scheduled in its place. If we limit the number of replicas to 0, it will stop.


1 Answers

Before kubernetes 1.15 the answer is no. But there is a workaround of patching deployment spec with a dummy annotation:

kubectl patch deployment web -p \   "{\"spec\":{\"template\":{\"metadata\":{\"annotations\":{\"date\":\"`date +'%s'`\"}}}}}" 

As of kubernetes 1.15 you can use:

kubectl rollout restart deployment your_deployment_name 

CLI Improvements

  • Created a new kubectl rollout restart command that does a rolling restart of a deployment.
  • kubectl rollout restart now works for DaemonSets and StatefulSets
like image 140
stratovarius Avatar answered Sep 21 '22 18:09

stratovarius