kubernetes restart all the pods using REST api

5/16/2020

I need to update all the pods(rolling updates), with env variable changes

I am not using kubectl, but using REST api.

Right not i am deleting the service and pods; And then recreating both services and pods. (It usually take around minutes, and there is downtime). Wanted similar with rolling update, without downtime.

-- shrw
kubernetes

2 Answers

5/16/2020

If you want to restart all pod attached to a deployment, then you can do that by running

$ curl -k --data '{"spec":{"template":{"metadata":{"annotations":{"kubectl.kubrnetes.io/restartedAt":"'"$(date +%Y-%m-%dT%T%z)"'"}}}}}' -XPATCH   -H "Accept: application/json, */*" -H "Content-Type: application/strategic-merge-patch+json" localhost:8001/apis/extensions/v1beta1/namespaces/default/deployments/mydeployment
-- hoque
Source: StackOverflow

5/16/2020

Use deployment instead of pods.

Deployment has DeploymentStrategy , maxUnavailable, maxSurge using which you can achieve zero downtime upgrade.

For changing env just change it the deployment yaml and apply it to the cluster. It will rollout the deployment without any downtime.

Kubectl internally calls rest api exposed by Kubernets API Server. You could check what rest call being sent by kubectl by increasing the verbosity. Once you know the rest api being called you could call those apis as well.

kubectl rollout restart deployment/frontend -v=10
-- Arghya Sadhu
Source: StackOverflow