<p>I need a job to be run once every time I apply my configuration to Kubernetes. I tried to use a job but it does not allow to update image version and requires deletion of previous job. I tried to use initContainer but it seems to be overkill since I don't need this to be run every time pod is started.
Essentially I have simple deployment with single pod and need to run a job before deployment is happening every time I update image in deployment and confused what is the best way to achieve it. Job seems to be perfect for this but issue is that I can not submit the same config second time with update image tag for job.</p>

Gregory Suvalian
<p>I'm afraid there is no other option. I recently had a similar situation and this is how I'm doing the job recreation:</p>
<pre><code>kubectl get &lt;job name&gt; -o json | \
jq -r '.metadata.annotations.&quot;kubectl.kubernetes.io/last-applied-configuration&quot;' | \
kubectl replace --save-config --force -f -
</code></pre>
<p>It uses the <code>&quot;kubectl.kubernetes.io/last-applied-configuration&quot;</code> annotation, that holds the initial job config that was applied, without the auto-generated/cluster fields. Then the <code>kubectl replace</code> will completely replace the current one with a copy of itself, simulating the &quot;rerun&quot; that you are looking for.</p>
<p>You can then add to the snippet above some code replacing the image name/tag, before the <code>kubectl replace</code>.</p>
