DaemonSets for Node-Specific Tasks
Use DaemonSets to run a copy of a Pod on all or selected nodes in your cluster for cluster-level operations.
DaemonSets for Node-Specific Tasks is a free DevOps Bootcamp lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the DevOps Bootcamp learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
What are DaemonSets?
Imagine you need a specific tool or service to run on every server in your cluster. For example, a logging agent that collects logs from each machine.
This is where DaemonSets come in! Unlike Deployments, which aim to keep a certain number of Pods running somewhere in the cluster, a DaemonSet ensures a copy of a Pod runs on all (or selected) nodes.
Common DaemonSet Uses
DaemonSets are perfect for tasks that need to run at the node level. Here are some common examples:
- Logging Agents: Tools like Fluentd or Logstash to collect logs from each node.
- Monitoring Agents: Prometheus Node Exporter to gather metrics from every server.
- Storage Daemons: Services like GlusterFS or Ceph that provide distributed storage on each node.
- Network Proxies: Kubernetes' own Kube-proxy runs as a DaemonSet to manage network rules.
Basic DaemonSet Manifest
A DaemonSet's definition looks very similar to a Deployment. The key difference is the kind: DaemonSet. Let's look at a basic structure:
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: my-daemonset
spec:
selector:
matchLabels:
app: my-daemonset-app
template:
metadata:
labels:
app: my-daemonset-app
spec:
containers:
- name: my-container
image: busybox
command: ["sh", "-c", "echo 'Hello from DaemonSet on node $(NODE_NAME)'; sleep 3600"]
env:
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeNameKey Parts of the YAML
Let's break down the important sections of our DaemonSet manifest:
kind: DaemonSet: This tells Kubernetes we want to manage node-specific Pods.spec.selector: Essential! It defines how the DaemonSet finds and manages its Pods using labels.spec.template: This is the Pod definition itself. It's almost identical to the Pod template you'd find in a Deployment. It describes the containers, volumes, and other settings for the Pod that will run on each node.
Deploying to All Nodes
Here's a simple DaemonSet that runs a busybox container on every eligible node. It will print a message indicating which node it's running on.
This is a common pattern for cluster-wide agents.
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: node-hello-daemon
spec:
selector:
matchLabels:
app: node-hello
template:
metadata:
labels:
app: node-hello
spec:
containers:
- name: hello-container
image: busybox
command: ["sh", "-c", "while true; do echo 'Hello from node: $(NODE_NAME)'; sleep 5; done"]
env:
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeNameLaunching Your DaemonSet
To create the DaemonSet in your Kubernetes cluster, you use the familiar kubectl apply command with the YAML file you just saw:
kubectl apply -f node-hello-daemonset.yaml
Kubernetes will then ensure a Pod is scheduled on every node that matches the DaemonSet's criteria.
Checking DaemonSet Health
After applying, you can check the status of your DaemonSet and the Pods it created:
- To see the DaemonSet:
kubectl get ds - To see the individual Pods running on each node:
kubectl get pods -l app=node-hello -o wide
The -o wide option helps you see which node each Pod is scheduled on.
DaemonSets on Selected Nodes
What if you only want your DaemonSet to run on a subset of your nodes? For example, only on nodes with a GPU, or nodes dedicated to storage.
You can achieve this using nodeSelector. This field in the Pod's spec (within the DaemonSet's template) allows you to specify node labels that a node must have for the Pod to be scheduled there.
Using Node Selectors in YAML
Let's modify our previous DaemonSet to only run on nodes labeled disktype: ssd. You'd first need to label your nodes, e.g., kubectl label node <node-name> disktype=ssd.
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: ssd-monitor-daemon
spec:
selector:
matchLabels:
app: ssd-monitor
template:
metadata:
labels:
app: ssd-monitor
spec:
nodeSelector:
disktype: ssd # Only runs on nodes with this label
containers:
- name: monitor-container
image: busybox
command: ["sh", "-c", "while true; do echo 'Monitoring SSD on node: $(NODE_NAME)'; sleep 10; done"]
env:
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeNameDaemonSet Capabilities
You've learned how DaemonSets work. Let's test your understanding!
DaemonSets: Key Takeaways
Great job! You've successfully learned about Kubernetes DaemonSets.
- DaemonSets ensure a Pod runs on every eligible node.
- They are crucial for node-level operations like logging, monitoring, and storage agents.
- You can use
nodeSelectorto target specific nodes. - DaemonSets are defined with
kind: DaemonSetand use a Pod template, similar to Deployments.
Next, you'll explore StatefulSets for managing stateful applications!
Frequently asked questions
Is the “DaemonSets for Node-Specific Tasks” lesson free?
Yes — the full text of “DaemonSets for Node-Specific Tasks” is free to read here on the web, and the DevOps Bootcamp course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the DevOps Bootcamp course, upgrade to CoddyKit PRO.
What will I learn in “DaemonSets for Node-Specific Tasks”?
Use DaemonSets to run a copy of a Pod on all or selected nodes in your cluster for cluster-level operations. You practise DevOps Bootcamp with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start DevOps Bootcamp?
No prior experience is required. DevOps Bootcamp on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “DaemonSets for Node-Specific Tasks” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this DevOps Bootcamp lesson?
Yes. Every DevOps Bootcamp lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- StatefulSets for Stateful Apps
- DaemonSets for Node-Specific Tasks
- Understanding Kubernetes Operators
- Custom Resource Definitions (CRDs)