DevOps Bootcamp · Lesson

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.

Lesson 2 of 411 steps

DaemonSets for Node-Specific Tasks is a free DevOps Bootcamp lesson on CoddyKit. This is lesson 2 of 4. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the DevOps Bootcamp learning path, and your progress syncs across the web and the CoddyKit app. The DevOps Bootcamp course includes 4 lessons in total.

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.nodeName

Key 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.nodeName

Launching 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.nodeName

DaemonSet 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 nodeSelector to target specific nodes.
  • DaemonSets are defined with kind: DaemonSet and use a Pod template, similar to Deployments.

Next, you'll explore StatefulSets for managing stateful applications!

Free to start

Learn DevOps Bootcamp with an AI tutor — free

Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.

Courses
142
Lessons
568

Frequently Asked Questions

Is the “DaemonSets for Node-Specific Tasks” lesson free?

Yes — any 3 lessons of the DevOps Bootcamp learning path, including “DaemonSets for Node-Specific Tasks”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The DevOps Bootcamp course includes 4 lessons in total.

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, so you can start here or from the beginning and move at your own pace. This is lesson 2 of 4.

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

  1. StatefulSets for Stateful Apps
  2. DaemonSets for Node-Specific Tasks
  3. Understanding Kubernetes Operators
  4. Custom Resource Definitions (CRDs)
← Back to DevOps Bootcamp