Pages

Sunday, January 9, 2022

Kubernetes - Restart Pods

There are many times where a developer needs to restart his application. When the application is deployed in a container/pod implementation like in kubernetes, the restart works in a different way. 


There are multiple ways to restart an application pod.

1.Use the deployment rollout restart command as below

[jagadishmanchala@Jagadish-theOne:k8s] kubectl get deploy

NAME                  READY   UP-TO-DATE   AVAILABLE   AGE

test-service-deploy   2/2     2            2           23m


Restart the deployment using below command,

[jagadishmanchala@Jagadish-theOne:k8s] kubectl rollout restart deployment test-service-deploy

deployment.apps/test-service-deploy restarted


Now we can see that the deployment is restarted 

[jagadishmanchala@Jagadish-theOne:k8s] kubectl get deploy

NAME                  READY   UP-TO-DATE   AVAILABLE   AGE

test-service-deploy   2/2     2            2           1m


2. Modify the Env Variables of a deployment as below,

[jagadishmanchala@Jagadish-theOne:k8s] kubectl set env deployment test-service-deploy DEPLOY_DATE="$(date)"

deployment.apps/test-service-deploy env updated


Set env sets up a change in env variables , and set the env variable DEPLOY_DATE to the latest timestamp for the deployment and causes the pod to restart


3. Scale Down or Up for the deployment

[jagadishmanchala@Jagadish-theOne:k8s] kubectl scale deployment test-service-deploy --replicas=0

deployment.apps/test-service-deploy scaled


[jagadishmanchala@Jagadish-theOne:k8s] kubectl scale deployment test-service-deploy --replicas=1

deployment.apps/test-service-deploy scaled


Note - We can’t just restart the pods alone, pods that are created as a part of deployment or replica set or replication controller can have the option to restart. 

No comments :

Post a Comment