Skip to content

Instantly share code, notes, and snippets.

@bastman
Last active June 16, 2020 07:04
Show Gist options
  • Save bastman/e26482d83227417083db7a32712ad0b2 to your computer and use it in GitHub Desktop.
Save bastman/e26482d83227417083db7a32712ad0b2 to your computer and use it in GitHub Desktop.
k8s create job from cronjob (how to run a cronjob now + once)
$ kubectl create job --from=cronjob/<CRONJOB-NAME> <NEW-JOB-NAME>
e.g.:
$ kubectl create job --from=cronjob/my-cron my-cron-manual-001
function k8s-cronjob-run() {
source_cronjob_name=$1
[ -z "$source_cronjob_name" ] && echo "Please provide source-cronjob-name !" && return
sink_run_id=$(date -u +"%Y-%m-%dt%H.%M.%Sz")
sink_job_name=${source_cronjob_name}-run-${sink_run_id}
echo "=== cronjob: $source_cronjob_name -> job: $sink_job_name ==="
cmd="kubectl create job --from=cronjob/${source_cronjob_name} ${sink_job_name}"
echo $cmd
$cmd
echo "You may want to: ... "
echo " kubectl get job ${sink_job_name}"
echo " kubectl describe job ${sink_job_name}"
echo " kubectl delete job ${sink_job_name}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment