Senior
DaemonSet — how does it work?
sobes.tech AI
Answer from AI
A DaemonSet in Kubernetes ensures that a copy of a pod runs on each (or selected) node in the cluster. Its working logic is as follows:
- When a DaemonSet is created, Kubernetes guarantees that one instance of the pod will be running on each node.
- If a new node is added to the cluster, the DaemonSet automatically creates a pod on it.
- If a node is removed, the corresponding pod is also removed.
- This is useful for running system agents, monitoring, logging, and other services that need to operate on all nodes.
Example of a DaemonSet manifest:
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: example-daemonset
spec:
selector:
matchLabels:
name: example
template:
metadata:
labels:
name: example
spec:
containers:
- name: example-container
image: busybox
command: ["sleep", "3600"]
Thus, the DaemonSet ensures the continuous presence of pods on all nodes, which is important for system tasks.