Example CronJob
Runs at 02:00 in the given time zone, never runs two copies at once, and keeps a short history:
apiVersion: batch/v1
kind: CronJob
metadata:
name: nightly-report
spec:
schedule: "0 2 * * *"
timeZone: "Europe/Berlin"
concurrencyPolicy: Forbid
startingDeadlineSeconds: 300
successfulJobsHistoryLimit: 3
failedJobsHistoryLimit: 1
jobTemplate:
spec:
template:
spec:
restartPolicy: OnFailure
containers:
- name: report
image: busybox:1.36
command: ["sh", "-c", "date; echo running report"]Fields that matter for scheduling
| Field | What it does |
|---|---|
schedule | The cron expression. Without timeZone, it uses the time zone of the kube-controller-manager, which is usually UTC. |
timeZone | An IANA name such as Europe/Berlin or America/New_York. Stable since Kubernetes 1.27. Don't put CRON_TZ= or TZ= in schedule; it isn't supported. |
concurrencyPolicy | Allow (default) lets runs overlap, Forbid skips a run while the last one is still going, Replace stops the old run and starts the new one. |
startingDeadlineSeconds | How late a run may start before it counts as missed, for example after the controller was down. |
suspend | Set to true to pause the schedule without deleting the CronJob. |
Test a CronJob without waiting
Create a one-off Job from the CronJob's template, then follow its logs:
kubectl create job --from=cronjob/nightly-report nightly-report-manual
kubectl logs -f job/nightly-report-manualFrequently asked questions
Why does my CronJob say "too many missed start times"?
If more than 100 scheduled runs were missed, for example because the CronJob was suspended or the controller was down, Kubernetes stops trying to start them. Set startingDeadlineSeconds so only recent missed runs are counted.
What time zone does a Kubernetes CronJob use?
The time zone of the kube-controller-manager unless you set spec.timeZone. On managed clusters this is normally UTC.
Can a CronJob run every 30 seconds?
No. The smallest unit in the schedule is one minute. For shorter intervals, run a Deployment whose container loops with a sleep.