egeland
egeland

Reputation: 1304

How to "deploy" in kubernetes without any changes, just to get pods to cycle

What I am trying to do:

The app that runs in the Pod does some refreshing of its data files on start. I need to restart the container each time I want to refresh the data. (A refresh can take a few minutes, so I have a Probe checking for readiness.)

What I think is a solution:

I will run a scheduled job to do a rolling-update kind of deploy, which will take the old Pods out, one at a time and replace them, without downtime.

Where I'm stuck:

How do I trigger a deploy, if I haven't changed anything??

Also, I need to be able to do this from the scheduled job, obviously, so no manual editing..

Any other ways of doing this?

Upvotes: 14

Views: 14628

Answers (2)

vdboor
vdboor

Reputation: 22526

As of kubectl 1.15, you can run:

kubectl rollout restart deployment <deploymentname>

What this does internally, is patch the deployment with a kubectl.kubernetes.io/restartedAt annotation so the scheduler performs a rollout according to the deployment update strategy.

For previous versions of Kubernetes, you can simulate a similar thing:

 kubectl set env deployment --env="LAST_MANUAL_RESTART=$(date +%s)"  "deploymentname"

And even replace all in a single namespace:

 kubectl set env --all deployment --env="LAST_MANUAL_RESTART=$(date +%s)" --namespace=...

Upvotes: 39

Maciej Strzelecki
Maciej Strzelecki

Reputation: 553

According to documentation:

Note: a Deployment’s rollout is triggered if and only if the Deployment’s pod template (i.e. .spec.template) is changed, e.g. updating labels or container images of the template.

You can just use kubectl patch to update i.e. a label inside .spec.template.

Upvotes: 11

Related Questions