Sub topic 2
When to use a DaemonSet
This chapter assumes you know Pods, labels and selectors, namespaces, and Deployments. It helps you decide when a DaemonSet is the right controller. Later chapters cover the manifest and the placement mechanics in detail.
The deciding question
A Deployment answers "how many copies of this Pod do I need?" A DaemonSet answers "which nodes need a copy?" Choose a DaemonSet when the workload belongs to the node, not to the application's capacity needs.
Three signs point to a DaemonSet:
- The Pod works with something local to the node, such as its logs, its disks, its network stack, or its kernel metrics.
- Each node needs exactly one copy, no more and no fewer.
- New nodes must get the Pod automatically, and removed nodes must take their Pod with them.
If you add a node to the cluster, the DaemonSet controller creates a Pod there without any action from you. A Deployment with a replica count would not do that.
Typical use cases
Most DaemonSets fall into a few groups:
| Category | What the Pod does | Typical examples |
|---|---|---|
| Log collection | Reads container and system logs from the node's disk and ships them elsewhere | Fluent Bit, Fluentd, Filebeat |
| Node monitoring | Exposes metrics about the node's CPU, memory, disk, and network | Prometheus node-exporter, Datadog agent |
| Networking | Programs routing or network policy rules on each node | Calico, Cilium, kube-proxy |
| Storage | Provides volume access on the node through a node plugin | CSI node plugins, Ceph agents |
| Security and tooling | Watches system calls or applies host-level settings | Falco, node tuning tools |
The tutorial's own example is a small log agent that mounts the node's /var/log directory read-only. It is the same pattern as a real log shipper, with the shipping removed.
When a DaemonSet is the wrong choice
A DaemonSet is not a way to scale an application. You cannot ask for three copies, and the count follows the number of eligible nodes. Use another controller in these cases:
- A web service that needs a chosen number of replicas belongs in a Deployment, where you can scale it or attach a HorizontalPodAutoscaler.
- A database that needs stable names and its own storage per replica belongs in a StatefulSet.
- A job that runs once and finishes belongs in a Job or CronJob.
Compare the three controllers on one question: who decides the count?
| Controller | Who decides the number of Pods |
|---|---|
| Deployment | You, through `replicas` |
| StatefulSet | You, through `replicas` |
| DaemonSet | The cluster, through the number of eligible nodes |
A quick check on your workload
Run through these questions before you write the manifest:
- Does the Pod need to read or change something that exists only on its node?
- Would running two copies on one node cause conflicts or wasted work?
- Would a node with no copy leave a gap, such as missing logs or missing metrics?
Answering yes to all three is a strong signal for a DaemonSet. If you answer no to the first one, a Deployment is usually simpler.
Seeing it on a real cluster
Many clusters already run DaemonSets. List them across all namespaces to see which ones your cluster depends on:
kubectl get daemonset --all-namespacesThe DESIRED column shows how many nodes should run the Pod. The READY column shows how many do. On a healthy cluster the two numbers match, and a difference is the first thing to investigate. The troubleshooting chapter returns to that.
Exercise
A team wants a Prometheus node-exporter to report CPU and disk metrics for every machine in the cluster, including machines added later. Should they use a Deployment with replicas: 10 or a DaemonSet? Explain why.
Show answer
Use a DaemonSet. The exporter reads data local to each node, needs exactly one copy per node, and must appear automatically on new nodes. A Deployment with a fixed replica count could put two copies on one node and none on another, and it would not follow the cluster as nodes are added or removed.