What Is a Kubernetes CronJob? Handle Schedule Timing, Duplicates, and Missed Runs
A CronJob is a Kubernetes resource that repeatedly creates Jobs from a cron schedule. It decides when work should start; each Job manages its Pods and retries. Scheduling is approximate, so a run may be created more than once or not at all. Make scheduled work safe to repeat.
Schedule and timezone
.spec.schedule uses five cron fields—minute, hour, day of month, month, and day of week—and also accepts aliases such as @daily. 0 2 * * * means 02:00 every day in the selected timezone. Without .spec.timeZone, the controller uses its local timezone. Set an IANA name such as Asia/Seoul or Etc/UTC; the field has been stable since Kubernetes 1.27. Do not put TZ= or CRON_TZ= inside the schedule.
Example: daily cleanup at 02:00
This creates a Job at 02:00 Seoul time in namespace batch. If the previous Job is still running, the next run is skipped; a run delayed by more than one hour is considered missed. Prepare the namespace and replace the example image and command with approved application values. This example was not run against a cluster and does not delete real data.
apiVersion: batch/v1
kind: CronJob
metadata:
name: daily-cleanup
namespace: batch
spec:
schedule: "0 2 * * *"
timeZone: Asia/Seoul
concurrencyPolicy: Forbid
startingDeadlineSeconds: 3600
successfulJobsHistoryLimit: 3
failedJobsHistoryLimit: 2
jobTemplate:
spec:
backoffLimit: 2
activeDeadlineSeconds: 1800
ttlSecondsAfterFinished: 86400
template:
metadata:
labels:
app: daily-cleanup
spec:
restartPolicy: Never
containers:
- name: cleanup
image: registry.example.com/team/cleanup:<approved-tag-or-digest>
command: ["/app/cleanup", "--date", "previous-day"].spec.jobTemplate applies to newly created Jobs; changing it does not alter Jobs already running. In the example, backoffLimit: 2 limits failed-Pod retries and activeDeadlineSeconds: 1800 limits total Job runtime. Forbid only applies to Jobs from the same CronJob. It skips an overlapping run; it does not queue every missed run for later replay.
Choose concurrency and missed-run behavior
| Policy | Behavior | Use when |
|---|---|---|
Allow (default) | Starts a new Job even if the prior one is active | Parallel runs are safe and capacity is available |
Forbid | Skips a run while the prior Job is active | Two runs must not overlap |
Replace | Terminates the prior Job and starts the new one | New work takes priority and interruption is safe |
These policies cannot provide exactly-once execution. Control-plane disruptions or schedule boundaries can result in zero or multiple Jobs for a scheduled time. Use a unique run key or transaction for database updates; for files, consider writing to a temporary path and renaming atomically. With Replace, account for Pod shutdown and partial output.
.spec.startingDeadlineSeconds sets how late a missed run may start. Once the deadline passes, that run is skipped and later schedules continue. If omitted, there is no deadline, but Kubernetes will not revive an unlimited backlog. If over 100 schedule times are missed, the controller reports an event and may create no Job. The controller checks about every 10 seconds, so a deadline shorter than 10 seconds may prevent a Job from starting.
Setting .spec.suspend: true stops future Job creation but does not stop Jobs already started. Schedules missed while suspended are counted as missed. When resuming without a starting deadline, the latest missed run may start immediately; check for duplicate effects after a long pause.
Apply and verify
These are examples, not commands run against a cluster. Check the current context, namespace, timezone support, image access, permissions, and expected runtime first.
kubectl config current-context
kubectl apply -f <cronjob.yaml>
kubectl get cronjob daily-cleanup -n batch
kubectl describe cronjob daily-cleanup -n batch
kubectl get jobs -n batch --sort-by=.metadata.creationTimestamp
kubectl get pods -n batch -l app=daily-cleanupCheck LAST SCHEDULE and ACTIVE; inspect a created Job with kubectl describe job <job-name> -n batch. If no Job appears, check schedule syntax, timezone, deadline, suspension, and controller events. For Pending, check quota, node capacity, and scheduling constraints. For ImagePullBackOff, check the image and registry credentials. For repeated failures, inspect events and logs with kubectl logs job/<job-name> -n batch.
Retain execution evidence
By default, CronJob retains three successful Jobs and one failed Job. Set successfulJobsHistoryLimit and failedJobsHistoryLimit to change these counts. A value of 0 removes finished Jobs of that type, so export status and logs first if needed for diagnosis. ttlSecondsAfterFinished also schedules cleanup of a finished Job and its dependent Pods. Coordinate both retention settings so evidence does not disappear too soon.
Keep CronJob names at 52 characters or fewer because Kubernetes appends a suffix when creating Jobs. A CronJob creates scheduled Jobs; it does not verify backup consistency, recoverability, or report accuracy. Check the result of the actual task and prepare a safe retry procedure.
Sources
[Kubernetes CronJob concepts and configuration](https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/)
[Kubernetes Job retries and completion](https://kubernetes.io/docs/concepts/workloads/controllers/job/)
[Automatic cleanup for finished Jobs](https://kubernetes.io/docs/concepts/workloads/controllers/ttlafterfinished/)
[Pod lifecycle and termination](https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/)
[Running automated tasks with a CronJob](https://kubernetes.io/docs/tasks/job/automated-tasks-with-cron-jobs/)
Scope: schedules and timezones, concurrency, missed and suspended runs, retention, and diagnosis. Kubernetes official documentation reviewed on 2026-11-23. The manifest and commands are examples and were not run in a cluster. Backup consistency and recovery procedures for a specific tool are outside scope.