Notes

Run a Kubernetes CronJob once, on demand

Create a separate Job from a CronJob template, follow its logs and distinguish a successful run from a failed one. The schedule stays unchanged.

A CronJob stores a schedule and a Job template. To run that template immediately, create a new Job from it. You do not need to edit the schedule or wait for its next tick.

First select the right cluster and namespace. A correct command against the wrong context is still the wrong operation. The commands below assume an existing daily-report CronJob in a namespace named reports.

Inspect before creating

kubectl config current-context
kubectl get cronjobs -n reports
kubectl get cronjob daily-report -n reports -o yaml
kubectl get jobs -n reports

Check the image, environment, service account, storage and currently running jobs. A manual invocation may send real emails, charge accounts or process the same batch as a scheduled invocation. Confirm the workload can tolerate a second execution before creating one.

Create a separate Job

Choose a unique, short Job name for each run:

job="daily-report-manual-$(date -u +%Y%m%d%H%M%S)"
kubectl create job "$job" \
  --from=cronjob/daily-report \
  -n reports

The timestamp makes accidental name reuse less likely; it is not a concurrency lock. kubectl create job fails if a Job with that name already exists. It copies the template into an independent Job; subsequent edits to the CronJob do not rewrite that Job.

To inspect what would be submitted without creating it, run the same command with --dry-run=client -o yaml. Client-side generation does not check admission policy, image availability or whether the workload can actually start.

Follow execution and check the outcome

In the same shell, where job is still set:

kubectl logs -f "job/$job" -n reports --all-containers=true
kubectl wait --for=condition=complete "job/$job" \
  -n reports --timeout=300s
kubectl get job "$job" -n reports

A newly created Job may not have a Pod ready when you request logs. If that happens, inspect its Pods and retry once a container starts. Following one Pod’s logs also does not aggregate every retry or parallel Pod.

kubectl wait exiting successfully confirms the Complete condition. A timeout does not by itself mean the Job failed: it might still be running, pending or retrying. Diagnose it with:

kubectl describe job "$job" -n reports
kubectl get pods -n reports -l "batch.kubernetes.io/job-name=$job"

Keep the schedule and concurrency in mind

The CronJob’s concurrencyPolicy governs Jobs created by that CronJob controller. Do not assume it serializes an independently created manual Job with scheduled runs. If exclusivity matters, implement it in the workload or coordinate execution operationally.

Likewise, suspending the CronJob prevents future scheduled starts; it does not cancel existing Jobs or prevent this manual creation. Treat the Job’s own resource limits, deadlines, retry policy and cleanup policy as part of the template you are choosing to run.

The exact command flags are documented in kubectl create job. The CronJob documentation explains scheduling and concurrency limits.