Skip to content

kubectl rollout restart deployment #657

@vdesplanque

Description

@vdesplanque

Hello,

I didn't find a built-in way in the client to execute a "rollout restart" of a deployment.

I figured out (by using --v=9 at the end of my command) that the request that kubernetes send internally is :

I0706 16:17:18.956135    2800 request.go:1068] Request Body: {"spec":{"template":{"metadata":{"annotations":{"kubectl.kubernetes.io/restartedAt":"2021-07-06T16:17:18+02:00"}}}}}

I tried to use "PatchNamespacedDeploymentAsync", with no luck.

Here is the code I use :

var deployment = await _kubernetes.ReadNamespacedDeploymentAsync(deploymentName, @namespace);
var restart = new Dictionary<string, string>(deployment.Metadata.Annotations)
{
    ["kubectl.kubernetes.io/restartedAt"] = DateTime.UtcNow.ToString("s")
};

var patch = new JsonPatchDocument<V1Deployment>();
patch.Replace(e => e.Metadata.Annotations, restart);
var patchResponse = await _kubernetes.PatchNamespacedDeploymentAsync(new V1Patch(patch), deploymentName, @namespace);
var patchedDeployment = await _kubernetes.ReadNamespacedDeploymentAsync(deploymentName, @namespace);

"patchedDeployment", that I retrieve by doing again a ReadNamespacedDeploymentAsync contains my updated Metadata.Annotations "kubectl.kubernetes.io/restartedAt" with the expected value, but the related pods are not restarted.

The pods are restarted almost instantly when I run "kubectl rollout restart deployment -n namespace --v=9"

What do I miss ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions