Kubernetes
CronJob
DevOps
Automation
CloudComputing

How to run a Kubernetes CronJob immediately (kubectl trigger)

Codemia Knowledge Hub ·

Create a one-off Job from the CronJob's template with kubectl create job --from=cronjob/<name> <job-name>. It runs the same pod spec right away and leaves the CronJob's schedule alone.

Create a Job from the CronJob

bash
kubectl create job --from=cronjob/nightly-report nightly-report-manual

This copies the jobTemplate of the CronJob nightly-report into a normal Job named nightly-report-manual. The CronJob keeps its schedule and still runs later; the manual run is just an extra execution.

For a unique name, add a timestamp:

bash
kubectl create job --from=cronjob/nightly-report nightly-report-manual-20260311

This is the cleanest method for testing, emergency runs and debugging.

Confirm the job actually started

Inspect it like any other job:

bash
1kubectl get jobs
2kubectl describe job nightly-report-manual
3kubectl get pods --selector=job-name=nightly-report-manual
4kubectl logs job/nightly-report-manual

These show whether the pod was created, whether it is failing on image pulls or environment setup, and whether the container completed. Check the pod logs too: a job can exist while its pod crash-loops or fails immediately.

Why not edit the schedule instead

Temporarily setting the schedule to every minute, waiting, and changing it back works, but it is noisy, easy to forget, and can trigger several runs instead of one. A one-off Job:

  • leaves the original schedule untouched
  • avoids repeated accidental runs from a temporary cron expression
  • has its own job name and logs

In most operational environments, that keeps troubleshooting much cleaner, and nobody has to remember to revert a modified CronJob.

Changing parameters for a manual run

If you need a small variation for debugging, such as a different environment variable or argument, export the CronJob:

bash
kubectl get cronjob nightly-report -o yaml

Copy its jobTemplate.spec into a standalone Job manifest and adjust it:

yaml
1apiVersion: batch/v1
2kind: Job
3metadata:
4  name: nightly-report-debug
5spec:
6  template:
7    spec:
8      restartPolicy: Never
9      containers:
10        - name: report
11          image: my-registry/report:1.0
12          args:
13            - "--dry-run"

Apply it:

bash
kubectl apply -f nightly-report-debug.yaml

This takes more work than kubectl create job --from=cronjob, but it gives you a controlled variant of the scheduled workload.

Manual jobs ignore concurrencyPolicy

The CronJob's concurrencyPolicy only controls what the CronJob controller does with scheduled runs. It does not stop you from creating an extra manual Job, so you can start one while a scheduled run is still active. Be careful with backups, billing, data imports, and anything else where duplicate execution hurts.

Also, --from=cronjob/... copies the current template. If the CronJob spec is wrong, the manual job reproduces the same mistake.

Cleaning up manual jobs

If your cluster does not already use TTL cleanup, delete manual jobs after testing. Leaving many old manual jobs around makes later troubleshooting harder:

bash
kubectl delete job nightly-report-manual

Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design