Skip to content
Latchkey

kubectl create job: Usage, Options & Common CI Errors

Kick off a one-off Job - or trigger a CronJob on demand.

kubectl create job creates a single Job, either from an image or from an existing CronJob's template. In CI it is the idiomatic way to run a database migration or a one-shot task and gate on its result.

What it does

kubectl create job NAME --image=IMG runs a one-off Job; --from=cronjob/NAME copies a CronJob's pod template so you trigger it immediately without waiting for its schedule. Pair it with kubectl wait --for=condition=complete to block until the Job finishes.

Common usage

Terminal
kubectl create job migrate --image=myreg/app:${GIT_SHA} -- ./migrate.sh
kubectl create job run-now --from=cronjob/nightly-report
kubectl wait --for=condition=complete job/migrate --timeout=300s
kubectl logs job/migrate

Common errors in CI

"AlreadyExists" on a fixed Job name is the re-run trap - append a unique suffix (the build number or git SHA) so each run gets its own Job, or delete the prior Job first. A Job that fails is not surfaced by create itself; you must kubectl wait --for=condition=complete (which times out non-zero on failure) and read the pod logs - a green create is not a green Job. The Job's backoffLimit means it may retry several times before reporting failed, so set a generous wait --timeout. Use --for=jsonpath to distinguish complete from failed if you need to branch.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →