,

DaemonSet Resource Requests: Why One Size Doesn’t Fit

The problem: one request, many kinds of nodes A DaemonSet runs one pod on every node it targets and usually handles node-related work, such as shipping logs, exporting metrics, watching for security events, handling networking and so on. All of these pods are created from the same pod template, which means that every one of…

The problem: one request, many kinds of nodes

A DaemonSet runs one pod on every node it targets and usually handles node-related work, such as shipping logs, exporting metrics, watching for security events, handling networking and so on. All of these pods are created from the same pod template, which means that every one of them carries the same CPU and memory request regardless of the node it lands on. The scheduler reserves that request on every node, whether the pod actually needs it there or not. Since both the scheduler and the node autoscaler pack and provision nodes based on requests rather than usage, an oversized request becomes capacity that is paid for but not used, while an undersized one becomes CPU throttling or OOM kills on the nodes where the pod works hardest.

For some DaemonSets, a single request is a reasonable choice. A spot interruption handler watches one external signal per node and a node exporter mostly reads counters from the kernel, so their usage does not vary much between a 4-core node hosting 10 pods and a 96-core one hosting 60. However, many other DaemonSets behave differently: their usage varies with the node they run on and with what runs on it. What drives this variation differs from one workload to another. The relevant factors fall into two groups.

The first group is intrinsic to the node, i.e., it is fixed for as long as the node exists:

  1. The size of the node, i.e., its allocatable CPU and memory. Size is a proxy for the work a DaemonSet gets, useful mainly because it is easy to observe. Usage follows it only when the larger nodes actually host more or heavier workloads and, even then, rarely in a linear way.
  2. The class of the node, e.g., its instance type, family or generation. The class constrains the size of the node, but it also carries what size alone does not capture: the CPU architecture and generation, and the network and storage capabilities.

The second group depends on what is scheduled on the node, i.e., it changes over the lifetime of the node:

  1. The density of the node, i.e., the number of pods it hosts. A security monitor that keeps a record for every pod it watches and for the communication between them needs more memory on a node with more pods, regardless of the size of that node. Note that density does not always follow size: in one of our own clusters, the log shipping agent on an 88-core node running a single ClickHouse instance had less work to do than the same agent on medium nodes packed with many small pods.
  2. The behavior of the workloads on the node, e.g., how much they log or how many requests they serve. It is not determined by the other three: two nodes of the same size, class and density can generate very different loads for the same log shipper.

The first group is known when a pod is scheduled and does not change afterwards. The second group is where the work actually comes from and it can only be observed by measuring, because it keeps changing while the node is running. Which factor matters differs from one DaemonSet to another and, in most cases, it is a combination of them, often in a nonlinear way. Either way, a single request for every pod is necessarily a compromise.

This limitation is built into the DaemonSet API. For a Deployment, the same request for every pod is the right call: the replicas are interchangeable, the traffic is spread across them and the scheduler picks a node for each pod only after its request is known. A DaemonSet pod is not interchangeable. It is bound to one particular node and usually does work related to that node, yet its pod template has no way to express a request that depends on that node.

Figure 1. Illustrative view of DaemonSet usage variance with respect to the node

Workload autoscalers inherited the same limitation. The Kubernetes Vertical Pod Autoscaler aggregates the usage of all the pods of a workload and applies one recommendation to every one of them. Our own workload autoscaler does the same by default. Size it for the busiest node and the request sits mostly unused everywhere else while you still pay for the reservation. Size it for a typical node and the pods on busy nodes get throttled, OOM killed or evicted, which is when you need their logs, metrics or security events the most.

The request of each DaemonSet looks small on its own but all of them are reserved on every node and together they end up taking a sizeable share of it. Across the clusters connected to Cast AI, the median cluster runs 9 DaemonSets that have pods (logging, metrics, security, networking, storage drivers) and one in ten runs 14 or more, each reserving its request on every node. On small nodes the combined reservation is a larger share of the capacity. In the extreme case a request sized for the large nodes does not fit in the room left on the smallest ones. The pod stays Pending and the node runs without it or, if the DaemonSet has a higher priority class than the workloads already there, the scheduler preempts them to make room.

So the real question is not only “what is the right request for this DaemonSet?”, but “what is the right request for this DaemonSet on this particular node?”. Answering it starts with understanding how each DaemonSet’s usage actually depends on the node, which is what the next sections look at.

How teams work around it today

Since Kubernetes offers no way to size a DaemonSet pod per node, teams end up working around the limitation. Each of the common workarounds either accepts the compromise from the previous section or moves the per-node decision to the people operating the cluster:

  1. Sizing for the worst case. The request is set for the busiest node while accepting the oversize request on every other node, choosing stability over cost. The workload autoscaler stays in read-only mode for DaemonSets and the number is whatever the worst case was on the day someone measured it.
  2. Setting a low request or none. The request is kept small or left out and the pod relies on limits or spare capacity on the node to get what it needs. This is the opposite choice to the first case, cost over stability. Nothing is reserved on the quiet nodes but the usage does not go away. It is invisible to the scheduler and the node autoscaler, which place workloads and provision nodes as if that capacity were free, and nothing sizes the pod from what it actually uses. On a busy node the pod is throttled when CPU runs short and is among the first to be evicted when memory does, which is when its logs, metrics or security events matter most.
  3. Rightsizing to the fleet average. A workload autoscaler aggregates the usage of all the pods and applies one recommendation to every one of them. Compared to the worst case it lowers the cost and follows the usage over time, but the request is still too large for the quiet nodes and now too small for the busy ones.
  4. One DaemonSet per node class. The DaemonSet is split into several copies, each with its own request and pinned through a node selector to one group of nodes, either a size tier such as small, medium and large or another combination of node properties. Since every copy is a separate workload, a workload autoscaler can size each one from its own usage. The limitation is the granularity. With a few coarse groups, each group still covers nodes with different usage, so its request is again a compromise, only a narrower one. Increasing the resolution means more groups, and every group is another copy whose selectors someone has to define and keep correct and which has to be upgraded and configured separately, so the operational cost grows with every step.

A mutating webhook or a policy engine can also set a different request per node at admission. It only applies a value though. Someone still has to decide what the value should be for each kind of node and keep deciding it as the usage changes.

Splitting per node class is the right idea: it keys the request on a property of the node that is known when a pod is scheduled. What holds it back is that every group is another copy of the DaemonSet. Finer groups, e.g., one per instance type, would follow the actual usage more closely, but they mean dozens or even hundreds of copies of the same workload to review, upgrade and keep in sync, while a node autoscaler that chooses from a wide range of instance types keeps bringing in new types as prices, availability and generations change. Wherever the values are picked by hand, they are also snapshots: someone measures once and picks a number while the cluster keeps changing around it. What is needed is one request per kind of node, with the kind defined by whichever node property fits the DaemonSet, computed only from the usage of the pods running on that kind of node, kept up to date continuously and without turning one DaemonSet into many copies. That is the problem we set out to solve.

How we approached it

Our first answer to the problem was deliberately simple and shipped fast. Its limits then defined the two data-driven approaches we evaluated next.

A first step: a share of the node

The first version, available today as node-aware DaemonSet sizing, expresses the request of a DaemonSet as a percentage of the allocatable CPU and memory of the node its pod lands on. Since a DaemonSet pod is pinned to its node before it is admitted, the admission webhook of our workload autoscaler reads the node, computes request = allocatable * percentage, clamps the result to the configured minimum and maximum and writes it into the pod. We shipped it first for three reasons: it needs no usage history, it is simple to reason about and the node autoscaler can predict the request of the DaemonSet on a node that does not exist yet, since it already plans nodes with the allocatable capacity of every candidate instance type.

It works, but it is a guess with three structural limitations:

  1. The percentage is picked by hand. Someone chooses it per DaemonSet, it does not come from the usage and it does not follow the usage when it changes, which makes it exactly the kind of snapshot described in the previous section.
  2. It assumes that usage is proportional to size. Apart from the optional minimum and maximum, which only bound the result, the request is strictly proportional to the allocatable capacity of the node: doubling the node doubles the request. That matches a DaemonSet only when its usage grows the same way, with no base usage that is there regardless of the node.
  3. It ignores density and workload behavior. In one production fleet, an eBPF-based observability tool used about the same CPU on a 16-core node running 16 application pods as on a 32-core node running a single one. The percentage sees only the size, so it gave the larger node twice the request.

In short, a percentage replaces one guessed number with another, scaled by the size of the node, which is only a proxy for what drives the usage. Against the requirements from the previous section, it keeps one DaemonSet as one workload and gives a request per node size, but the kind of node is always its size and the request is neither computed from the usage nor kept up to date with it.

Two data-driven approaches

The natural next step is to derive the request from the observed usage instead of guessing it, and there are two obvious ways to do it:

  1. Linear regression on node property. For every DaemonSet, fit a line, usage = slope * node_dimension + intercept, where the dimension is the size of the node or its pod count, and read the request off that line for any node. If a log collector uses 50m, 100m, 150m and 200m on progressively larger nodes, the line gives its request on every other node size, including the ones never observed. This is basically the percentage approach with the slope learned from the data and an intercept for the base overhead. It is cheap to compute and store and easy to implement, but it has three weaknesses: it is valid only if the usage actually grows linearly with the dimension, the right dimension has to be found and validated for every DaemonSet and it fails when the usage is driven by something other than the fitted dimension, e.g., the behavior of the workloads on the node.
  2. Size tiers on node property. Group the nodes into fixed tiers, e.g., up to 4, 4 to 16, 16 to 32, 32 to 48, 48 to 64 and above 64 cores or by memory/pod count, and use the observed usage of the pods in each tier as the recommendation for that tier. Tiers handle step-like and nonlinear relationships, assume no relationship between the tiers and never extrapolate, because each tier uses only what was observed in it. On the other hand the boundaries change the result considerably and neither way of choosing them is satisfactory. Fixed, human-friendly tiers are the same everywhere but leave some tiers with too few nodes for a reliable recommendation. Tiers derived from the data, e.g., from the percentiles of node size, give every tier enough nodes but follow the distribution of the fleet they were derived from, so they mean something different in each fleet and have to be recomputed when the node mix changes. Tiers also inherit the dimension problem of the first approach, since they are still defined over one property of the node and more tiers fit the data better only until they start to overfit.

Both approaches meet most of the requirements from the previous section: they compute the request from the usage, keep updating it as the usage changes and keep one DaemonSet as one workload. What they fix in advance is the definition of a kind of node. Like the percentage, both bet that a single numeric property of the node, its size or its pod count, predicts the usage of a DaemonSet well enough to size it from, the scaling function also betting on a straight line and the tiers on boundaries that hold across DaemonSets and fleets. Before building either, we checked that bet against production data.

Testing the bet: does a node property predict usage?

The percentage, the scaling function and the size tiers all bet that a property of the node predicts how much a DaemonSet uses on it. We tested that bet the way any predictive model is tested, in two steps: first we explored how much of the variation in usage each property explains, then we validated the candidates on nodes they had never seen.

The testbed

We used 7 days of usage from 92 production clusters, the largest by CPU requests among the clusters connected to Cast AI. The large clusters give enough nodes and pods per DaemonSet to test grouping, but they are also likely to have more instance types than average, so the gains may be larger than in smaller clusters. For every pod of a DaemonSet we took its CPU usage at the 95th percentile and its maximum memory, together with the allocatable capacity of its node and the node’s labels, which include the instance type. We kept only the pods that ran at least half as long as the longest-running pod of their DaemonSet. This removes the pods that were recreated by rollouts or ran on short-lived nodes and so saw only part of the usage of their DaemonSet, and only the DaemonSets with at least 20 such pods on at least two instance types. Everything was computed per container of a DaemonSet within one cluster, which is also how our workload autoscaler computes a recommendation. This left 1,374 DaemonSet containers and about 215,000 pods.

Step 1: exploring with Rยฒ

For every DaemonSet, the first question is how much of the difference in usage between its pods is explained by a node property. This is exactly what the coefficient of determination measures:

R2=1โˆ’โˆ‘i(yiโˆ’y^i)2โˆ‘i(yiโˆ’yโ€พ)2R^2 = 1 – \frac{\sum_i (y_i – \hat{y}_i)^2}{\sum_i (y_i – \bar{y})^2}

where
yแตข is the usage of pod i,
ลทแตข is the usage predicted for pod i from its node,
ศณ is the average usage of all pods, i.e., one request for every pod.

For a line, ลทแตข is read off the fitted line at the size of the pod’s node. For a grouping, e.g., by instance type, ลทแตข is the average usage of the pod’s group. In short, Rยฒ tells how much better a property is than one number for all pods: 0 means no better and 1 means it explains all the variance.

The exploration pointed in one direction. Instance type explained the most, with a median Rยฒ of 0.66 for CPU and 0.60 for memory, against 0.28 and 0.31 for size tiers and 0.19 and 0.20 for a line on the size of the node (medians over the DaemonSets whose usage varies, see below). However, these numbers are measured on the same pods the averages were computed from, and on those pods a finer grouping always scores higher: a group per pod would explain everything. The exploration tells us where to look, not what works.

Step 2: validating on nodes we have not seen

The real task is to predict the usage of a pod on a node we have not measured yet, which is what happens every time a new node joins the cluster. To reproduce it, we split the nodes of every DaemonSet into five folds, computed every recommendation from the pods on four of them and predicted the pods on the fifth, then repeated the process until every node was held out once (5-fold cross-validation grouped by node). A tier or a group with fewer than three pods in the training folds falls back to one request for all pods, just as a recommendation without enough data does.

For the held-out pods we measure two errors:

typical error=meanโก(|yiโˆ’y^i|)meanโก(yi)\text{typical error} = \frac{\operatorname{mean}\left(\lvert y_i – \hat{y}_i \rvert\right)}{\operatorname{mean}(y_i)}
Rnew nodes2=1โˆ’โˆ‘i(yiโˆ’y^i)2โˆ‘i(yiโˆ’y^train)2R^2_{\text{new nodes}} = 1 – \frac{\sum_i (y_i – \hat{y}_i)^2}{\sum_i (y_i – \hat{y}_{\text{train}})^2}

where
ลทtrain is the average usage of the training pods

The typical error is the one to read: it is the average miss as a share of the DaemonSet’s average usage. It uses absolute differences, so a single extreme pod does not dominate it, and it is relative, so a DaemonSet that uses 10m and one that uses 2 cores count the same. The second one is the same Rยฒ as in the exploration, computed on the new nodes and against one request for everyone, so the two steps compare directly. Its squared differences weigh the large misses more, which are the ones that end in throttling, OOM kills or capacity paid for but not used.

What we found

Most DaemonSets do not need a request per node. For 57% of the DaemonSet containers (58% for memory), the standard deviation of the usage across pods is below 20% of its average. One request already fits them.

For the other 591 (580 for memory), the results on new nodes are the following (median over DaemonSets):

ApproachCPU typical errorCPU error reduction vs one requestMemory typical errorMemory error reduction vs one request
One request for all pods35%N/A25%N/A
Best-fit percentage of allocatable capacity of the node51%-9%53%-62%
Linear regression on allocatable capacity of the node29%10%21%12%
Size tiers29%14%20%20%
Instance type25%29%19%25%
Best label for each DaemonSet25%30%19%29%

Note: The table measures how well each approach fits the usage and not how much is saved, since the savings depend on how a request is derived from the prediction, e.g., which percentile and how much headroom.

Figure 2. Error reduction against one request for all pods, per DaemonSet whose usage varies.
Boxes show the 25th to 75th percentile, whiskers show the 10th to 90th percentile, while the line shows the median. Values below 0 mean the approach was worse than one request.

The error reduction is the median of the per-DaemonSet reductions against one request for all pods, so it can differ from the change between the medians in the error columns. Grouping by instance type cuts the typical error by 29% for CPU and 25% for memory. Size tiers and the linear regression help less, while the percentage is worse than one request for all pods: even with the best possible percentage, a line through zero cannot represent a usage that has a base part independent of the node. On a smaller dataset from 31 clusters, where we also captured the number of pods per node, a line on the pod count barely improved on one request for the typical DaemonSet.

The validation also shows how much the exploration overstated, see the table below:

ApproachRยฒ in exploration (CPU / memory)Rยฒ on new nodes (CPU / memory)
Instance type0.66 / 0.600.27 / 0.26
Size tiers0.28 / 0.310.13 / 0.20
Linear regression on allocatable capacity0.19 / 0.200.16 / 0.16

The finer the grouping, the bigger the drop, exactly as expected, yet instance type stays the best single key. The ranking also holds when we keep the short-lived pods in: instance type still cuts the typical error by 23% for CPU and 25% for memory.

Compounding the gains: from errors to requests

The typical error measures how close a recommendation gets to the typical pod, but a request is not sized from the typical pod. Our default policy sizes memory from the maximum usage plus 20% and CPU from the 90th percentile plus 5%, so a single request has to cover the heaviest pods of the whole DaemonSet, while a group only has to cover its own. This is where the gains compound: a moderate improvement in the typical error turns into a much larger change in the requests.

The OpenTelemetry Collector in one of our own clusters shows it well. At the time of writing, it runs 83 pods on 24 instance types. With one request for all of them, every pod gets 2.27 GiB of memory, sized for the heaviest pod of the DaemonSet. With a group per instance type, each group gets its own peak plus 20%, and the memory requested across the 83 pods drops from 188 GiB to 39 GiB, almost 5 times less.

Figure 3. Scoped vs Unscoped view of memory recommendations per pod in GiB

CPU goes the other way. The 90th percentile across all pods is 0.04 cores, but the busiest collectors used between 0.5 and 0.7 cores every day of the past week. Their groups now get between 0.5 and 0.6 cores. No collector was throttled, since they run without a CPU limit, so what the single value hid was under-declaration: these pods consumed 0.5 to 0.7 cores while requesting 0.037. They borrowed capacity from their neighbors, which made the node look emptier than it was to the scheduler and to any cost model that prices requests.

Figure 4. Scoped vs Unscoped view of CPU recommendations per pod in GiB

One request therefore oversizes memory almost everywhere and undersizes CPU exactly where the collector works hardest.Figure 5. Instance type scoped recommendation distribution of OpenTelemetry collector in one of Cast AI production clusters.

Figure 5. Instance type scoped recommendation distribution of OpenTelemetry collector in one of Cast AI production clusters.

What the data does not show

The testbed has limits. It covers the largest clusters and we did not test smaller ones. It keeps only the DaemonSets that run on at least two instance types, which is where grouping can help at all, so the 57% describes this subset and not all DaemonSets. It spans 7 days, i.e., one weekly cycle, which misses monthly peaks, and the split is across nodes and not across time, so it says nothing yet about how long a recommendation stays valid. Finally, both errors are symmetric: they count an oversized and an undersized request the same, although an undersized request costs reliability and an oversized one costs money.

Resolution against data per group

The trade-off behind these numbers is resolution against data per group. A finer grouping can follow the usage more closely but each group holds fewer pods, so its average is noisier and a new group has no history at all. This is why the gap between exploration and validation grows with the number of groups.

Why flexibility

The most important result is that no grouping wins everywhere. When every DaemonSet picks the label that fits it best, decided on the training pods only, instance type wins for 29% of the DaemonSets that vary, size tiers for 28%, the instance family for 25% and the number of CPUs for 13%, while for 5% none of them beats one request (for memory, size tiers lead with 33%). Size tiers, however, exist as a label only if the nodes of a cluster are labeled that way. Instance type is still a strong default: when another label wins, instance type is usually right behind it, with a median gap below 1% of the error of one request. Yet for 9% of the DaemonSets that vary (12% for memory), another label is clearly better, i.e., by more than a tenth of the error of one request.

In short, no single grouping is best for every DaemonSet. Instance type is the best single key and the one to start from but for about one in ten of the DaemonSets that vary another label is clearly better, and choosing the label per DaemonSet adds only a little at the median. Searching every property of every node for the best partition per DaemonSet is not an option either, since the finer the partition the less data each group has. What we can rely on is the classification every node already carries and which is known before its pods are admitted: its labels. That is why we let a node label define the groups and compute the request of every group from the usage measured in it, which is what scoped recommendations do.

The solution: Scoped DaemonSet Recommendations

The measurements lead to a simple idea: stop trying to derive a rule that works for every DaemonSet and let the grouping be configured instead. Scoped recommendations partition the observed usage of a DaemonSet by the values of a node label and compute one recommendation per such value. The DaemonSet remains a single workload with a single recommendation object, which contains both the per-group recommendations and the unscoped one used as fallback.

Curious to see how it works? Move on to part 2 to learn what we just launched.

Cast AI โ€บ Blog โ€บ DaemonSet Resource Requests: Why One Size Doesn’t Fit