Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

kubernetes

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?

like image 793
egeland Avatar asked Nov 09 '16 04:11

egeland


People also ask

What is the difference between Deployments and pods?

Their Role in Building and Managing Software As we now know, a pod is the smallest unit of Kubernetes used to house one or more containers and run applications in a cluster, while deployment is a tool that manages the performance of a pod.

What is difference between deployment and pod in Kubernetes?

In short, a pod is the core building block for running applications in a Kubernetes cluster; a deployment is a management tool used to control the way pods behave.


2 Answers

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.

like image 45
Maciej Strzelecki Avatar answered Sep 27 '22 18:09

Maciej Strzelecki


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=...
like image 195
vdboor Avatar answered Sep 27 '22 18:09

vdboor