Kubernetes CronJob Schedule Guide
Kubernetes CronJobs create Jobs on a recurring schedule using standard Unix cron syntax. This guide covers the cron format, YAML configuration, best practices, and ready-to-use examples.
Kubernetes Cron Schedule Format
Kubernetes uses the standard 5-field Unix cron format. Quartz-style expressions (with seconds) are not supported.
┌───────────── minute (0-59) │ ┌───────────── hour (0-23) │ │ ┌───────────── day of month (1-31) │ │ │ ┌───────────── month (1-12) │ │ │ │ ┌───────────── day of week (0-6, Sun=0) │ │ │ │ │ * * * * *
CronJob YAML Examples
Run every 5 minutes — */5 * * * *
apiVersion: batch/v1
kind: CronJob
metadata:
name: health-check
spec:
schedule: "*/5 * * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: health-check
image: busybox:latest
command: ["sh", "-c", "echo Health check at $(date)"]
restartPolicy: OnFailureDaily at midnight (database backup) — 0 0 * * *
apiVersion: batch/v1
kind: CronJob
metadata:
name: daily-backup
spec:
schedule: "0 0 * * *"
concurrencyPolicy: Forbid
successfulJobsHistoryLimit: 3
failedJobsHistoryLimit: 1
jobTemplate:
spec:
template:
spec:
containers:
- name: backup
image: postgres:16
command: ["pg_dump", "-h", "db-host", "-U", "admin", "mydb"]
restartPolicy: OnFailureWeekly on Sunday at 2:00 AM (cleanup) — 0 2 * * 0
apiVersion: batch/v1
kind: CronJob
metadata:
name: weekly-cleanup
spec:
schedule: "0 2 * * 0"
concurrencyPolicy: Replace
jobTemplate:
spec:
template:
spec:
containers:
- name: cleanup
image: alpine:latest
command: ["sh", "-c", "find /data/logs -mtime +30 -delete"]
restartPolicy: OnFailureConcurrency Policies
| Policy | Behavior | Best For |
|---|---|---|
| Allow | Runs new jobs even if previous ones are still active | Independent, idempotent tasks |
| Forbid | Skips new job if previous is still running | Database backups, non-overlapping work |
| Replace | Cancels running job and starts new one | Cache refresh, latest-data-wins scenarios |
Setting a Timezone (Kubernetes 1.27+)
Starting with Kubernetes 1.27, you can set the .spec.timeZone field to any valid IANA timezone:
apiVersion: batch/v1
kind: CronJob
metadata:
name: timezone-example
spec:
schedule: "0 9 * * 1-5"
timeZone: "America/New_York"
jobTemplate:
spec:
template:
spec:
containers:
- name: notify
image: alpine:latest
command: ["echo", "Good morning NYC!"]
restartPolicy: OnFailureFrequently Asked Questions
What cron format does Kubernetes use?
Kubernetes CronJobs use the standard Unix 5-field cron format: minute (0-59), hour (0-23), day of month (1-31), month (1-12), and day of week (0-6, Sunday=0). Quartz-style 6-7 field expressions are not supported.
What timezone do Kubernetes CronJobs use?
By default, Kubernetes CronJobs use the timezone of the kube-controller-manager, which is usually UTC. Starting with Kubernetes 1.27, you can set the .spec.timeZone field to specify a timezone like "America/New_York" or "Europe/London".
What is the concurrencyPolicy in a Kubernetes CronJob?
The concurrencyPolicy controls what happens when a new job is scheduled while the previous one is still running. Options are: Allow (default, runs concurrently), Forbid (skips the new job), and Replace (stops the old job and starts the new one).
How do I check CronJob history in Kubernetes?
Use "kubectl get cronjobs" to list CronJobs and "kubectl get jobs" to see completed/running jobs. Use successfulJobsHistoryLimit and failedJobsHistoryLimit in the CronJob spec to control how many completed jobs are kept.
Can I suspend a Kubernetes CronJob?
Yes. Set .spec.suspend to true in the CronJob manifest or run "kubectl patch cronjob <name> -p '{"spec":{"suspend":true}}'". While suspended, no new jobs will be created at scheduled times.