Capacity and advanced scheduling
Calculate capacity from allocatable resources
A scheduler needs a node that can satisfy a Pod request, not simply a cluster with unused CPU in aggregate. Start with Node Allocatable, which reflects configured system reservations; subtract existing scheduled requests, including DaemonSet requests that consume allocatable resources. Do not subtract system reservations twice. For an ordinary Pod with no restartable init sidecars or Pod-level resources, use the larger of the sum of app container requests and the largest init request for each resource, then add Pod overhead when configured. Real accounting has additional rules for native sidecars and newer Pod-level resource features.
Node allocatable: 4000m CPU, 8192 MiBExisting requests: 2300m, 4096 MiBRemaining: 1700m, 4096 MiBNew Pod: 1500m + 100m overhead, 3072 MiBFits the two-resource gate; 100m CPU remains.Filter first, then rank nodes
Consider three nodes with remaining resources A: 2000m/2048 MiB, B: 1000m/4096 MiB, C: 1500m/3072 MiB. A Pod requesting 1200m and 3000 MiB fits only C, although aggregate capacity is much larger. This is resource fragmentation. The actual scheduler filters for hard constraints such as resources, taints, affinity and volume topology, then scores eligible nodes. NodeResourcesFit supports strategies including MostAllocated and RequestedToCapacityRatio for packing. A scheduler profile selects plugins and settings; the Pod schedulerName selects a matching scheduler profile where configured. Packing can leave whole nodes free, but spreading reduces concentration risk.
A fails memory; B fails CPU; C passes both.Scoring cannot rescue a node that failed filtering.Spread and prioritize intentionally
Topology spread can constrain how unevenly matching Pods are distributed among eligible domains. For two eligible zones with matching counts 2 and 1, adding a Pod to the smaller zone produces 2 and 2. A hard maxSkew of 1 with DoNotSchedule prevents adding to the larger zone in this simplified example. Real rules also depend on eligible domains, selectors, minDomains and node inclusion policies. PriorityClass affects queue priority and possible preemption. Preemption may remove lower-priority Pods to fit a higher-priority Pod; it is not guaranteed, and PDB protection is best effort during scheduler preemption. Non-preempting priority is an option when disruption is unacceptable.
topologySpreadConstraints: - maxSkew: 1 topologyKey: topology.kubernetes.io/zone whenUnsatisfiable: DoNotSchedule labelSelector: matchLabels: app: catalogRight-size using evidence
Requests are scheduling inputs, not measured utilization. CPU limits can throttle execution; memory pressure and limits can cause eviction or OOM termination through different mechanisms. Compare resource usage, throttling, working-set behavior, errors, latency and peaks over a representative workload. A smaller request can make packing easier but increase contention or alter HPA utilization calculations. Keep headroom for disruption and replacement. Model the loss of a node and verify the largest workload still fits a surviving eligible node; aggregate free resources alone are insufficient.
Request change: 1000m -> 750mAt 500m measured usage: 50% -> about 66.7% of requestHPA policy may react differently; verify before rollout.Practice and next step
Read nodes.json and capacity-cases.json in lab-fixtures/performance-capacity. Predict eligible nodes for four workload shapes, then test request overhead and topology cases. Explain why the output is a shortlist rather than a scheduling decision. Next: device resources, CPU placement and DRA.
python validate_offline.py # run in the extracted lab directoryFurther reading
- https://kubernetes.io/docs/tasks/administer-cluster/reserve-compute-resources/ — Node Allocatable and reserved resources
- https://kubernetes.io/docs/concepts/scheduling-eviction/pod-overhead/ — Pod infrastructure overhead
- https://kubernetes.io/docs/concepts/scheduling-eviction/resource-bin-packing/ — Resource scoring strategies
- https://kubernetes.io/docs/concepts/scheduling-eviction/scheduling-framework/ — Scheduler extension points and profiles
- https://kubernetes.io/docs/concepts/scheduling-eviction/pod-priority-preemption/ — Priority, preemption and disruption
- https://kubernetes.io/docs/concepts/scheduling-eviction/topology-spread-constraints/ — Topology spread constraints
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Capacity and advanced scheduling — knowledge check
Evaluate requests, bin packing and topology
Which resource quantity is the starting point for scheduling capacity?
Why can aggregate free resources be misleading?
What happens before node scoring?
Does scheduler preemption guarantee PDB preservation?
At 500m usage, lowering a CPU request from 1000m to 750m changes utilization relative to request to about what?