Kubernetes--How to trigger a job if configmap changes?

12/13/2019

We have a scenario in our deployment process where an activity needs to be performed only once before the actual application containers are live and ready. This activity can not be placed as an init container because init container will be executed with every replica of application container but in this case, this activity needs to be done only once.

To achieve this, I have created a kubernetes job which executes that activity and completes.

  1. Is there a way to check in my application container deployment definition that this particular Job has been completed? Are there any pre-defined keys in kubernetes which stores this metadata information and can be used to identify the job status?

  2. This Job is using a configMap and the container used in this Job loads the configuration files (provided by configMap) in Directory Server. Is there a way to trigger the job automatically if configMap changes? I can delete the job and recreate using kubectl but I am looking for an auto trigger. Is there any possible way available in OpenShift or HELM to do this if not in Kubernetes?

-- DD2607
configmap
kubernetes
kubernetes-jobs
openshift-origin

2 Answers

1/7/2020

When a ConfigMap already being consumed in a volume is updated, projected keys are eventually updated as well. refer Mounted ConfigMap on official kubernetes docs.

And for some kind of auto-trigger you can try using CronJob option say based on a time-based if you know your data changes every tow hours or every midnight.

-- DT.
Source: StackOverflow

12/13/2019

Helm has post-deploy hooks for this kind of thing, though they can be a little rough to work with. We use a custom operator for this so we can have an explicit state machine on our deployments (init -> migrate -> deploy -> test -> ready). But that's a lot of work to write.

-- coderanger
Source: StackOverflow