Kubernetes DaemonSets Explained: One Pod Per Node

Kubernetes DaemonSets Explained: One Pod Per Node

Every Kubernetes cluster has work that belongs on every node. Log files must be collected from every machine, metrics must be scraped from every machine, and the network fabric must be present on every machine before any application pod can talk to anything else. None of this work belongs in an application Deployment, which runs a fixed number of replicas spread across the cluster rather than guaranteeing coverage of every node. The workload that guarantees one pod on every node is the DaemonSet, and it is one of the oldest and most widely used controllers in Kubernetes.

A DaemonSet is deceptively simple to describe and surprisingly rich in behavior once you start using it in production. You declare a pod template and the controller makes sure that a copy of that pod runs on every node that matches the DaemonSet, adding a pod when a node joins the cluster and removing it when a node leaves. This article explains exactly what a DaemonSet guarantees, the classic use cases it serves, how to write and scope one, how taints and tolerations control where it runs, how its update strategies work, and how it compares with Deployments and static pods.

What a DaemonSet Guarantees

A DaemonSet guarantees that one pod matching its template runs on every node that is eligible for it. Eligibility is the key word. The controller watches the nodes in the cluster and schedules a pod onto each node that matches the DaemonSet’s node selector, node affinity rules, and tolerations, and it leaves alone any node that does not match. When a new node joins the cluster, the controller notices it and creates a pod there. When a node is removed, the controller deletes the pod that was running on it. When a DaemonSet pod is deleted or crashes, the controller recreates it on the same node. The guarantee is about coverage of the node fleet, not about a number of replicas, and there is no replica count to set or scale in a DaemonSet.

Because the guarantee is tied to nodes, DaemonSet pods are scheduled in a special way. Unlike normal pods, which the Kubernetes scheduler places, DaemonSet pods are scheduled by the DaemonSet controller itself, and the controller sets the nodeName field directly on the pod. This is why a DaemonSet pod that cannot start because its node is out of resources stays in a Pending state on that node rather than being moved to a healthier one: moving it would break the one pod per node guarantee.

Every DaemonSet pod must have its restart policy set to Always, or left unset so that it defaults to Always. The API server rejects a DaemonSet whose template uses OnFailure or Never, because a DaemonSet pod is expected to run continuously for the lifetime of its node. If a container exits, the kubelet restarts it in place. This is the correct model for the agents a DaemonSet typically runs: a log collector that exits has failed and should come back, not finish quietly. The restart policy rule is enforced at creation time, so if you copy a pod template from a Job or a one-off troubleshooting pod, remember to change the restart policy before you apply it.

DaemonSet pods are also treated differently by the cluster when nodes become unhealthy. The DaemonSet controller automatically adds tolerations for the node.kubernetes.io/not-ready and node.kubernetes.io/unreachable taints, with a toleration period of 300 seconds, so that a DaemonSet pod is not evicted the moment a node reports a problem. This matters because a DaemonSet often runs the very agents that report node health, and evicting them at the first sign of trouble would destroy the evidence you need to diagnose the problem. After the toleration period expires, the pod is evicted like any other, but five minutes of grace is usually enough for a transient network partition to resolve or for an operator to intervene.

The Classic Use Cases: Logging, Monitoring, and Networking

Three categories of work account for the vast majority of DaemonSets in production clusters, and they are all node-level services that every node needs. The first is log collection. Applications write logs to files on the node, and a log collector such as Fluent Bit or Fluentd runs on every node, tails those files, and forwards the contents to a central store. Running the collector as a DaemonSet means you never have to remember to install it on a new node, and a node that loses its collector gets a replacement automatically. The collector typically needs access to the host log directories, so it mounts /var/log and the container runtime log directory into the pod, and it runs with enough privilege to read files owned by other processes.

The second classic use case is monitoring. Node Exporter, the Prometheus agent that exposes hardware and operating system metrics, is the canonical example: one Node Exporter per node, scraping CPU, memory, disk, and network statistics and exposing them for Prometheus to collect. Without a DaemonSet, a monitoring gap would open every time a node was added or a pod was deleted, and the gaps would be exactly the nodes you most need to observe during an incident. Our Prometheus and Grafana monitoring tutorial shows how those metrics flow from Node Exporter into dashboards and alerts, and the DaemonSet is what keeps the data flowing from every node without manual intervention.

The third category is cluster networking and storage. The Container Network Interface plugin that gives pods their network connectivity runs as a DaemonSet in almost every cluster, because every node needs the networking agent before it can host any pod at all. The same applies to storage drivers and to the kube-proxy component in many installations. These are infrastructure DaemonSets, installed by the cluster administrator or by the managed Kubernetes provider, and they illustrate an important property of the controller: a DaemonSet is the natural home for any component that must be present before other workloads can function on a node. If a component must run everywhere, it is probably a DaemonSet.

Beyond these three, DaemonSets appear anywhere a per-node agent is needed: security scanners that inspect the host filesystem, backup agents, certificate managers that need node access, and GPU device plugins that expose hardware to the scheduler. The common thread is that the work is tied to the node, not to a service. If you find yourself writing a Deployment and then wondering how to make sure one replica lands on every node, that is the signal to reach for a DaemonSet instead.

Writing Your First DaemonSet

A DaemonSet manifest looks familiar if you have written a Deployment, because the two share the same building blocks: an apiVersion, a kind, metadata, a selector, and a pod template. The differences are in the details. The DaemonSet API version is apps/v1, the kind is DaemonSet, the update strategy field lives under spec.updateStrategy instead of spec.strategy, and there is no replicas field at all. The selector must match the labels on the pod template, and it is immutable after creation, so choose your labels carefully before you apply the manifest for the first time.

Here is a complete, working DaemonSet that runs Fluent Bit on every node to collect container logs. It uses the official Fluent Bit image, mounts the host log directories into the pod, and runs with a service account that has permission to read pod metadata. Save it as fluent-bit-daemonset.yaml and apply it with kubectl apply -f fluent-bit-daemonset.yaml.

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: fluent-bit
  namespace: logging
  labels:
    app: fluent-bit
spec:
  selector:
    matchLabels:
      app: fluent-bit
  template:
    metadata:
      labels:
        app: fluent-bit
    spec:
      serviceAccountName: fluent-bit
      containers:
        - name: fluent-bit
          image: cr.fluentbit.io/fluent/fluent-bit:3.1
          resources:
            limits:
              memory: 200Mi
            requests:
              cpu: 100m
              memory: 100Mi
          volumeMounts:
            - name: varlog
              mountPath: /var/log
            - name: varlibdockercontainers
              mountPath: /var/lib/docker/containers
              readOnly: true
      volumes:
        - name: varlog
          hostPath:
            path: /var/log
        - name: varlibdockercontainers
          hostPath:
            path: /var/lib/docker/containers
      tolerations:
        - key: node-role.kubernetes.io/control-plane
          operator: Exists
          effect: NoSchedule

Several choices in this manifest deserve attention. The hostPath volumes give the collector read access to the logs on the node, mounted read-only because the collector never needs to write there. Resource requests and limits keep a misbehaving collector from starving application pods on the same node. The toleration at the bottom is deliberate: it allows this DaemonSet to run on control-plane nodes as well as worker nodes, so that control-plane logs are collected too. Without it, the control-plane taint would keep the pod off those nodes, and the next section explains exactly how that mechanism works.

Once the DaemonSet is applied, inspect it the same way you would inspect any workload. The kubectl get ds command is the DaemonSet equivalent of kubectl get deploy, and the -A flag shows DaemonSets across all namespaces, which is useful because infrastructure DaemonSets often live in kube-system while yours live in an application namespace.

kubectl get ds -A
kubectl get ds fluent-bit -n logging
kubectl describe ds fluent-bit -n logging
kubectl get pods -n logging -o wide

The output of kubectl get ds shows the desired number of pods, the number currently running, the number ready, and the number up to date, along with the node selector if one is set. Desired equals the number of eligible nodes, so if desired is smaller than the number of nodes in your cluster, some nodes are being excluded by a selector, an affinity rule, or a missing toleration, and kubectl describe ds will show the events that explain why. The -o wide flag on kubectl get pods is particularly useful for DaemonSets because it shows the node each pod is running on, letting you confirm at a glance that every node really has one.

Scoping DaemonSets with nodeSelector, Affinity, and Labels

Running on every node is the default, but many DaemonSets should run on a subset of nodes. A GPU monitoring agent is useless on nodes without GPUs, a storage driver should only run where its storage backend is attached, and a compliance scanner might be required only on nodes in a particular region. Kubernetes gives you three tools for scoping a DaemonSet, and they can be combined: nodeSelector for simple label matching, node affinity for expressive rules, and taints with tolerations for keeping pods off nodes unless they explicitly opt in.

The simplest tool is nodeSelector, a map of label key value pairs under spec.template.spec.nodeSelector. The controller only schedules pods onto nodes whose labels contain every entry in the map. For example, adding nodeSelector with disk: ssd restricts the DaemonSet to nodes labelled disk=ssd, which is exactly what you want for a storage agent that only works with solid state drives. The limitation is that nodeSelector can only express AND conditions on exact label matches, so it cannot say “nodes in zone A or zone B” or “any node except the ones labelled experimental”. For those rules you need affinity.

Node affinity, specified under spec.template.spec.affinity.nodeAffinity, supports both requiredDuringScheduling rules that act as hard constraints and preferredDuringScheduling rules that act as soft preferences with weights. A required rule can express the OR condition that nodeSelector cannot, for example requiring a node to carry either the label gpu=true or the label accelerator=nvidia. A preferred rule can express a preference, such as preferring nodes in a particular availability zone, without excluding nodes elsewhere. Affinity is more verbose than nodeSelector, but it is the right tool whenever the scoping rule is anything more complex than a single label match, and it composes cleanly with taints and tolerations.

Labels are the foundation of all three tools, and labelling nodes well is a prerequisite for scoping DaemonSets sensibly. Use kubectl label node to add labels, and keep the labelling scheme consistent across the cluster so that a DaemonSet author can predict which nodes will match. One common mistake is to label nodes by hand in an ad hoc way and then write a DaemonSet that matches a label that only exists on half the intended nodes; the other half silently gets no pod, and the gap is only discovered when the missing node’s logs are needed during an incident. Verify coverage after every change with kubectl get pods -o wide and compare the node list against kubectl get nodes.

Taints and Tolerations, Including Control-Plane Nodes

Taints are the inverse of labels: instead of attracting pods, a taint repels them. A node with a taint will not accept a pod unless the pod declares a toleration for that taint. The three taint effects are NoSchedule, which prevents new pods from being scheduled on the node, PreferNoSchedule, which discourages scheduling but allows it if no other node is available, and NoExecute, which evicts pods that are already running on the node. Taints are the mechanism Kubernetes uses to reserve nodes for special purposes, and tolerations are how a DaemonSet opts in to running on a tainted node.

The most important taint for DaemonSet authors is the control-plane taint. In a typical cluster, control-plane nodes carry the taint node-role.kubernetes.io/control-plane:NoSchedule, which keeps ordinary application pods off the machines that run the API server, etcd, and the scheduler. DaemonSets do not run on control-plane nodes unless you add a toleration for the control-plane taint. Whether you should add that toleration depends on the agent. A log collector or monitoring agent usually should run there, because control-plane logs and metrics are among the most valuable data in the cluster. An application-facing agent probably should not, because the control plane should stay reserved for cluster components.

Adding the toleration is a small block in the pod template, as shown in the Fluent Bit example above. The operator Exists form tolerates the taint regardless of its value, which is the usual choice for the control-plane taint because you want to tolerate the taint as it is defined rather than matching a specific value. You can scope the toleration with tolerationSeconds if you only want the pod to survive on a tainted node for a limited time, but for a DaemonSet that should run permanently on control-plane nodes, leave tolerationSeconds unset so the toleration has no expiry. Remember that a toleration is permission, not a command: it allows the pod onto the node, but the node selector and affinity rules still apply, so a DaemonSet with a nodeSelector that excludes control-plane nodes will not run there even with the toleration present.

Two other taints deserve attention because the DaemonSet controller handles them automatically. When a node stops reporting, Kubernetes taints it with node.kubernetes.io/not-ready or node.kubernetes.io/unreachable, and the DaemonSet controller automatically adds tolerations for both, with a toleration period of 300 seconds. This automatic toleration is why DaemonSet pods survive brief node outages instead of being evicted immediately, and it is one of the reasons DaemonSet pods are more resilient than ordinary pods during transient failures. You do not need to declare these tolerations yourself, and declaring them with a different tolerationSeconds value will override the default, so leave them alone unless you have a specific reason to change the grace period.

For the full reference on how taints and tolerations interact, including the built-in taints Kubernetes applies to nodes in special states, the official taints and tolerations documentation is the authoritative source.

Update Strategies: RollingUpdate vs OnDelete

Updating a DaemonSet means replacing the pod on every node with a new version, and the controller offers two strategies for doing it. RollingUpdate is the default: the controller updates pods one node at a time, waiting for each new pod to become ready before moving to the next node. OnDelete does nothing automatically: the controller leaves the old pods running until you delete them yourself, and only then creates the replacement pod with the new template. Choosing between them is a decision about how much control you want over the timing of the rollout.

RollingUpdate is the right choice for most DaemonSets, because it keeps the service running throughout the upgrade. The controller’s default behavior updates one node at a time, and you can speed it up with the maxUnavailable field, which sets how many nodes may have their DaemonSet pod unavailable during the update. Setting maxUnavailable to 1 is the cautious default, appropriate for a log collector where a brief gap on one node is acceptable but a gap on many nodes is not. Setting it to a higher number or a percentage, such as 25 percent, rolls the update out faster at the cost of more nodes temporarily without the agent.

OnDelete is the right choice when the update must happen at a moment you control, rather than the moment you apply the manifest. The classic case is a networking plugin, where replacing the agent mid-traffic could briefly disrupt pod connectivity, so the operator applies the new DaemonSet definition and then deletes pods node by node during a maintenance window, verifying connectivity after each one. Another case is a DaemonSet whose new version requires a node reboot, where the pod update must be coordinated with work outside Kubernetes. The trade-off is that OnDelete requires discipline: if you forget to delete the old pods, the new version never rolls out, and the cluster silently runs the old version indefinitely. Add a step to your change checklist that reminds you to trigger the rollout, and verify with kubectl rollout status after you start it.

Whichever strategy you choose, monitor the rollout the same way you would monitor a Deployment. The command kubectl rollout status ds/fluent-bit -n logging reports the progress of the update, and kubectl rollout history ds/fluent-bit -n logging shows previous revisions so you can roll back with kubectl rollout undo if the new version misbehaves. One difference worth remembering is that a failed DaemonSet rollout can leave some nodes on the new version and others on the old, so check the pod images across nodes before declaring the rollout finished.

DaemonSet vs Deployment vs Static Pods

DaemonSets, Deployments, and static pods all run containers on nodes, and the confusion between them is understandable, but they solve different problems and choosing the wrong one creates real operational pain. A Deployment runs a fixed number of replicas and spreads them across the cluster according to the scheduler. It is the right controller for applications that serve traffic, because you scale it by changing the replica count and you expose it through a Service. A DaemonSet runs one pod per eligible node and has no replica count. It is the right controller for node-level agents, because the number of pods is determined by the number of nodes rather than by a number you set.

The scaling difference is the clearest way to tell them apart. If demand grows and you need more capacity, you scale a Deployment up and the scheduler finds room for the new replicas. Scaling a DaemonSet is meaningless: the only way to get more DaemonSet pods is to add more nodes, and the only way to get fewer is to remove nodes or narrow the scope. If you catch yourself wanting to scale a DaemonSet, you almost certainly have a Deployment-shaped problem. Conversely, if you catch yourself writing a Deployment with an anti-affinity rule to force one replica onto every node, you have a DaemonSet-shaped problem and the anti-affinity hack will break the moment a node is added, because nothing will create a replica for the new node.

Static pods are the third option, and they are different in kind. A static pod is defined by a manifest file placed in a directory on a node, usually /etc/kubernetes/manifests, and the kubelet on that node runs it directly without any API server involvement. Static pods are how the control-plane components themselves are typically run in a kubeadm cluster, because the API server cannot manage its own pods before it exists. They are appropriate for bootstrapping the control plane, but they are a poor choice for anything else: there is no controller reconciling them, no rolling update, and managing them means managing files on every node individually.

The decision rule is simple enough to apply in a design review. Ask whether the work belongs to the node or to the service. Node work, meaning logging, monitoring, networking, storage drivers, and security agents, goes in a DaemonSet. Service work, meaning anything that handles requests, processes a queue, or runs a batch job, goes in a Deployment, a StatefulSet, or a Job. Bootstrapping work, meaning the components that must exist before the API server can manage anything, goes in static pods. When in doubt, the question to ask is what happens when a node is added: if the correct answer is that a new pod should appear automatically, it is a DaemonSet.

Frequently Asked Questions

Can a DaemonSet run more than one pod per node?

No, a DaemonSet runs exactly one pod per eligible node. The controller creates one pod for each node that matches the DaemonSet, and if a pod is deleted it is recreated on the same node. If you need multiple copies of an agent on a node, run them as separate containers in the same pod or as separate DaemonSets with different names and selectors.

Why is my DaemonSet not running on all nodes?

The most common causes are a nodeSelector or affinity rule that excludes some nodes, a taint on the node without a matching toleration, most often the control-plane taint, and a pod that cannot start because of insufficient resources or a failing image pull. Check kubectl get ds to compare desired and current counts, then kubectl describe ds for events, and kubectl get pods -o wide to see exactly which nodes are missing a pod.

What happens to DaemonSet pods when a node is drained?

DaemonSet pods are ignored by kubectl drain by default, because evicting them would break the one pod per node guarantee and the agents they run are usually needed during maintenance. You can force their eviction with the –ignore-daemonsets flag, but the controller will recreate the pod on the node as soon as the drain finishes, so the eviction is temporary by design.

How do I update a DaemonSet without downtime?

Use the default RollingUpdate strategy, which replaces pods one node at a time and waits for each new pod to become ready before moving on. Tune maxUnavailable to control how many nodes can be without the pod at once, and monitor the rollout with kubectl rollout status ds/<name>. For updates that need manual timing, switch to OnDelete and delete pods yourself during a maintenance window.

Can I use a DaemonSet for my application?

You can, but you usually should not. Applications are better served by a Deployment, which gives you a replica count, scaling, and a Service for load balancing. A DaemonSet is for node-level agents that must run everywhere, and using it for an application ties your capacity to your node count and removes the scaling and traffic management tools that Deployments provide.

Conclusion

DaemonSets are one of the simplest controllers in Kubernetes, and that simplicity is the point. By guaranteeing one pod per eligible node, they solve the problem of node-level services cleanly: log collectors, monitoring agents, and networking plugins are present on every node, appear automatically when a node joins, and disappear cleanly when a node leaves. Scoping, tolerations, and update strategies give you control without complicating the core idea.

If you are building or operating a cluster, start by listing the agents that must run on every node and check that each one is a DaemonSet. If you are still learning Kubernetes, the Kubernetes tutorial for beginners covers the core concepts this article builds on, and the Kubernetes Deployment YAML tutorial is the natural next step for understanding how DaemonSets differ from the controller you will use for your applications. The official DaemonSet documentation is the authoritative reference for the fields described here. Get the DaemonSet right and the invisible infrastructure of your cluster takes care of itself, node by node.

Scroll to Top