Use CronJob resources to run batch workloads on a schedule in Kubernetes clusters. Understand spec fields, concurrency policy, history limits, timezones, and retries.
Introduction
Kubernetes CronJobs create Jobs on a cron schedule. They are ideal for recurring tasks like database backups, report generation, or cleanup jobs.
CronJob Spec Basics
apiVersion: batch/v1 kind: CronJob metadata: name: report-generator spec: schedule: "0 2 * * *" jobTemplate: spec: template: spec: containers: - name: report image: myrepo/report:latest args: ["/app/generate-report.sh"] restartPolicy: OnFailureConcurrency & History Policies
concurrencyPolicy:Allow|Forbid|ReplacesuccessfulJobsHistoryLimit&failedJobsHistoryLimit- Set resource requests/limits to avoid cluster overload
Timezones & DST
Kubernetes relies on node time settings. Prefer UTC schedules for predictability. Use the Timezone Converter to preview runs in different regions.
Retries & Backoff
Configure backoffLimit on Jobs and add retry logic within your workload for transient failures.
Best Practices
- Use
ForbidorReplaceto avoid overlapping jobs - Log to stdout/stderr for centralized collection
- Tag images immutably and pin versions
- Add readiness checks to pre-validate dependencies