Working with DaemonSets
1. Creating DaemonSet
Example: Node log agent DaemonSet
apiVersion: apps/v1
kind: DaemonSet
metadata: { name: fluent-bit, namespace: logging }
spec:
selector: { matchLabels: { app: fluent-bit } }
template:
metadata: { labels: { app: fluent-bit } }
spec:
tolerations:
- { operator: Exists, effect: NoSchedule }
containers:
- name: fb
image: fluent/fluent-bit:3
volumeMounts:
- { name: varlog, mountPath: /var/log }
volumes:
- { name: varlog, hostPath: { path: /var/log } }
2. Listing DaemonSets
kubectl get ds -A
kubectl get ds fluent-bit -n logging -o wide
| Column | Meaning |
| DESIRED | Nodes matching nodeSelector/tolerations |
| CURRENT | Pods created |
| READY | Pods passing readiness |
| UP-TO-DATE | Pods matching latest spec |
3. Describing DaemonSet Details
| Section | Info |
| Node-Selector | Where pods are scheduled |
| Pods Status | Running counts |
| Update Strategy | RollingUpdate / OnDelete |
4. Understanding DaemonSet Scheduling
| Mechanism | Detail |
| Scheduler | Default kube-scheduler with affinity injection |
| New node | DS controller adds pod when node joins |
| Node removal | Pod deleted with node |
5. Using Node Selectors
spec:
template:
spec:
nodeSelector:
kubernetes.io/os: linux
node-role: edge
| Use | Example |
| OS | kubernetes.io/os=linux |
| Architecture | kubernetes.io/arch=amd64 |
| Custom role | node-role=ingress |
6. Using Node Affinity
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- { key: gpu, operator: In, values: [nvidia] }
| Mode | Behavior |
| required | Hard requirement |
| preferred | Soft preference w/ weight |
7. Tolerating Taints
tolerations:
- operator: Exists # tolerate any taint
- key: node-role.kubernetes.io/control-plane
operator: Exists
effect: NoSchedule
| Use | Detail |
| Run on master | Tolerate control-plane taint |
| Run on tainted edge | Tolerate role-specific taint |
8. Updating DaemonSets
| updateStrategy | Behavior |
| RollingUpdate (default) | Replace pods node by node |
| OnDelete | Update only when pod manually deleted |
kubectl rollout status ds/fluent-bit -n logging
kubectl rollout history ds/fluent-bit -n logging
kubectl rollout undo ds/fluent-bit -n logging
9. Setting Max Unavailable
updateStrategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 25%
maxSurge: 0 # since 1.25; 0 by default for DS
| Field | Default |
| maxUnavailable | 1 |
| maxSurge | 0 (no extra pod per node) |
10. Deleting DaemonSets
| Command | Effect |
kubectl delete ds NAME | Cascading delete pods |
kubectl delete ds NAME --cascade=orphan | Keep pods |
11. Troubleshooting DaemonSet Pods
| Symptom | Likely Cause |
| Not running on N nodes | nodeSelector/affinity excludes them |
| Missing on master | Missing toleration for control-plane taint |
| Hostpath permission denied | SecurityContext / SELinux / mount options |
| Pods evicted | Resource pressure; lower priority class |