Understanding DaemonSets in Kubernetes: A Beginner-Friendly Guide
When learning Kubernetes, you often work with Deployments and ReplicaSets to ensure your applications run reliably across your cluster. But what if you need one pod per node instead of multiple replicas? That’s where DaemonSets come in.
Let’s break it down.
What is a DaemonSet?
A DaemonSet is a Kubernetes object that ensures exactly one copy of a pod runs on every node in your cluster.
When a new node joins the cluster, the DaemonSet automatically deploys a pod on it.
When a node is removed, the pod running on it is also deleted.
Think of it as a “one pod per node manager.”
Key difference from ReplicaSet:
ReplicaSets focus on running a specified number of pod replicas across the cluster.
DaemonSets focus on ensuring every node has one copy of a pod.
Why Use a DaemonSet?
DaemonSets are perfect for workloads that need to run on every node, such as:
Monitoring agents
Example: You want to deploy a pod that collects logs or metrics from every node.
DaemonSet ensures each node automatically gets the monitoring pod.
Cluster networking components
- Example: Solutions like Weave Net require an agent pod on every node to manage network traffic.
Node-level system components
- Example: The kube-proxy component, which handles network rules, can run as a DaemonSet on all nodes.
✅ Tip: DaemonSets save you the trouble of manually adding or removing pods as nodes are added or removed.
How Does a DaemonSet Work?
Before Kubernetes v1.12
Pods were scheduled manually on nodes by setting the
nodeNameproperty in the pod specification.Each pod was “pinned” to a specific node.
From Kubernetes v1.12 Onwards
DaemonSets use the default scheduler along with node affinity rules.
The scheduler automatically decides which pod goes to which node.
You no longer need to manually specify nodes; Kubernetes takes care of it.
Creating a DaemonSet
Creating a DaemonSet is very similar to creating a ReplicaSet. The main difference is the kind:
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: monitoring-daemon
spec:
selector:
matchLabels:
app: monitoring
template:
metadata:
labels:
app: monitoring
spec:
containers:
- name: monitoring-agent
image: monitoring-agent:lates
Steps to create and manage DaemonSets:
- Create the DaemonSet:
kubectl create -f monitoring-daemon.yaml
- View all DaemonSets:
kubectl get daemonset
- View detailed info about a DaemonSet:
kubectl describe daemonset monitoring-daemon
⚠️ Tip: Ensure the labels in the
selectormatch the labels in the pod template. Otherwise, the DaemonSet won’t manage the pods properly.
Summary: Why DaemonSets Matter
Automatic deployment: Ensures one pod per node without manual intervention.
Perfect for node-level tasks: Monitoring, logging, networking, or system agents.
Integrates with Kubernetes scheduler: Modern DaemonSets use affinity rules to schedule pods efficiently.
Key Takeaways for Learners
DaemonSets = One pod per node
Use cases: kube-proxy, monitoring agents, network agents
Modern scheduling: Uses default scheduler + node affinity
Management commands:
kubectl create,kubectl get daemonset,kubectl describe daemonset
DaemonSets may seem like just another Kubernetes object, but they are crucial for maintaining cluster-wide consistency for essential services. Understanding how to deploy and manage them is a key step in mastering Kubernetes.