Kubernetes CronJob is a Kubernetes API object that creates Jobs on a schedule. In practical terms, it lets you run recurring tasks inside your cluster, such as database backups, report generation, cache cleanup, certificate checks, or batch imports.
A CronJob automates work that needs to run at specific times or intervals. It uses cron-style scheduling, similar to Linux cron, but runs the task as a Kubernetes Job.
Common examples include:
A CronJob does not run containers directly. Instead, the Kubernetes CronJob controller creates a Job whenever the schedule matches. That Job then creates one or more Pods to perform the actual work.
The flow looks like this:
This example runs a container every day at 02:00 UTC:
apiVersion: batch/v1
kind: CronJob
metadata:
name: daily-cleanup
spec:
schedule: "0 2 * * *"
jobTemplate:
spec:
template:
spec:
restartPolicy: OnFailure
containers:
- name: cleanup
image: busybox:1.36
command:
- /bin/sh
- -c
- echo "Running cleanup job"
The schedule field uses standard cron format:
# ββββββββββββββ minute: 0-59
# β ββββββββββββ hour: 0-23
# β β ββββββββββ day of month: 1-31
# β β β ββββββββ month: 1-12
# β β β β ββββββ day of week: 0-6, Sunday to Saturday
# β β β β β
# * * * * *
schedule: Defines when the CronJob runs, using cron syntax.jobTemplate: Defines the Job that Kubernetes creates on each scheduled run.concurrencyPolicy: Controls what happens if a previous Job is still running when the next one is due.suspend: Temporarily pauses future runs without deleting the CronJob.startingDeadlineSeconds: Sets how long Kubernetes can wait to start a missed run.successfulJobsHistoryLimit: Controls how many completed Jobs Kubernetes keeps.failedJobsHistoryLimit: Controls how many failed Jobs Kubernetes keeps for troubleshooting.timeZone: Sets the time zone for the schedule, if supported by your Kubernetes version.The concurrencyPolicy field is important for production workloads. It controls overlapping runs:
Allow: Allows multiple Jobs to run at the same time. This is the default.Forbid: Skips a new run if the previous one is still running.Replace: Stops the currently running Job and starts a new one.For example, use Forbid for a database backup job if two backups running at once could overload the database or corrupt output files.
Use a CronJob for scheduled, finite work. Use a Job for one-time batch work. Use a Deployment for services that should stay running continuously.
CronJobs are simple to create, but they still need production controls:
Teams usually define CronJobs in YAML and manage them through GitOps, Helm, Kustomize, or Terraform. If your team manages cluster objects through infrastructure as code, you can also deploy Kubernetes resources using Terraform.
Keep CronJob definitions versioned with the application or platform code. This makes schedule changes reviewable and easier to roll back.
A Kubernetes CronJob works well for simple scheduled tasks. It is usually not the best fit for complex workflow orchestration.
Consider a workflow engine such as Apache Airflow when you need:
For data platforms running on Kubernetes, teams often compare CronJobs with tools like Apache Airflow on Amazon EKS when scheduled work becomes more complex.
CronJob behavior can depend on your Kubernetes version, especially around controller behavior and fields such as timeZone. If you run many scheduled production tasks, include CronJobs in your test plan when preparing Kubernetes upgrades.
Suppose your SaaS product stores temporary export files in an object storage bucket. You can create a CronJob that runs every hour, lists files older than 24 hours, deletes them, and exits. The task does not need a long-running service, so a CronJob is a good fit.
In production, you would also add:
Forbid concurrency policy if overlapping cleanup runs are riskyA Kubernetes CronJob schedules recurring work inside a cluster by creating Jobs at defined times. It is useful for backups, cleanup, reports, imports, and other finite tasks that run on a schedule. For reliable production use, set clear retry behavior, resource limits, concurrency rules, logging, and alerting.