What You Will Learn
Intermediate
- What a DaemonSet is
- When to use it
- How it differs from Deployment
A DaemonSet ensures that a copy of a Pod runs on every node (or selected nodes). When a new node joins the cluster, the DaemonSet automatically places a Pod on it.
| Deployment | DaemonSet |
|---|---|
| N replicas anywhere | 1 Pod per node |
| Scale by changing replicas | Scale by adding nodes |
| Best for: web apps, APIs | Best for: node-level services |
Common Use Cases
- Log collection: Fluentd/Fluent Bit on every node
- Monitoring: Prometheus Node Exporter on every node
- Network plugin: Calico, Weave on every node
- Storage daemon: Ceph, GlusterFS on storage nodes
daemonset.yamlyaml
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:latest
volumeMounts:
- name: varlog
mountPath: /var/log
volumes:
- name: varlog
hostPath:
path: /var/logPractical Exercise
Create a DaemonSet YAML
Apply: kubectl apply -f daemonset.yaml
Check: kubectl get pods - should be 1 per node
Check: kubectl get daemonsets
Add a node (if using minikube: minikube node add)
Key Takeaways
- DaemonSet: 1 Pod per node (automatically).
- New node = DaemonSet puts a Pod on it.
- Use for: log collection, monitoring, network plugins.
- Deployment = N replicas anywhere. DaemonSet = 1 per node.
- Scale by adding nodes, not changing replicas.
Comments
Comments
Post a Comment