How to rollout restart deployment through the API?

11/26/2019

Kubernetes 1.15 introduced the command

kubectl rollout restart deployment my-deployment

Which would be the endpoint to call through the API? For example if I want to scale a deployment I can call

PATCH /apis/apps/v1/namespaces/my-namespace/deployments/my-deployment/scale
-- Leandro Cofre
kubernetes

1 Answer

11/26/2019

If you dig around in the kubectl source you can eventually find (k8s.io/kubectl/pkg/polymorphichelpers).defaultObjectRestarter. All that does is change an annotation:

apiVersion: apps/v1
kind: Deployment
spec:
  template:
    meta:
      annotations:
        kubectl.kubernetes.io/restartedAt: '2006-01-02T15:04:05Z07:00'

Anything that changes a property of the embedded pod spec in the deployment object will cause a restart; there isn't a specific API call to do it.

The useful corollary to this is that, if your kubectl and cluster versions aren't in sync, you can use kubectl rollout restart in kubectl 1.14 against older clusters, since it doesn't actually depend on any changes in the Kubernetes API.

-- David Maze
Source: StackOverflow