Skip to content

CronJobs: Automated Scheduled Tasks

A CronJob creates Jobs on a repeating schedule using standard crontab expressions.


apiVersion: batch/v1
kind: CronJob
metadata:
name: nightly-database-backup
spec:
schedule: "0 2 * * *" # Every day at 02:00 AM UTC
concurrencyPolicy: Forbid
successfulJobsHistoryLimit: 3
failedJobsHistoryLimit: 1
jobTemplate:
spec:
template:
spec:
restartPolicy: OnFailure
containers:
- name: db-backup
image: postgres:15-alpine
command: ["/bin/sh", "-c", "pg_dumpall -h db.prod > /backups/dump.sql"]
  • Allow (default): Concurrent jobs are allowed to run concurrently.
  • Forbid: If a previous job is still running, the new scheduled run is skipped.
  • Replace: Cancels the currently running job and starts a new one.