'How to rollout restart deployment through the API?

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


Solution 1:[1]

TLDR

curl --location --request PATCH 'https://kubernetes.docker.internal:6443/apis/apps/v1/namespaces/default/deployments/keycloak?fieldManager=kubectl-rollout&pretty=true' \
--header 'Content-Type: application/strategic-merge-patch+json' \
--data-raw '{
    "spec": {
        "template": {
            "metadata": {
                "annotations": {
                    "kubectl.kubernetes.io/restartedAt": <time.Now()>
                }
            }
        }
    }
}'

If you have kubectl you can debug the calls on a local minikube by providing the extra flag --v 9 to your command. That said you can try to do a dummy rollout restart on your local cluster to see the results.

For future readers: This can vary between versions, but if you are in apps/v1 it should be ok.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1