Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Correct way to scale/restart an application down/up in kubernetes (replicaset, deployments and pod deletion)?

Tags:

kubernetes

I usually restart my applications by:

kubectl scale deployment my-app --replicas=0

Followed by:

kubectl scale deployment my-app --replicas=1

which works fine. I also have another running application but when I look at its replicaset I see:

$ kubectl get rs
NAME                                        DESIRED   CURRENT   READY     AGE
another-app                                 2         2         2         2d

So to restart that correctly I would of course need to:

kubectl scale deployment another-app --replicas=0
kubectl scale deployment another-app --replicas=2

But is there a better way to do this so I don't have to manually look at the repliasets before scaling/restarting my application (that might have replicas > 1)?

like image 396
u123 Avatar asked Oct 24 '25 01:10

u123


1 Answers

You can restart pods by using level

kubectl delete pods -l name=myLabel

You can rolling restart of all pods for a deployments, so that you don't take the service down

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

And After kubernetes version 1.15 you can

kubectl rollout restart deployment your_deployment_name
like image 166
hoque Avatar answered Oct 26 '25 18:10

hoque