2.08 DaemonSets
π§© DaemonSets in Kubernetes
- DaemonSets are similar to ReplicaSets, but instead of managing replicas across nodes, they ensure one pod runs on every node in the cluster.
- When a new node joins, a pod is automatically created on it; when a node is removed, the corresponding pod is deleted.
- This guarantees one instance per node, maintaining consistent functionality across the cluster.
πΉ Use Cases
- Deploying monitoring agents (e.g., Prometheus Node Exporter).
- Running log collectors (e.g., Fluentd, Filebeat).
- Installing node-level system daemons such as storage or networking agents.
- Deploying networking components like Calico, which requires an agent on each node.
- Running kube-proxy, which can be deployed as a DaemonSet to manage networking rules on all nodes.
πΉ Key Points
- The DaemonSet manifest is almost identical to a ReplicaSetβs, except:
apiVersionβapps/v1kindβDaemonSet- Includes a
selectorandtemplatesection with matching labels - To create and inspect a DaemonSet:
Below is a sample YAML definition for a simple monitoring DaemonSet.
π§Ύ DaemonSet Example (Click to Expand)
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: monitoring-daemon
labels:
app: monitor-agent
spec:
selector:
matchLabels:
app: monitor-agent
template:
metadata:
labels:
app: monitor-agent
spec:
containers:
- name: node-monitor
image: busybox
imagePullPolicy: IfNotPresent
command: ["sh", "-c", "while true; do echo 'Monitoring node...'; sleep 30; done"]
resources:
limits:
cpu: "100m"
memory: "128Mi"
requests:
cpu: "50m"
memory: "64Mi"
π₯ DaemonSets Video Tutorial
Watch this video to understand DaemonSets in Kubernetes more visually: