Kubernetes
DaemonSet
Scaling
DevOps
Cloud Computing

How to scale a Kubernetes DaemonSet to 0

Codemia Knowledge Hub ·

A DaemonSet has no replica count, so you cannot scale it the way you scale a Deployment. Its whole purpose is to run a pod on every matching node. To get it to zero pods without deleting it, change where its pods are allowed to schedule: taint the nodes and make sure the DaemonSet has no toleration for that taint.

A DaemonSet is a controller that ensures a specific pod runs on all or some nodes in a cluster. When a node joins, Kubernetes schedules the pod on it automatically. Typical uses are logging daemons, monitoring agents, and per-node network services such as proxies or firewalls.

Why take a DaemonSet to zero

You may need to stop the workload on every node while keeping the DaemonSet configuration:

  • Reducing resource usage during low traffic periods.
  • Debugging, testing, or redeploying updated DaemonSet configurations.
  • Preventing interference during critical operations or upgrades.

Steps with taints and tolerations

  1. Taint all nodes. A taint lets a node repel pods that do not have a matching toleration.
bash
   kubectl taint nodes --all key=value:NoSchedule

This taints every node with key=value and the NoSchedule effect, so no new pod without the matching toleration can be scheduled there.

  1. The toleration that matches the taint. A DaemonSet with this toleration can still schedule onto the tainted nodes, so this is the spec to remove (or keep, when you restore):
yaml
1   apiVersion: apps/v1
2   kind: DaemonSet
3   metadata:
4     name: my-daemonset
5   spec:
6     template:
7       spec:
8         tolerations:
9         - key: "key"
10           operator: "Equal"
11           value: "value"
12           effect: "NoSchedule"
  1. Remove the toleration. Without a toleration for the taint, the DaemonSet's pods are no longer scheduled, and the DaemonSet is effectively at 0.
  2. Verify that no pods from the DaemonSet are running:
bash
   kubectl get pods -o wide

If no pods belong to the DaemonSet, it is at 0.

Restoring the DaemonSet

When you want the pods back, remove the taint from the nodes and revert any changes you made to the DaemonSet spec:

bash
kubectl taint nodes --all key=value:NoSchedule-

Side effects to watch for

  • Other workloads: a NoSchedule taint on every node also blocks scheduling of other workloads that lack the toleration, which can affect the cluster if not handled.
  • Version compatibility: taints and tolerations have been available since Kubernetes 1.6.
  • Automation: script the tainting and toleration changes so they are applied and reverted consistently.

Quick reference

TopicDetails
ObjectiveScale DaemonSet to 0 at will
MethodUse taints and tolerations
Commands Involvedkubectl taint, kubectl get pods
ImpactRemoves scheduling of pods while maintaining DaemonSet config
RestorationRemove taints to resume normal operation
Version RequisiteKubernetes 1.6+
Automation PotentialHigh, scriptable task

Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design