How to “deploy” in kubernetes without any changes,

2020-06-24 06:30发布

问题:

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?

回答1:

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.



回答2:

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=...


标签: kubernetes