Kubernetes: DaemonSets
A DaemonSet is a workload that runs one copy of a Pod on every node. A DaemonSet adds a Pod when a node joins and removes it when a node leaves.
One Pod per node, in YAML
The manifest looks like a Deployment. The kind is DaemonSet, and there is no replica count to set.
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: log-agent
spec:
selector:
matchLabels:
app: log-agent
template:
metadata:
labels:
app: log-agent
spec:
containers:
- name: log-agent
image: nginx:1.27-alpineCreate the DaemonSet
apply creates the DaemonSet. It then places one Pod on each node.
kubectl apply -f log-agent.yamlCheck one per node
Desired 1 matches the one node in minikube. A second node would raise it to 2.
kubectl get daemonsetsSee which node runs it
The wide view shows the node name. The agent Pod sits on minikube.
kubectl get pods -o wideExample
kubectl apply -f log-agent.yaml
kubectl get daemonsets
kubectl get podsKey points
- DaemonSet: a workload that keeps one Pod on every node in the cluster.
- Use a DaemonSet for a log collector, a monitor or a storage helper.
- A new node gets a new Pod by itself, with no command from you.
- A node that leaves takes its Pod with it.
- Use kubectl get daemonsets to check the count against the node count.
- A DaemonSet Pod runs the same image on every node.
In this example, apply creates a DaemonSet that runs a log agent. get daemonsets shows one Pod per node. get pods shows the agent running on the minikube node. Add a node and a new agent Pod appears there by itself.
Note
A DaemonSet is for work that belongs on every machine, not for an app that serves users.
Try it Yourself
Edit the code, then press Run.
Running is simulated · Rust Playground
Exercise
What does a DaemonSet do?