how to scale kubernetes daemonset to 0?
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Scaling a Kubernetes DaemonSet to 0 is a task that can be useful for situations where the workloads managed by the DaemonSet are temporarily not needed, or when you want to conserve resources. This article delves into the technical steps, considerations, and implications of scaling a DaemonSet to 0, along with examples to provide clarity.
Understanding DaemonSets
A DaemonSet in Kubernetes is a controller that ensures a specific pod is running on all or some nodes in a cluster. When a new node is added, Kubernetes automatically schedules the defined pod to run on it. Typical use cases include deploying logging daemons, monitoring agents, or network services like proxies or firewalls on each node.
Why Scale a DaemonSet to 0?
There might be scenarios where you need to temporarily halt the workloads running on every node without deleting the DaemonSet configuration. Some common reasons include:
- Reducing resource usage during low traffic periods.
- Debugging, testing, or redeploying updated DaemonSet configurations.
- Preventing interference during critical operations or upgrades.
Technical Considerations
Scaling a DaemonSet is not directly supported since the very purpose of a DaemonSet is to ensure that a pod runs on every node. However, by leveraging tolerations and node selectors, we can effectively scale the DaemonSet pods down to 0. Here are the technical steps involved:
Step-by-Step Guide
- Add a Taint to All Nodes: Taints are applied to nodes and allow a node to repel a set of pods without a matching toleration.
This command will taint all nodes with key=value and a NoSchedule effect, preventing any further scheduling of pods without the necessary toleration.
- Update DaemonSet with Toleration: Modify the DaemonSet to include a toleration that matches the taint. Once this is active, the pods will not be scheduled due to the presence of the taint.
- Remove the Toleration Temporarily: Without the toleration, the pods will be unscheduled and, effectively, the DaemonSet will scale to 0.
- Verify the Changes: Use the following command to verify that no pods from the DaemonSet are currently running:
With no running pods associated with the DaemonSet, it's successfully scaled to 0.
Restore to Original State
When you're ready to resume operations, remove the taint from the nodes and revert any changes made to the DaemonSet spec.
Additional Considerations
- Impact on Node Resources: Be aware that once taints are applied, it can prevent necessary scheduling of other workloads if not properly handled, potentially affecting cluster operations.
- Version Compatibility: Ensure that the Kubernetes version in use supports the required taint and toleration features, typically available since Kubernetes 1.6.
- Automated Scripts: Consider writing scripts to automate the tainting and toleration process for efficiency and accuracy.
Summary Table
| Topic | Details |
| Objective | Scale DaemonSet to 0 at will |
| Method | Use taints and tolerations |
| Commands Involved | kubectl taint, kubectl get pods |
| Impact | Removes scheduling of pods while maintaining DaemonSet config |
| Restoration | Remove taints to resume normal operation |
| Version Requisite | Kubernetes 1.6+ |
| Automation Potential | High, scriptable task |
Scaling a Kubernetes DaemonSet to 0 involves using Kubernetes' built-in mechanisms effectively, allowing you to manage resources efficiently while retaining the ability to quickly revert to full operational status as needed. This approach ensures optimal management of node resources and reduces the manual overhead involved in operational tasks.
Related reading
- How to schedule pods restart
- How to scrape metrics-server to prometheus outside kubernetes cluster
- How to see logs of terminated pods
- How to see Pod logs a container name must be specified for pod... choose one of wait main
- How to scan between date range using Lambda and DynamoDB?
- How to schedule tasks on SageMaker
- How to search for plain text in cloudwatch logs insights?
- How to see all running Amazon EC2 instances across all regions?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.