Skip to content
Cron Cookbook

Kubernetes CronJob: schedule syntax and examples

A Kubernetes CronJob creates a Job on a cron schedule: put a five-field expression in spec.schedule, the Pod to run in spec.jobTemplate, and apply it with kubectl apply. Set spec.timeZone to pin the schedule to a zone, and concurrencyPolicy: Forbid to stop runs overlapping.

Six things that differ from crontab

  1. The controller's time zone, unless you set timeZone

    Without spec.timeZone, the schedule follows the kube-controller-manager's local time, which you may not control on a managed cluster. Set it to an IANA name such as Etc/UTC.
  2. Sunday is 0, never 7

    Day of week runs 0–6. 0 0 * * 7 is rejected, though most crontabs accept it. Names like mon-fri work in any case.
  3. Five fields only

    No seconds field, no year, and no L, W or #. A Quartz or Spring expression has to be rewritten.
  4. Runs overlap by default

    concurrencyPolicy defaults to Allow, so a slow Job keeps running while the next one starts. Set Forbid or Replace.
  5. Missed runs aren't all caught up

    After downtime or a suspension, the controller starts at most one Job, for the most recent missed time.
  6. Scheduling is approximate

    Kubernetes may occasionally create two Jobs for one scheduled time, or none, so make the work idempotent.

Create a CronJob

The example manifest runs a container at 02:00 London time every night. Only schedule and jobTemplate are required; the template has the same schema as a Job's spec, and its Pod needs restartPolicy set to OnFailure or Never. Apply it, then watch the Jobs it creates:

terminal
kubectl apply -f cronjob.yaml
kubectl get cronjob nightly-report
kubectl get jobs --watch

For a quick test, kubectl can create one without a file:

terminal
kubectl create cronjob nightly-report \
  --image=busybox:1.36 \
  --schedule="0 2 * * *" \
  -- /bin/sh -c "date; echo report done"

Each Job is named after the CronJob plus a suffix, and from Kubernetes 1.32 it carries a batch.kubernetes.io/cronjob-scheduled-timestamp annotation with the time it was scheduled for. Editing the CronJob changes only Jobs that start afterwards; running ones keep the old template.

The schedule syntax

spec.schedule takes five fields: minute (0–59), hour (0–23), day of month (1–31), month (1–12 or jan–dec) and day of week (0–6 or sun–sat, with 0 as Sunday). Lists, ranges and steps work as in crontab, names are case-insensitive, and ? means the same as *. When both day fields are restricted, a day matching either one runs, as in standard cron. Quote the value in YAML, since a schedule starting with * or @ isn't a valid plain string.

The usual macros are accepted too:

MacroSame asRuns
@yearly or @annually0 0 1 1 *At 00:00 on the 1st of January.
@monthly0 0 1 * *At 00:00 on the 1st of every month.
@weekly0 0 * * 0At 00:00 on Sundays.
@daily or @midnight0 0 * * *At 00:00 every day.
@hourly0 * * * *Every hour, on the hour.

Kubernetes validates the schedule with the robfig/cron parser when you apply the manifest, so a bad expression is refused straight away. These are the mistakes it catches most often, with the message that follows Invalid value:

You wroteErrorFix
0 0 * * 7end of range (7) above maximum (6): 7Write Sunday as 0 or sun.
0 0 6 * * *expected exactly 5 fields, found 6: [0 0 6 * * *]Drop the seconds field (a Quartz or Spring habit).
0 9 L * *failed to parse int from L: strconv.Atoi: parsing "L": invalid syntaxThere is no L, W or #; see the last-day workaround below.
0 24 * * *end of range (24) above maximum (23): 24Hours run 0–23; midnight is 0.
CRON_TZ=Europe/Berlin 0 9 * * *cannot use TZ or CRON_TZ in schedule, use timeZone field insteadMove the zone to spec.timeZone.
timeZone: LocaltimeZone must be an explicit time zone as defined in https://www.iana.org/time-zonesName the zone, such as America/New_York.
timeZone: Europe/Lodnonunknown time zone Europe/LodnonCheck the spelling against the IANA list; the zone is looked up when you apply.

To check an expression before applying it, paste it into the cron expression explainer: it lists the next runs in any time zone and has a Kubernetes row that flags a 7 for Sunday.

Kubernetes CronJob schedule examples

scheduleRunsUse
0 3 * * 1At 03:00 on Mondays.The docs' example: weekly backup
*/5 * * * *Every 5 minutes.Poll or sync
0 2 * * *At 02:00 every day.Nightly report
30 6 * * mon-friAt 06:30, Monday through Friday.Weekday mornings
0 */6 * * *Every 6 hours from 00:00 through 18:00.Four times a day
0 0 1 * *At 00:00 on the 1st of every month.Monthly cleanup

Every schedule page has a Kubernetes tab with a ready spec excerpt, for example every 5 minutes, every hour and every 2 hours.

Time zones

Without spec.timeZone, the kube-controller-manager reads the schedule in its own local time zone. On a managed cluster you usually can't see or change that, so a job meant for 02:00 can run hours off. The timeZone field, stable since Kubernetes 1.27, takes an IANA name such as Etc/UTC, Europe/London or America/New_York. It's checked when you apply: a misspelled zone or Local is refused, and the binaries carry Go's time zone database as a fallback when the node has none.

Writing TZ= or CRON_TZ= at the start of the schedule was never officially supported, and new or changed CronJobs that do it are rejected. A CronJob that already had one can keep it, but not alongside timeZone.

Daylight saving still applies

In a zone with daylight saving, a schedule inside the hour the clocks skip or repeat (often 01:00–02:59) behaves differently on those two nights a year. Keep important jobs outside that window, or use Etc/UTC.

Stop runs overlapping: concurrencyPolicy

A CronJob starts its Job on time whether or not the previous one has finished. spec.concurrencyPolicy decides what happens when they meet:

PolicyWhen the last Job is still running
AllowThe default. The new Job starts while the old one is still running.
ForbidThe new run is skipped and counted as missed. Once the old Job finishes, a late start is still possible within startingDeadlineSeconds.
ReplaceThe running Job is replaced by the new one.

The policy only compares Jobs from the same CronJob; two CronJobs always run side by side. For a job that must never run twice at once, Forbid is the safe choice. The same problem on a plain server is solved with flock, as shown on every 5 minutes.

Missed runs and startingDeadlineSeconds

spec.startingDeadlineSeconds is how late a Job may start. If the controller can't start it within that many seconds of its scheduled time (it was down, or Forbid held it back), that run is skipped and counted as failed. Unset, there is no deadline. Keep it at 10 seconds or more: the controller checks every 10 seconds, so a shorter deadline can mean the job never starts.

After an outage, the controller doesn't replay every missed time. It starts one Job, for the most recent one. If it counts more than 100 missed times (since the last run, or within startingDeadlineSeconds when that is set), it also records a TooManyMissedTimes warning event: "too many missed start times. Set or decrease .spec.startingDeadlineSeconds or check clock skew". The CronJob keeps running.

Make the job idempotent

Scheduling is approximate: in rare cases Kubernetes creates two Jobs for one time, or none. A job that processes everything outstanding since its last success, rather than "the last 24 hours", copes with both.

Run, pause and inspect a CronJob

To test without waiting for the schedule, create a Job from the CronJob's template. It runs once and doesn't change the schedule:

terminal
# Start a Job from the CronJob's template right now
kubectl create job --from=cronjob/nightly-report nightly-report-manual-1

# Follow it
kubectl logs -f job/nightly-report-manual-1

spec.suspend: true stops new Jobs from starting without deleting anything. When you resume a CronJob that has no startingDeadlineSeconds, a Job for the most recent missed time starts straight away, so set a deadline first if that run would be unwelcome:

terminal
# Pause the schedule (running Jobs carry on)
kubectl patch cronjob nightly-report -p '{"spec":{"suspend":true}}'

# Resume it
kubectl patch cronjob nightly-report -p '{"spec":{"suspend":false}}'

kubectl describe cronjob nightly-report shows the last schedule time and recent events, which is where skipped and missed runs show up. Finished Jobs are cleaned up by successfulJobsHistoryLimit (default 3) and failedJobsHistoryLimit (default 1), and their Pods and logs go with them.

The last day of the month

With no L, schedule the job on days 28–31 and let the container exit early unless tomorrow is the 1st. date -d tomorrow needs GNU date, as in Debian and Ubuntu images. The container runs in UTC unless its image sets a zone, so keep its date and the CronJob's timeZone in step:

cronjob.yaml (excerpt)
schedule: "0 23 28-31 * *"
jobTemplate:
  spec:
    template:
      spec:
        containers:
          - name: month-end
            image: debian:12-slim
            command:
              - /bin/sh
              - -c
              - '[ "$(date -d tomorrow +%d)" = "01" ] && echo month-end job || true'

Kubernetes CronJob not running? Check these

What you seeCauseFix
kubectl apply fails with “Invalid value” on spec.scheduleThe parser rejected the expression: a 7 for Sunday, six fields, L or #, or TZ= in the schedule.Match the message to the table above, or paste the schedule into the explainer, whose Kubernetes row flags the same problems.
It runs, but hours offNo timeZone, so the schedule follows the controller manager's zone.Set spec.timeZone and keep the schedule in that zone's local time.
LAST SCHEDULE never changessuspend: true, or startingDeadlineSeconds under 10: the controller checks every 10 seconds, so a shorter deadline can miss every start.Check kubectl get cronjob for SUSPEND, and use a deadline of a minute or more.
Some runs are skippedconcurrencyPolicy: Forbid with a Job that outlasts the interval, or a start later than startingDeadlineSeconds.Shorten the job, widen the schedule, or raise the deadline.
Event: “too many missed start times”More than 100 schedule times were missed, often after controller downtime or clock skew. One Job still starts, for the latest time.Set startingDeadlineSeconds, so only misses inside that window are counted.
Jobs run, but no Pods or logs are left to readHistory limits removed them: 3 successful and 1 failed Job are kept by default, and 0 keeps none.Raise successfulJobsHistoryLimit or failedJobsHistoryLimit.
The CronJob can't be created: name too longThe controller adds 11 characters to the name, and a Job name can't pass 63, so a CronJob name can be at most 52.Shorten metadata.name, ideally to a DNS label (lowercase letters, digits and hyphens).

Need the field-by-field basics first? See the cron expression syntax guide.