DaemonSets
Theory
A DaemonSet ensures that a copy of a specific Pod runs on every node (or a subset using node selectors or affinity rules). Use cases include:
- Running log collection agents (e.g., FluentD)
- Running monitoring agents (e.g., Prometheus node-exporter)
- Running networking plugins (e.g., kube-proxy, weave-net)
DaemonSets are commonly used when you need:
- Node-local functionality
- To ensure one Pod per node
- Full visibility or access to host-level resources
Scheduling Behavior
- Prior to Kubernetes v1.12, DaemonSet pods were scheduled manually by the DaemonSet controller.
- From Kubernetes v1.12 onwards, they use the default scheduler with
NodeAffinityunder the hood.

DaemonSets vs ReplicaSets vs Deployments
Unlike ReplicaSets and Deployments, which distribute Pods across nodes based on desired counts, DaemonSets schedule one pod per node, regardless of cluster size.

Use Cases
1. Monitoring & Logging
Deploy logging and monitoring agents on each node:

2. kube-proxy
The Kubernetes networking component kube-proxy runs as a DaemonSet:

3. Networking Plugins
CNI plugins like weave-net, flannel, etc., are deployed using DaemonSets:

Practical
1. Viewing DaemonSets
kubectl get daemonsets --all-namespaces
kubectl describe daemonset <name> -n <namespace>
2. Count all DaemonSets in the cluster:
kubectl get daemonsets --all-namespaces --no-headers | wc -l
3. Identify kube-proxy DaemonSet
kubectl get daemonset kube-proxy -n kube-system
- Namespace:
kube-system - Scheduled on 1 node (from DESIRED column)
4. Get Image of kube-flannel-ds DaemonSet
kubectl get daemonset kube-flannel-ds -n kube-flannel -o jsonpath="{.spec.template.spec.containers[*].image}"
Create a DaemonSet
YAML Definition:
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: elasticsearch
namespace: kube-system
labels:
k8s-app: fluentd-logging
spec:
selector:
matchLabels:
name: fluentd
template:
metadata:
labels:
name: fluentd
spec:
containers:
- name: fluentd
image: registry.k8s.io/fluentd-elasticsearch:1.20
resources:
limits:
memory: 200Mi
requests:
cpu: 100m
memory: 200Mi
volumeMounts:
- name: varlog
mountPath: /var/log
- name: varlibdockercontainers
mountPath: /var/lib/docker/containers
readOnly: true
terminationGracePeriodSeconds: 30
volumes:
- name: varlog
hostPath:
path: /var/log
- name: varlibdockercontainers
hostPath:
path: /var/lib/docker/containers
Apply:
kubectl apply -f fluentd-daemonset.yaml
Imperative Creation:
kubectl create daemonset elasticsearch \
--image=registry.k8s.io/fluentd-elasticsearch:1.20 \
--namespace=kube-system \
--dry-run=client -o yaml | kubectl apply -f -
Inspect Existing DaemonSet
Example:
kubectl get daemonsets
kubectl describe daemonsets monitoring-daemon

Appendix
Example DaemonSet YAML
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: monitoring-daemon
spec:
selector:
matchLabels:
app: monitoring-agent
template:
metadata:
labels:
app: monitoring-agent
spec:
containers:
- name: monitoring-agent
image: monitoring-agent

This section is part of: Scheduling -> DaemonSets