Sub topic 9
Resource requests and priority for node agents
This chapter assumes you can read a DaemonSet manifest, know what a Pod's resources block looks like, and understand that a node has a fixed amount of CPU and memory. Node agents run on every node, so a mistake in their resource settings repeats across the whole cluster.
Why agents need requests
A DaemonSet Pod is scheduled like any other Pod. The scheduler compares the Pod's requests with the node's allocatable capacity, which is the capacity left after the operating system and the kubelet take their share. If the requests don't fit, the Pod stays Pending on that node.
Requests also decide the Pod's quality of service (QoS) class:
| Settings | QoS class | Under node memory pressure |
|---|---|---|
| Requests equal limits for CPU and memory | Guaranteed | Evicted last |
| At least one request or limit set, not equal | Burstable | Evicted in the middle |
| No requests or limits | BestEffort | Evicted first |
An agent with no requests is BestEffort. It is the first Pod the kubelet evicts when memory runs low, which usually happens just when you need its logs or metrics.
Sizing the agent
The log agent from the earlier chapter uses this block:
resources:
requests:
cpu: 20m
memory: 32Mi
limits:
memory: 64Mi- The CPU request reserves a small share on every node. Because the Pod is replicated per node, 20m on a 100-node cluster reserves 2 CPU cores in total.
- The memory limit protects the node. If the agent leaks memory, the kernel kills the container at 64Mi (an OOM kill) before it harms neighbors.
- There is no CPU limit. A CPU limit throttles the agent during bursts, such as log spikes, and the agent then falls behind. Many teams set a CPU request and leave the limit off.
Measure real usage with kubectl top pod -n kube-system -l app=node-log-agent, which needs metrics-server. Then set the request near typical usage and the memory limit with headroom above the peak.
Priority and preemption
Requests alone don't guarantee a place on a full node. If application Pods already use all the allocatable room, a new agent Pod can't be scheduled, so that node has no agent.
A PriorityClass fixes this. It is a cluster-wide object that maps a name to an integer. When a Pod can't be scheduled, the scheduler may preempt (evict) Pods with lower priority to make room.
apiVersion: scheduling.k8s.io/v1
kind: PriorityClass
metadata:
name: node-agent-critical
value: 1000000
globalDefault: false
description: "Per-node agents that must run on every node."Reference it in the Pod template, not at the top level of the DaemonSet:
spec:
template:
spec:
priorityClassName: node-agent-criticalKubernetes ships two built-in classes for system components: system-cluster-critical and system-node-critical. The second has the highest value. Use them for cluster infrastructure such as networking and storage plugins. Create your own class for ordinary agents, with a value above your applications and well below the built-in ones.
Common errors
- No requests set. The agent is BestEffort and is evicted first under pressure.
- Memory limit too low. The container restarts with
OOMKilled. Checkkubectl describe podunder "Last State". - Requests too large. A big request on a small node leaves that node's Pod
Pending, andDESIREDno longer matchesREADY. - Unknown
priorityClassName. The Pod is rejected at creation. Create the PriorityClass first.
Exercise
A DaemonSet agent requests 200m CPU and 256Mi memory. The cluster has 50 nodes. How much CPU and memory does the agent reserve cluster-wide, and what happens on a node with only 100m CPU unreserved if the agent has the same priority as the existing Pods?
Show answer
It reserves 50 × 200m = 10 CPU cores and 50 × 256Mi = 12,800Mi (12.5Gi) of memory. On the node with 100m free, the request doesn't fit. Equal priority means nothing can be preempted, so the agent Pod stays Pending and that node has no agent. Fix it by lowering the request or by giving the agent a higher PriorityClass.