Kubernetes CronJobs: Complete Scheduling Guide

Spec, concurrency policies, timezones, retries, and best practices for scheduling with Kubernetes CronJobs.

12 min read
Kubernetes CronJobs: Complete Scheduling Guide

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: OnFailure

Concurrency & History Policies

  • concurrencyPolicy: Allow | Forbid | Replace
  • successfulJobsHistoryLimit & 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 Forbid or Replace to avoid overlapping jobs
  • Log to stdout/stderr for centralized collection
  • Tag images immutably and pin versions
  • Add readiness checks to pre-validate dependencies

Ready to Create Your Cron Job?

Now that you understand the concepts, try our cron expression generator to create your own cron jobs!

Try Cron Generator