Junior — Middle
What is the purpose of DaemonSets in Kubernetes and how are they used?
sobes.tech AI
Answer from AI
DaemonSet in Kubernetes is used to run a copy of a pod on each (or selected) node in the cluster. This is useful for tasks that need to run on all nodes, such as log collection, monitoring, network proxies, or other system agents.
When you create a DaemonSet, Kubernetes ensures that one instance of the pod is running on each node. If a new node is added to the cluster, the DaemonSet automatically starts a pod on it. If a node is removed, the pod is removed along with it.
Example of using a DaemonSet to run a monitoring agent on all nodes:
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: node-exporter
spec:
selector:
matchLabels:
name: node-exporter
template:
metadata:
labels:
name: node-exporter
spec:
containers:
- name: node-exporter
image: prom/node-exporter
ports:
- containerPort: 9100
Thus, the DaemonSet provides automatic and guaranteed deployment of system pods on all required nodes of the cluster.