In particular, I want to set environment variables. I have a CronJob
definition that runs on a schedule, but every so often I want to invoke it manually while specifying slightly different environment variables.
I can invoke the cron job manually with this command:
kubectl create job --from=cronjob/my-cron-job my-manual-run
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 create job
command?
I built on the answer from @Rico to first create the job in kubectl as a --dry-run
, then modifiy the job using jq
, then apply. This removes the need for having base JSON files and having to manage additional job metadata fields.
For example:
$ kubectl create job --from=cronjob/my-cron-job my-manual-run --dry-run -o "json" \
| jq ".spec.template.spec.containers[0].env += [{ \"name\": \"envname1\", value:\"$envvalue1\" }]" \
| kubectl apply -f -
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With