Crontab format is the five-field schedule expression used by a CronJob to decide when the CronJob controller creates Jobs. The fields represent minute, hour, day of month, month, and day of week, from left to right. section 18.2 section 18.2.2
Build a schedule by replacing asterisks with values, ranges, lists, or step patterns:
- `* * * * *` runs every minute; `15 * * * *` runs 15 minutes after every hour. section 18.2.2
- `1-5` selects an inclusive range, `1,2,5-8` selects values and ranges, and `*/3` selects every third value. section 18.2.2
- When both day-of-month and day-of-week contain restrictions, either matching field can trigger the schedule; `* * 13 * 5` runs on every 13th and every Friday. section 18.2.2
- Use `@hourly`, `@daily`, `@weekly`, `@monthly`, `@yearly`, or `@annually` for common recurring schedules. section 18.2.2
Run a Job every minute
Set `spec.schedule` to `"* * * * *"` in a `batch/v1` CronJob. The first Job appears when the next minute starts, and `kubectl get cj` reports the schedule and last scheduling time. section 18.2.1
Use a specific time zone
Combine `schedule: "0 3 * * *"` with `timeZone: CET` to schedule the CronJob at 03:00 in the specified time zone. section 18.2.2
Listing 18.17 A CronJob that runs a Job every minute
apiVersion: batch/v1 #1
kind: CronJob #1
metadata:
name: aggregate-responses-every-minute
spec:
schedule: "* * * * *" #2
jobTemplate: #3
metadata: #3
labels: #3
app: aggregate-responses-today #3
spec: #3
template: #3
metadata: #3
labels: #3
app: aggregate-responses-today #3
spec: #3
restartPolicy: OnFailure #3
containers: #3
- name: updater #3
image: mongo:5 #3
command: #3
- mongosh #3
- mongodb+srv://quiz-pods.kiada.svc.cluster.local/kiada?tls=false #3
- --quiet #3
- --file #3
- /script.js #3
volumeMounts: #3
- name: script #3
subPath: script.js #3
mountPath: /script.js #3
volumes: #3
- name: script #3
configMap: #3
name: aggregate-responses-today #3
Inspect the complete CronJob manifest, including the schedule field and Job template. section 18.2.1
