CronJob
What is CronJob?
CronJob: Creates Jobs on a cron schedule. The Kubernetes equivalent of crontab — for backups, reports, and periodic cleanup. A CronJob in Kubernetes runs a task on a schedule, like the classic crontab on Linux servers. It creates a Job at the set times, such as 0 3 * * * for every night at three.
Frequently asked questions about CronJob
How is CronJob used in practice?
Typical uses are backups, report generation, cleaning up old data and syncing with external systems. Each run gets its own pod, which starts, does its work and stops.
What should you keep in mind with CronJob?
Set concurrencyPolicy: Forbid if two runs must never overlap, for example a backup that takes longer than expected. Keep a few finished jobs with successfulJobsHistoryLimit so you can read their logs. And monitor them. A CronJob that silently fails every night looks exactly like one that works, until the day you need that backup.
What does an example of CronJob look like?
apiVersion: batch/v1 kind: CronJob metadata: name: nightly-backup spec: schedule: "0 2 * * *" jobTemplate: spec: template: spec: restartPolicy: OnFailure containers: - name: backup image: backup-tool:2.0 At a glance
| Category | Kubernetes |
|---|---|
| Explained by | Reinier de la Parra |
| Updated |