Interview's MateKubernetes
Interview's Mate

Kubernetes

K8s · Workloads · GitOps · Cloud

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
Kubernetes topics
Lesson 30/ 160
02. Workload Controllers & Scaling

CronJobs: Scheduled Recurring Tasks & Concurrency Policies

Schedule recurring Jobs and choose Forbid, Allow, or Replace concurrency.

IntermediateCronJob · Schedule · Concurrency3 quiz questions
Practice DevOps Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

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-now and 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

Loading interactive 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.

Verify Schedule, not only object creation

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.

Key takeaway: CronJob is implemented only when this invariant remains observable: 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.

Recover from Schedule drift

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.

Key takeaway: Accept the trade-off consciously: Forbid prevents overlap but can skip work, Replace guarantees a fresh attempt but can interrupt a legitimate long run, and Allow demands idempotent concurrency.

How it works, step by step

Step 1 of 4
Workload author

1. 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.

CronJob contract → owned state
Key numbers at this step
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-now in 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-now first: 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

Controller-managed workload
Best for: Schedule recurring Jobs and choose Forbid, Allow, or Replace concurrency. A concrete incident check is 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.

Hand-managed Pods
Best for: Quickly testing the Schedule assumption with 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.

Progressive-delivery layer
Best for: Teams that need Concurrency integrated with guardrails; the evidence path is 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-now without 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?
Interview tip: Interview sequence: state the invariant, run 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

Loading quiz

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.

Open DevOps Q&A →Tech Learn Q&A
Previous topic
Job Parallelism, Completions, backoffLimit & TTL After Finished
Next topic
Horizontal Pod Autoscaler (HPA) & Metrics Server