CKA Day 12 — Kubernetes DaemonSet, Job & CronJob Explained
Day 12 of the 40-day CKA full course by Tech Tutorials with Piyush. Duration: 19:30. Focus: three specialized workload controllers that handle node-local services, one-off tasks, and scheduled batch execution.
Synthesis
This video introduces three workload primitives beyond the standard Deployment: DaemonSet, Job, and CronJob. While Deployments are designed for stateless, horizontally scalable applications, these three controllers cover edge cases that are equally critical in production: running exactly one Pod per node, running a task to completion exactly once, and running a task on a schedule.
DaemonSet
A DaemonSet ensures that a copy of a Pod runs on every node (or a subset of nodes selected by a node selector). When a new node joins the cluster, the DaemonSet automatically schedules a Pod on it. When a node leaves, the Pod is garbage collected. Unlike a Deployment, which spreads replicas across nodes for high availability, a DaemonSet is one-to-one with nodes by design.
Canonical use cases:
- Node monitoring agents (Prometheus Node Exporter, Datadog Agent)
- Log collectors (Fluentd, Fluent Bit, Logstash) that need access to node-level logs
- CNI network plugins (Calico, Cilium, Flannel) that must run on every node to set up networking
- Storage daemons (Ceph OSD, Portworx) that manage local disk
YAML structure is nearly identical to a Deployment, but the kind is DaemonSet and apiVersion is apps/v1. There is no replicas field — the count is implicit (one per eligible node). The selector uses matchLabels just like a ReplicaSet.
Key difference from Deployment: A Deployment scales horizontally across the cluster; a DaemonSet scales vertically across the node axis. You cannot scale a DaemonSet with kubectl scale because the node count itself determines the replica count.
Practical commands:
kubectl get daemonset
kubectl describe daemonset <name>Job
A Job creates one or more Pods and ensures that a specified number of them terminate successfully. It is designed for finite, batch-style workloads that run to completion rather than running indefinitely. When the Pod(s) finish successfully, the Job is marked Complete.
Key properties:
completions: how many successful Pod completions are required (default: 1)parallelism: how many Pods can run concurrently (default: 1)backoffLimit: how many retries before marking the Job as failed (default: 6)activeDeadlineSeconds: maximum time a Job can run before Kubernetes terminates it
Use cases:
- Database migrations and schema updates
- One-off data processing or ETL tasks
- Batch report generation
- CI/CD pipeline steps that run inside the cluster
Restart policy: Jobs require restartPolicy: OnFailure or Never in the Pod template — Always is invalid because the Job controller must detect completion.
Practical commands:
kubectl get jobs
kubectl logs job/<name> # reads logs from the job's pod
kubectl delete job <name> # deletes the job and its podsCronJob
A CronJob wraps a Job with a time-based schedule defined by a cron expression. It is the Kubernetes equivalent of crontab for cluster workloads. The CronJob controller creates a new Job object every time the schedule triggers, which in turn creates a Pod. This means failed executions do not block future scheduled runs because each run is an independent Job.
Key properties:
schedule: standard cron syntax ("*/5 * * * *"for every 5 minutes)startingDeadlineSeconds: grace period for missed starts (e.g., if the controller was down)concurrencyPolicy:Allow(default),Forbid, orReplace— controls whether multiple Jobs from the same CronJob can run simultaneouslysuccessfulJobHistoryLimit/failedJobHistoryLimit: how many completed Job objects to retain (default 3 and 1)suspend: set totrueto pause the schedule without deleting the CronJob
Use cases:
- Scheduled backups (database dumps, etcd snapshots)
- Periodic cleanup tasks (deleting old logs, pruning temp files)
- Recurring report generation (daily, weekly, monthly)
- Health-check probes that run on a timer rather than continuously
Exam tip: The CKA exam may ask you to create a CronJob with a specific schedule. Use kubectl create cronjob with --dry-run=client -o yaml to generate the manifest, then edit the schedule field.
kubectl create cronjob my-cron --image=busybox --schedule="*/5 * * * *" \
--dry-run=client -o yaml > cronjob.yamlComparative Summary
| Controller | Lifetime | Scaling Axis | Use Case | apiVersion |
|---|---|---|---|---|
| Deployment | Indefinite | Horizontal (replicas) | Long-running stateless apps | apps/v1 |
| DaemonSet | Indefinite | Node count (one per node) | Node-local agents, monitoring, networking | apps/v1 |
| Job | Finite (to completion) | Parallelism + completions | One-off batch tasks, migrations | batch/v1 |
| CronJob | Scheduled (finite per run) | Node + time axis | Recurring backups, cleanup, reports | batch/v1 |
CKA Exam Relevance
- Workloads & Scheduling (~15%): Expect tasks to create a DaemonSet, a Job, or a CronJob from a given spec.
- Troubleshooting (~30%): Debug why a Job is stuck (check
restartPolicy,backoffLimit, image pull errors) or why a CronJob missed a schedule (checkstartingDeadlineSecondsand controller health). - Speed patterns:
kubectl create job ... --dry-run=client -o yamlfor quick Job manifestskubectl create cronjob ... --dry-run=client -o yamlfor CronJob templates- Remember that
restartPolicy: Alwaysis invalid inside a Job template
See Also
Wiki Concepts
- Kubernetes DaemonSet — node-level workload controller deep dive
- Kubernetes Jobs — batch execution and completion semantics
- Kubernetes CronJobs — scheduled batch workloads
- Pod Fundamentals — the unit all these controllers manage
- Deployment, ReplicaSet & Replication Controller — the standard long-running workload controller
- Kubernetes Architecture — where kube-proxy and CoreDNS run as DaemonSets/Deployments
- CKA Certification — exam structure and domains
- CKA Study Roadmap — 40-day schedule
Related Sources
- CKA Day 8 — Deployments, ReplicaSets & Replication Controllers — the foundation for workload controllers
- CKA Day 7 — Pod Explained — Pod fundamentals
Creator / Entity
- Tech Tutorials with Piyush — CKA 40-day course creator
Tags: kubernetes daemonset job cronjob cka workload batch scheduling devops