<p>In particular, I want to set environment variables. I have a <code>CronJob</code> definition that runs on a schedule, but every so often I want to invoke it manually while specifying slightly different environment variables.</p>

<p>I can invoke the cron job manually with this command:</p>

<pre><code>kubectl create job --from=cronjob/my-cron-job my-manual-run
</code></pre>

<p>But that copies in all the same environment variables that are specified in the resource definition. How can I add additional, new environment variables using this <code>create job</code> command?</p>

soapergem
<p>I built on the answer from @Rico to first create the job in kubectl as a <code>--dry-run</code>, then modifiy the job using <code>jq</code>, then apply. This removes the need for having base JSON files and having to manage additional job metadata fields.</p>
<p>For example:</p>
<pre class="lang-sh prettyprint-override"><code>$ kubectl create job --from=cronjob/my-cron-job my-manual-run --dry-run -o &quot;json&quot; \
  | jq &quot;.spec.template.spec.containers[0].env += [{ \&quot;name\&quot;: \&quot;envname1\&quot;, value:\&quot;$envvalue1\&quot; }]&quot; \
  | kubectl apply -f -
</code></pre>
