CronJob scheduling
A recurring task
A Job is a finite execution. A CronJob is a schedule that creates Jobs; it is not a process running inside a Pod. A bookstore might produce a summary at the start of each hour. The CronJob controller observes the schedule and creates Jobs as appropriate. The Job controller then manages Pods. Treat scheduled time, actual start, completion and report correctness as separate observations.
Read the schedule
The five cron fields are minute, hour, day of month, month and day of week. The expression 0 * * * * selects minute zero of each hour. Quoting the expression avoids YAML interpretation problems. Etc/UTC makes the schedule explicit instead of relying on the controller local time zone; the timeZone field is stable from v1.27. Put the time zone in the dedicated field, not inside the cron expression. This offline example is deliberately suspended and uses an invalid registry hostname. The nested Job template sets its own three-minute active deadline.
apiVersion: batch/v1kind: CronJobmetadata: name: catalog-summary namespace: batch-studyspec: schedule: "0 * * * *" timeZone: Etc/UTC suspend: true concurrencyPolicy: Forbid startingDeadlineSeconds: 600 successfulJobsHistoryLimit: 2 failedJobsHistoryLimit: 1 jobTemplate: spec: backoffLimit: 2 activeDeadlineSeconds: 180 ttlSecondsAfterFinished: 7200 template: spec: restartPolicy: Never automountServiceAccountToken: false securityContext: runAsNonRoot: true runAsUser: 10001 seccompProfile: type: RuntimeDefault containers: - name: summary image: example.invalid/bytemind/report:offline command: ["python3", "-c"] args: ['print("catalog items=3")'] securityContext: allowPrivilegeEscalation: false readOnlyRootFilesystem: true capabilities: drop: ["ALL"] resources: requests: cpu: 25m memory: 32Mi limits: cpu: 100m memory: 64MiDecide what happens on overlap
Imagine a separate task scheduled for 10:00 UTC while its previous Job still runs. Allow permits concurrent Jobs from this CronJob. Forbid avoids starting another while the previous Job is active; a skipped occurrence might become eligible after that Job finishes if the start window still permits it. Replace asks the controller to replace the old execution with a new one; termination is not instantaneous or an atomic transaction. These settings coordinate Jobs belonging to one CronJob, not other schedules or manually launched Jobs. Use a stable business key regardless of policy.
Missed starts versus runtime limits
The starting deadline bounds acceptable lateness for creating a scheduled Job, not its execution duration. With 600 seconds allowed, observation at 10:07 is within the window; at 10:11 it is outside. An eligible occurrence is not a guarantee of creation: suspension, overlap, controller state and API failures also matter. The controller has a periodic check, so very small deadlines may miss starts. Excessive missed occurrences can prevent catch-up; official docs describe a threshold above 100. Do not assume every missed occurrence is automatically replayed. A created Job has its own active deadline and failure policy.
Pause, resume and retain evidence
Setting suspend true prevents future scheduled creation; it does not stop Jobs already running. A resumed schedule can process missed occurrences subject to its start window and controller rules. Review that window before enabling a schedule. Successful and failed history limits retain counts of finished Jobs, while TTL is time-based; either cleanup mechanism can make old objects disappear. The example asks for two successful and one failed history entries and a two-hour Job TTL. Keep needed evidence elsewhere, with retention and access controls.
Diagnose a missing report
First check whether the CronJob was suspended and whether the intended schedule and time zone match. Compare scheduled and observed times, check active Jobs, events and any created Job conditions. Then examine Pod logs and the synthetic report output. On modern releases starting with v1.32, created Jobs have a scheduled timestamp annotation which can help distinguish intended time from creation time. No exact-once schedule guarantee exists: duplicate or missed creation can occur. The following commands are static, require a separately approved lab and were not run.
kubectl --context bytemind-lab -n batch-study get cronjob catalog-summarykubectl --context bytemind-lab -n batch-study describe cronjob catalog-summarykubectl --context bytemind-lab -n batch-study get jobsPractice
Use schedule-cases.json to classify individual occurrences as eligible, expired, suspended, deferred or replacement intent. This is a simplified reasoning model, not the real controller. Explain why Forbid does not replace durable duplicate protection. The next chapter introduces workloads whose containers cooperate inside a Pod.
Documentation for further reading: https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/ and https://kubernetes.io/docs/reference/kubernetes-api/batch/cron-job-v1/. Examples are static; actual cluster behavior is not tested.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
CronJob scheduling — knowledge check
Apply the chapter concepts using synthetic offline scenarios.
A summary should run on the hour in UTC. Which configuration is suitable?
A prior Job from the same CronJob is still active and policy is Forbid. What happens to the new occurrence?
A 09:00 occurrence is observed at 09:12 with startingDeadlineSeconds 600. What follows?
A CronJob is suspended while a Job is active. What does suspension alone do?
Two separate CronJobs write the same business report. Both use Forbid. What else is needed?