CronJobs: Scheduled Recurring Tasks & Concurrency Policies
Schedule recurring Jobs and choose Forbid, Allow, or Replace concurrency.
In plain words
A CronJob is a train timetable that decides whether an overdue train, the next train, or all trains may occupy the platform. The simple Kubernetes rule is: CronJobs create Jobs from a five-field schedule and apply Allow, Forbid, or Replace when an earlier run still exists.
Think of it like…
A CronJob is a train timetable that decides whether an overdue train, the next train, or all trains may occupy the platform.
Where you’ve seen it
During a release or scale event, the workload owner runs kubectl get cronjob reports -o yaml; kubectl create job --from=cronjob/reports reports-now. Expected evidence: CronJobs create Jobs from a five-field schedule and apply Allow, Forbid, or Replace when an earlier run still exists. If the run instead shows this symptom, stop and restore the last known state: Daylight-saving or time-zone changes, an unschedulable node, or too many missed schedules can create a delayed Job burst.
Words you’ll hear
- CronJob
- For this lesson, CronJob is the controlling idea: CronJobs create Jobs from a five-field schedule and apply Allow, Forbid, or Replace when an earlier run still exists.
- Schedule
- Schedule is the checkpoint; run
kubectl get cronjob reports -o yaml; kubectl create job --from=cronjob/reports reports-nowand inspect the owner chain. Daylight-saving or time-zone changes, an unschedulable node, or too many missed schedules can create a delayed Job burst. - Concurrency
- Concurrency is the outcome to preserve; the cost is explicit: Forbid prevents overlap but can skip work, Replace guarantees a fresh attempt but can interrupt a legitimate long run, and Allow demands idempotent concurrency.
- Verification evidence
- The evidence command is
kubectl get cronjob reports -o yaml; kubectl create job --from=cronjob/reports reports-now. It connects the declaration to this behavior: Schedule recurring Jobs and choose Forbid, Allow, or Replace concurrency.
Visual diagram
Theory & deep dive
How CronJob reaches the intended state
Schedule recurring Jobs and choose Forbid, Allow, or Replace concurrency. CronJobs create Jobs from a five-field schedule and apply Allow, Forbid, or Replace when an earlier run still exists.
The concrete checkpoint is kubectl get cronjob reports -o yaml; kubectl create job --from=cronjob/reports reports-now; compare the CronJob owner, Schedule state, and Concurrency outcome instead of treating YAML acceptance as proof.
Run kubectl get cronjob reports -o yaml; kubectl create job --from=cronjob/reports reports-now after the change and correlate the result with Events and the owning object. CronJobs create Jobs from a five-field schedule and apply Allow, Forbid, or Replace when an earlier run still exists.
Schedule: failure boundary and production cost
Daylight-saving or time-zone changes, an unschedulable node, or too many missed schedules can create a delayed Job burst. The prerequisite contract is concrete: CronJobs create Jobs from a five-field schedule and apply Allow, Forbid, or Replace when an earlier run still exists.
Forbid prevents overlap but can skip work, Replace guarantees a fresh attempt but can interrupt a legitimate long run, and Allow demands idempotent concurrency. A safe design limits blast radius, records the last good configuration, and uses kubectl get cronjob reports -o yaml; kubectl create job --from=cronjob/reports reports-now as a deterministic rollback checkpoint.
Capture the current state with kubectl get cronjob reports -o yaml; kubectl create job --from=cronjob/reports reports-now, then correct the controlling manifest rather than patching a child object; the relevant divergence signal is specific: Daylight-saving or time-zone changes, an unschedulable node, or too many missed schedules can create a delayed Job burst.
How it works, step by step
Step 1 of 41. Declare workload intent
Write the controller-owned Pod or scaling intent and preserve the owner chain: CronJobs create Jobs from a five-field schedule and apply Allow, Forbid, or Replace when an earlier run still exists.
- Goal
- Schedule recurring Jobs and choose Forbid, Allow, or Replace concurrency.
- Owner
- CronJob
When to use it & trade-offs
What it is
Schedule recurring Jobs and choose Forbid, Allow, or Replace concurrency. CronJobs create Jobs from a five-field schedule and apply Allow, Forbid, or Replace when an earlier run still exists.
Why it matters: Daylight-saving or time-zone changes, an unschedulable node, or too many missed schedules can create a delayed Job burst. The invariant at risk is specific: CronJobs create Jobs from a five-field schedule and apply Allow, Forbid, or Replace when an earlier run still exists. The quickest fact check before changing the design is kubectl get cronjob reports -o yaml; kubectl create job --from=cronjob/reports reports-now.
When to reach for it
- Use CronJob to enforce this invariant: CronJobs create Jobs from a five-field schedule and apply Allow, Forbid, or Replace when an earlier run still exists.
- Use Schedule evidence from
kubectl get cronjob reports -o yaml; kubectl create job --from=cronjob/reports reports-nowin reviews and incident timelines. Schedule recurring Jobs and choose Forbid, Allow, or Replace concurrency. - Choose the progressive-delivery layer route only when this cost is justified by governance or scale: Forbid prevents overlap but can skip work, Replace guarantees a fresh attempt but can interrupt a legitimate long run, and Allow demands idempotent concurrency.
When to avoid or be careful
- Avoid assuming CronJob is complete after YAML submission; the required behavior is concrete: CronJobs create Jobs from a five-field schedule and apply Allow, Forbid, or Replace when an earlier run still exists.
- Avoid treating the next symptom as random; check the owner and state with
kubectl get cronjob reports -o yaml; kubectl create job --from=cronjob/reports reports-nowfirst: Daylight-saving or time-zone changes, an unschedulable node, or too many missed schedules can create a delayed Job burst. - Avoid adopting a heavier platform wrapper before measuring its cost: Forbid prevents overlap but can skip work, Replace guarantees a fresh attempt but can interrupt a legitimate long run, and Allow demands idempotent concurrency.
Native, manual, and managed paths for CronJob
kubectl get cronjob reports -o yaml; kubectl create job --from=cronjob/reports reports-now.Strengths: CronJobs create Jobs from a five-field schedule and apply Allow, Forbid, or Replace when an earlier run still exists.
Watch out: Forbid prevents overlap but can skip work, Replace guarantees a fresh attempt but can interrupt a legitimate long run, and Allow demands idempotent concurrency. Recovery must also recognize this signal: Daylight-saving or time-zone changes, an unschedulable node, or too many missed schedules can create a delayed Job burst.
kubectl get cronjob reports -o yaml; kubectl create job --from=cronjob/reports reports-now; the expected invariant is: CronJobs create Jobs from a five-field schedule and apply Allow, Forbid, or Replace when an earlier run still exists.Strengths: kubectl get cronjob reports -o yaml; kubectl create job --from=cronjob/reports reports-now gives immediate feedback without first building a platform layer.
Watch out: A manual change can hide drift, and unlike CronJob, it does not make this symptom self-documenting: Daylight-saving or time-zone changes, an unschedulable node, or too many missed schedules can create a delayed Job burst.
kubectl get cronjob reports -o yaml; kubectl create job --from=cronjob/reports reports-now.Strengths: Platform controls can wrap this exact behavior in policy or dashboards: CronJobs create Jobs from a five-field schedule and apply Allow, Forbid, or Replace when an earlier run still exists.
Watch out: The added platform ownership buys value at this cost: Forbid prevents overlap but can skip work, Replace guarantees a fresh attempt but can interrupt a legitimate long run, and Allow demands idempotent concurrency.
Interview signals & numbers to know
When this topic comes up
- Interview anchor: CronJobs create Jobs from a five-field schedule and apply Allow, Forbid, or Replace when an earlier run still exists.
- Trace CronJob to Concurrency through Schedule; the invariant is: CronJobs create Jobs from a five-field schedule and apply Allow, Forbid, or Replace when an earlier run still exists.
- Recognize the symptom: Daylight-saving or time-zone changes, an unschedulable node, or too many missed schedules can create a delayed Job burst.
- Justify the cost: Forbid prevents overlap but can skip work, Replace guarantees a fresh attempt but can interrupt a legitimate long run, and Allow demands idempotent concurrency.
- Verify with kubectl get cronjob reports -o yaml; kubectl create job --from=cronjob/reports reports-now instead of only inspecting YAML.
Benchmarks & rules of thumb
- 5
- schedule fields: minute, hour, day of month, month, and weekday
- 3
- concurrency policies: Allow, Forbid, and Replace
- 3
- default successful Jobs retained when successfulJobsHistoryLimit is unset
Common mistakes & follow-ups
Common interview mistakes
- Debugging only the child object misses the CronJob owner contract: CronJobs create Jobs from a five-field schedule and apply Allow, Forbid, or Replace when an earlier run still exists.
- Ignoring this telltale condition leads to unrelated changes: Daylight-saving or time-zone changes, an unschedulable node, or too many missed schedules can create a delayed Job burst.
- Repeating
kubectl get cronjob reports -o yaml; kubectl create job --from=cronjob/reports reports-nowwithout an owner for remediation wastes retry cost. Forbid prevents overlap but can skip work, Replace guarantees a fresh attempt but can interrupt a legitimate long run, and Allow demands idempotent concurrency.
Likely interviewer follow-ups
- How would API output and runtime evidence prove this behavior: CronJobs create Jobs from a five-field schedule and apply Allow, Forbid, or Replace when an earlier run still exists?
- Which owner object, logs, and Events would you inspect for this symptom-Daylight-saving or time-zone changes, an unschedulable node, or too many missed schedules can create a delayed Job burst-?
- At what threshold would this cost become unacceptable: Forbid prevents overlap but can skip work, Replace guarantees a fresh attempt but can interrupt a legitimate long run, and Allow demands idempotent concurrency?
kubectl get cronjob reports -o yaml; kubectl create job --from=cronjob/reports reports-now, name the failure, then justify the cost. Invariant: CronJobs create Jobs from a five-field schedule and apply Allow, Forbid, or Replace when an earlier run still exists. Failure: Daylight-saving or time-zone changes, an unschedulable node, or too many missed schedules can create a delayed Job burst. Cost: Forbid prevents overlap but can skip work, Replace guarantees a fresh attempt but can interrupt a legitimate long run, and Allow demands idempotent concurrency.Knowledge check
Put it into practice
Practice related interview Q&A
Apply CronJobs: Scheduled Recurring Tasks & Concurrency Policies with generative AI interview Q&A and hands-on practice.