Rolling restart of pods in deployment

4,717 views
Skip to first unread message

Keshava Bharadwaj

unread,
Dec 15, 2017, 5:00:24 AM12/15/17
to kubernet...@googlegroups.com
Hi,

We have a simple deployment of 3 replicas.
We have a requirement to have a kubernetes cron job, that would need to restart(rolling restart) the pods/containers in the deployment.

Use-case: we use certs in our services in deployment and we need the certificates to be auto renewed before expiry(very short - every 15 days), and hence the cron would restart
the pods before expiry. On a restart, during container startup, it would fetch certificates.

Is this possible to achieve this with existing Deployments construct and API?

From documentation,  -
 A Deployment’s rollout is triggered if and only if the Deployment’s pod template (that is, .spec.template) is changed, for example if the labels or container images of the template are updated. Other updates, such as scaling the Deployment, do not trigger a rollout.

So, i wanted to ask whether - is it possible to have rolling restart of containers declared as part of deployment periodically?

Tim Hockin

unread,
Dec 15, 2017, 11:42:13 AM12/15/17
to Kubernetes user discussion and Q&A
What I have seen several people do for this is to increment an env
var, or use a timestamp - something trivial that doesn't impact the
app, but forces a restart. Updating an env var can not ever be done
without restart.

On Fri, Dec 15, 2017 at 2:00 AM, Keshava Bharadwaj
<kb.sa...@gmail.com> wrote:
> Hi,
>
> We have a simple deployment of 3 replicas.
> We have a requirement to have a kubernetes cron job, that would need to
> restart(rolling restart) the pods in the deployment.
>
> Use-case: we use certs in our services in deployment and we need the
> certificates to be auto renewed before expiry, and hence the cron would
> restart
> the pods before expiry. On a container startup, it would fetch certificates.
>
> Is this possible with Deployments construct and API?
>
> From documentation, -
>>
>> A Deployment’s rollout is triggered if and only if the Deployment’s pod
>> template (that is, .spec.template) is changed, for example if the labels or
>> container images of the template are updated. Other updates, such as scaling
>> the Deployment, do not trigger a rollout.
>
>
> So, i wanted to ask whether - is it possible to have rolling restart of
> containers periodically?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Kubernetes user discussion and Q&A" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to kubernetes-use...@googlegroups.com.
> To post to this group, send email to kubernet...@googlegroups.com.
> Visit this group at https://groups.google.com/group/kubernetes-users.
> For more options, visit https://groups.google.com/d/optout.

Timo Reimann

unread,
Dec 16, 2017, 2:57:00 AM12/16/17
to Kubernetes user discussion and Q&A
I believe you can also update / create an annotation inside the pod spec's metadata section if you fear that an environment variable might collide or just pollute your application's env var space.

More discussions, tips, and related issues regarding the subject of forced restarts can be found in https://github.com/kubernetes/kubernetes/issues/27081.

Timo Reimann

unread,
Dec 16, 2017, 3:01:51 AM12/16/17
to Kubernetes user discussion and Q&A
Actually, it's the Deployment's pod template (.spec.template) that needs to host the annotation. Always getting confused. https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#updating-a-deployment has it formally defined.

Keshava Bharadwaj

unread,
Dec 18, 2017, 4:01:21 AM12/18/17
to Kubernetes user discussion and Q&A
Thanks  for the inputs. Using annotations and updating them using patch serves the purpose. 

- Keshava
Reply all
Reply to author
Forward
0 new messages