Appearance

DaemonSets, Jobs, and CronJobs

Choose between a system agent on each node, a one-off task, and a scheduled batch task.

What you will understand

  • Explain how a DaemonSet responds when an eligible node joins the cluster.
  • Read Job completion, retry, and deadline behavior.
  • Explain how CronJob timing and concurrency affect the application code.

Builds on: StatefulSets and stable identity

Match the controller to the work

A cluster needs a log collector on every worker, a report generated once today, and a fresh report every morning. Each is a workload, but success means something different for each.

A DaemonSet aims to run a Pod on every eligible node, or on a subset selected by labels and other constraints. A log collector often needs one copy per node because it reads that node’s logs. When a new eligible node joins, the DaemonSet controller creates a Pod for it. Use the node coverage scene to see why adding a node can create a new Pod even though no replica number was edited.

Why does adding a worker add a collector Pod?

A DaemonSet’s target is the set of eligible nodes, so a newly eligible worker gets an instance without a requested replica count change.

  1. Find the eligible nodes

    The controller applies node selection and placement rules; the control node is excluded in this example.

  2. Run one collector on each

    Agent A is assigned to Worker A. Its purpose is coverage of that node rather than satisfying a generic replica count.

  3. Add a new eligible worker

    Worker B joins with matching labels and acceptable taints, creating another node that needs coverage.

  4. Start its collector

    Agent B runs on Worker B and consumes that worker resources. Requests and permissions still matter for infrastructure agents.

One agent Pod per eligible worker in steady state; update surge and transient overlap are omitted.

Run one report to completion

A Job runs a task to completion. It creates Pods, tracks their successful completions, and can retry failures within its policy. The following Job runs a command, writes a timestamp and marker, then exits successfully. restartPolicy: Never lets you see separate Pods for retry attempts. backoffLimit bounds retries, activeDeadlineSeconds bounds the Job’s running time, and the TTL cleans up finished work after 600 seconds. For a real report, store the output where it will still be available after the Pod is gone.

apiVersion: batch/v1
kind: Job
metadata:
  name: report-once
spec:
  backoffLimit: 2              # Bound retry attempts after failures.
  activeDeadlineSeconds: 120   # Bound total running time.
  ttlSecondsAfterFinished: 600 # Clean up later; export needed evidence first.
  template:
    spec:
      restartPolicy: Never
      containers:
        - name: report
          image: busybox:1.36
          command: ["sh", "-c", "date -u; echo report-complete"]

Follow a scheduled task through retries

A CronJob creates Jobs on its schedule. A Job tracks completion and may retry a failed attempt until its policy stops it.

  1. CronJob triggers a run

    The CronJob evaluates its schedule and concurrency policy, then creates a Job for an eligible run.

  2. Job starts the first attempt

    The Job starts a Pod. It may produce an external side effect before its final exit status is known.

  3. A failed attempt can be retried

    A failure within backoffLimit can create another attempt. The controller does not know whether the previous external write was committed.

  4. Successful completion records the result

    The second attempt uses the same business work key so the destination can deduplicate the result, then Job completion is recorded.

One CronJob and finite work; no exactly-once business guarantee.

Check Job results and node coverage

Save the file as report-once.yaml. Compare the Job’s completion status with the Pod’s phase and read the output. Then list a DaemonSet already in the cluster and compare its assigned Pods with eligible nodes. For an exercise that uses both ownership and workload status, use the workload management lab.

kubectl apply -f report-once.yaml
kubectl get jobs,pods
kubectl logs job/report-once
kubectl describe job report-once
# Inspect node-local coverage where the cluster already has DaemonSets.
kubectl get daemonsets -A
kubectl get pods -A -o wide

Plan for missed or overlapping scheduled runs

A CronJob creates Jobs according to a schedule. If a new run comes due while the previous one is active, Allow permits overlap, Forbid skips a concurrent run, and Replace replaces the active Job with a new one. These policies apply to Jobs created by the same CronJob. Check the time zone used for the schedule and decide how late a missed run may start.

A CronJob can miss a run or create more than one Job for a scheduled time in some conditions. Job retries can also repeat work after a partial failure. Make the task safe to repeat. One report generator might write to a path keyed by the report’s date and replace the completed file atomically after a successful run.

Check your understanding

A daily report usually takes 10 minutes but sometimes runs past the next scheduled time. What does Forbid protect, and what do you still need to handle?

It prevents the same CronJob from starting an overlapping run. That can mean skipping a report at its scheduled time. The report code still needs to handle retries and partial results safely, and the operator needs a way to see missing outputs.

Primary documentation

Go to the source

Reviewed 2026-10-27 · Kubernetes 1.37 · Related local exercise

Search the book

Search loads when you open it.

Keyboard shortcuts

Ctrl + K / ⌘ + K
Search the book
?
Open this guide
Tab / Shift + Tab
Move between controls
Enter / Space
Activate a focused button or disclosure
← / →
Focused visual timeline · previous or next step
Home / End
Focused visual timeline · first or last point
Esc
Close the open dialog or menu