A DaemonSet is a Kubernetes workload resource designed to ensure that a copy of a specific Pod runs on every eligible node in a cluster. It is commonly used for node-level services such as log collectors, monitoring agents, and networking components.
1. DaemonSet Identifies Eligible Nodes
When a DaemonSet is created, the DaemonSet controller determines which nodes should run its Pods. By default, this means all nodes. However, nodeSelector or node affinity can be used to restrict the DaemonSet to specific nodes.
2. One Pod Per Eligible Node
The controller creates one Pod for each eligible node. If a new matching node is added to the cluster, the DaemonSet automatically creates a Pod for that node.
For example, if a cluster has five eligible worker nodes, the DaemonSet normally maintains five Pods, with one Pod on each node.
3. Kubernetes Scheduler Places the Pod
The DaemonSet controller creates the Pod with node-specific affinity targeting the selected node. The Kubernetes scheduler then normally handles the scheduling and binds the Pod to that node.
This is different from a Deployment, where the scheduler can place replicas across suitable nodes according to normal scheduling decisions.
4. Taints and Tolerations
Taints can prevent Pods from being scheduled on certain nodes. A DaemonSet can use tolerations to allow its Pods to run on nodes with specific taints.
This is useful for system-level workloads that need to run on specialized or otherwise restricted nodes.
5. What Happens When a Node Is Removed?
If a node is removed from the cluster, the Pod associated with that node is also removed. If another eligible node is added, the DaemonSet controller creates a new Pod there.
6. Resource Requirements Still Matter
Although a DaemonSet aims to place a Pod on every eligible node, the Pod still needs to satisfy scheduling requirements such as available CPU and memory, node selectors, affinity rules, and tolerations.
If a Pod cannot fit on a node, Kubernetes may be unable to schedule it there.
7. Common Use Cases
DaemonSets are commonly used for:
- Log collection agents
- Node monitoring agents
- Storage-related services
- Network plugins
- Security and observability agents
Overall, a DaemonSet does not simply create a fixed number of replicas. It maintains one Pod on each eligible node, automatically responding when nodes are added or removed. This makes it ideal for services that need to operate locally on every node in a Kubernetes cluster.