Kubernetes CronJob
5-field cron for `CronJob` resources — same syntax as Vixie cron, plus a `timeZone` spec field since Kubernetes 1.25.
Overview
Kubernetes `CronJob` (`batch/v1`) resources use 5-field cron expressions parsed by the internal `robfig/cron/v3` parser. Syntax matches Vixie cron — step values, named days/months, and `@hourly`-style aliases are supported.
Since Kubernetes 1.25 (stable in 1.27), `spec.timeZone` lets you override the kube-controller-manager's local timezone with an IANA name (e.g. `America/New_York`). Before 1.25 the schedule was always evaluated in the controller-manager's timezone.
Field Structure
Field Order5 fields: minute hour day-of-month month day-of-week
Day-of-Week0 or 7 = Sunday, 1=Monday, …, 6=Saturday.
Special Characters
| Token | Meaning |
|---|---|
| * | Any value. |
| , | List separator. |
| - | Range. |
| / | Step. |
Aliases
- `@yearly`, `@annually`, `@monthly`, `@weekly`, `@daily`, `@midnight`, `@hourly`.
- `@every <duration>` (e.g. `@every 15m`) — robfig extension.
Comparison vs. Unix Cron
| Feature | Kubernetes CronJob | Unix Cron |
|---|---|---|
| Field count | 5 | 5 |
| Seconds field | No (disabled in batch/v1 parser) | No |
| Step syntax | Yes | Limited |
| Named months/days | Yes | No |
| Aliases | Yes (incl. `@every`) | No |
| Timezone control | `spec.timeZone` (1.25+) | Local + `CRON_TZ` |
Examples
Gotchas & Pitfalls
- ⚠Before Kubernetes 1.25, schedules ran in the controller-manager's local timezone — not the cluster timezone or the pod timezone. Always set `spec.timeZone` on modern clusters.
- ⚠`spec.concurrencyPolicy` (`Allow` / `Forbid` / `Replace`) determines what happens when a new run starts while the previous one is still going.
- ⚠`spec.startingDeadlineSeconds` controls how long after the scheduled time Kubernetes will still try to launch the job. If set too short, missed schedules are skipped.
- ⚠Schedule strings must be quoted in YAML: `schedule: "*/5 * * * *"` — without quotes the `*` characters are interpreted as YAML aliases.