liveBook · Manning

DaemonSet

As explained in Kubernetes in Action, Second Edition

A DaemonSet is a Kubernetes resource that ensures a pod instance runs on each eligible node or selected subset of nodes.

A DaemonSet runs one Pod on each eligible cluster node, or on each node in a selected subset. It is useful for node-level agents that collect logs, monitor processes, or provide networking services. Unlike a Deployment, it has no replica count: the number of Pods follows the number of eligible nodes. A node with an untolerated taint is not eligible; this commonly excludes control-plane nodes. section 17.1 section 17.1.1 section 17.4

Listing 17.1 A DaemonSet manifest example
apiVersion: apps/v1     #1
kind: DaemonSet        #1
metadata:
  name: demo      #2
spec:
  selector:            #3
    matchLabels:       #3
      app: demo        #3
  template:                 #4
    metadata:               #4
      labels:               #4
        app: demo           #4
    spec:                   #4
      containers:           #4
      - name: demo          #4
        image: busybox      #4
        command:            #4
        - sleep             #4
        - infinity          #4

A minimal apps/v1 manifest shows the two essential parts: a label selector and a Pod template whose labels match it. The example Pods run sleep so their placement is easy to inspect. section 17.1.2

The DaemonSet controller checks which Pods match its label selector and reconciles them against the nodes: it creates a Pod for a newly eligible node and removes one when a node leaves. To limit placement, set spec.template.spec.nodeSelector to match node labels. The node selector chooses nodes; the Pod label selector identifies Pods owned by the DaemonSet. section 17.1.1 section 17.1.3

Inspect and narrow placement

Apply a manifest with kubectl apply -f ds.demo.yaml, then run kubectl get ds to compare DESIRED, CURRENT, and READY. Use kubectl get pods -l app=demo -o wide to see each Pod’s node. Adding nodeSelector: {gpu: cuda} to the Pod template produces no Pods if no nodes have that label; labeling an eligible node gpu=cuda brings a Pod into scope, and removing the label takes it out. section 17.1.2 section 17.1.3

Changing the Pod template also changes the Pods. RollingUpdate replaces them automatically, normally stopping an old Pod before starting its replacement on that node. OnDelete waits until you delete each old Pod, letting you choose the pace. For node agents that need host resources, configure that access in the Pod template. A hostPort can forward a node port to its local agent Pod; unlike a NodePort Service, it does not send the connection to a Pod on another node. section 17.1.4 section 17.2 section 17.3.1

How Kubernetes in Action, Second Edition covers it

How deep it goes
Works through manifests, placement checks, controller reconciliation, and update strategies; treats host access as Pod-template configuration.
Examples
Uses a sleeping-Pod manifest, GPU-labeled nodes, kubectl status checks, and a node agent reachable through a host port.
What it assumes
Builds on Pods and Deployments while introducing DaemonSets from their per-node purpose and first manifest.
What you can do after
Operate/configure it with kubectl and manifests to inspect per-node Pods, select nodes, and choose an update strategy.
How it connects
Connects Pod templates and label selectors to node selectors, taints, rolling updates, and host ports.

Also explained in

Compare how 3 books explain DaemonSet →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kubernetes in Action, Second Edition. The section links point to the parts of the book it draws on.