Skip to main content

DaemonSet

A DaemonSet is a Kubernetes controller that runs one copy of a pod on every node, or on a chosen subset of nodes. New nodes automatically get the pod and removed nodes have it cleaned up, which suits log collectors, monitoring agents, and network plugins.

When to use a DaemonSet

Use it for per-node infrastructure agents:

  • Log collection (Fluent Bit, Promtail)
  • Node metrics (Node Exporter)
  • CNI and storage node agents
  • Security agents (Falco)

Do not use it for ordinary application workloads. Use a Deployment, where you control the replica count, or a Job for batch work.

flowchart TD D["DaemonSet
node-exporter"] -->|"one pod"| N1["mumbai-node-1"] D -->|"one pod"| N2["mumbai-node-2"] D -->|"one pod"| N3["mumbai-node-3"] N4["New node joins"] -->|"auto-scheduled"| D classDef ctl fill:#326CE5,color:#ffffff classDef node fill:#DBEAFE,color:#1E293B classDef new fill:#D1FAE5,color:#1E293B class D ctl class N1,N2,N3 node class N4 new

Example: Node Exporter

YAML
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: node-exporter
namespace: monitoring
spec:
selector:
matchLabels:
app: node-exporter
template:
metadata:
labels:
app: node-exporter
spec:
hostNetwork: true
hostPID: true
tolerations:
- key: node-role.kubernetes.io/control-plane
operator: Exists
effect: NoSchedule
containers:
- name: node-exporter
image: prom/node-exporter:v1.8.2
resources:
requests:
cpu: "50m"
memory: "64Mi"
limits:
memory: "128Mi"

Limiting which nodes run it

Use nodeSelector or node affinity for subsets, such as GPU nodes only. Add tolerations for tainted nodes, scoped to the specific taint where possible.

Bash
kubectl get ds -n monitoring
kubectl get pods -n monitoring -l app=node-exporter -o wide
kubectl rollout status ds/node-exporter -n monitoring
Remember

Pod count should equal the number of eligible nodes. A shortfall usually means a taint without a toleration or pods failing on those nodes.

Security

hostNetwork and hostPID expose the node's network and processes. Reserve them for trusted infrastructure agents and review them in audits.

Tip

Always set resource requests and limits. A log agent without limits can starve application pods during a log burst.

Common Mistake

Using a Deployment with replicas equal to the node count. New nodes will not get a pod automatically.

Frequently Asked Questions

Why not use a Deployment with enough replicas?

A Deployment replica count is static and does not guarantee one pod per node, so two pods may share a node while another has none. A DaemonSet follows the node list automatically.

Do DaemonSet pods run on control-plane nodes?

Only if they tolerate the control-plane taint. Add a toleration for node-role.kubernetes.io/control-plane when the agent must run there.

How do I update a DaemonSet safely?

Use the RollingUpdate strategy with maxUnavailable set so only a few nodes are updated at once, and watch kubectl rollout status for progress.

Found a mistake, an outdated step or a broken link?