<p>In a k8s cronjob, can I pull the image (or just the tag) which is being used dynamically (<strong>at job execution time</strong>, not at deployment time using helm etc.) from a configmap (or something similar)?</p>
<pre><code>apiVersion: batch/v1
kind: CronJob
metadata:
  name: hello
spec:
  schedule: &quot;* * * * *&quot;
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: hello
            image: busybox:{my-dynamic-tag-here}
</code></pre>
<p>My use case is that I have a lot of cron jobs which are getting created at different times and I would need to make changes to the image/tag that is being used for them at a later time.</p>

silent
<p>The <code>image:</code> value must be directly specified in the Kubernetes manifest.  Nothing in Kubernetes proper does any sort of lookup, substitution, or indirect reference to modify this value.</p>
<p>Setting this image is one of the most useful abilities of wrapper tools like Helm or Kustomize.  I'm most familiar with <a href="https://helm.sh" rel="nofollow noreferrer">Helm</a>.  There you'd use Helm's templating language to inject the image tag at deployment time</p>
<pre class="lang-yaml prettyprint-override"><code># templates/cronjob.yaml
image: busybox:{{ .Values.dynamicTag }}
</code></pre>
<p>and then when you actually go to deploy it, you can specify that value at the command line</p>
<pre class="lang-bash prettyprint-override"><code>helm upgrade my-app . --set-string dynamicTag=20230710
</code></pre>
<p>There is also a path to pass a file of YAML (or JSON) deploy-time configuration values, which can be clearer if your CI tool can write this file.</p>
<p><a href="https://kustomize.io" rel="nofollow noreferrer">Kustomize</a> has a specific path to <a href="https://kubectl.docs.kubernetes.io/references/kustomize/kustomization/images/" rel="nofollow noreferrer">change the <code>image:</code> value</a>.  Again, this involves your CI tool writing out the Kustomization bundle, or running the <code>kustomize edit</code> CLI tool to modify it at deploy time.</p>
