A Deployment's replica count is a number you choose based on how much of something you need. Some workloads don't fit that question at all — a log collector, for instance, doesn't need "5 replicas," it needs exactly one copy running on every single node, no matter how many nodes exist.
2 min read
"How many replicas of my log collector do I need?" doesn't have a
meaningful fixed number — the real requirement is "exactly one instance
per node, always, including any node added to the cluster later."
Achieving this with a Deployment would mean manually tracking the node
count and updating replicas every time a node is added or removed,
which doesn't scale as a practice and is easy to get out of sync.
A DaemonSet ensures exactly one Pod runs on every node matching its selector, automatically adding a Pod when a new node joins and removing it when a node leaves — no manual replica count involved at all:
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: log-collector
spec:
selector:
matchLabels:
app: log-collector
template:
metadata:
labels:
app: log-collector
spec:
containers:
- name: fluentd
image: fluentd:v1.16The common thread: these workloads are about the node itself, not about handling a share of application traffic — which is exactly the axis that separates "use a Deployment" from "use a DaemonSet."
A DaemonSet doesn't have to run on literally every node — a
nodeSelector or node affinity rule can restrict it to nodes matching
specific labels, useful when only some nodes need a particular daemon (a
GPU-monitoring DaemonSet only needs to run on nodes that actually have a
GPU, for instance).
spec:
template:
spec:
nodeSelector:
gpu: "true"Most clusters already run several DaemonSets by default, often installed
by the cloud provider or cluster setup itself (a CNI plugin, a log
forwarder, a metrics agent) — recognizing them in kubectl get daemonsets --all-namespaces output as expected cluster infrastructure, rather than
mysterious extra Pods to investigate, is directly useful even for someone
who never authors a DaemonSet manifest personally.
Check your understanding
A quick comprehension check — not tracked, not graded, just for you.
1. What problem does a DaemonSet solve that a Deployment's fixed replica count can't naturally address?
2. What kind of workloads are DaemonSets typically used for?
3. Can a DaemonSet be restricted to run on only a subset of nodes instead of all of them?
Kubernetes