Scheduling and nodesLesson 10 of 10
- Requests, limits and quotas, not reconciled
- QoS classes and node-pressure eviction, not reconciled
- cgroups, memory pressure and the OOM killer, not reconciled
- How the scheduler places a pod, not reconciled
- Affinity, taints and tolerations, not reconciled
- Topology spread constraints, not reconciled
- Priority and preemption, not reconciled
- Nodes and the kubelet, not reconciled
- Disruptions and PodDisruptionBudgets, not reconciled
- Cluster autoscaling, not reconciled
Cluster autoscaling
Node autoscalers add nodes when pods cannot be scheduled and remove nodes whose pods fit elsewhere. Cluster Autoscaler resizes node groups; Karpenter launches the instance each batch of pods needs.
Shows the lesson one block at a time. Arrow keys step, number keys jump to a scene, and Escape returns to the page where you were.
A cluster with a fixed set of nodes forces a choice between paying for capacity it rarely uses and running out of capacity when it matters. Node autoscalers remove the choice: they add nodes when pods have nowhere to run and remove nodes whose pods could run elsewhere. Kubernetes itself has no built-in node autoscaler. SIG Autoscaling sponsors two, Cluster Autoscaler and Karpenter, and both talk to a cloud provider to create and delete the machines behind nodes.
Reconcile, in 7 scenes
The trigger
unschedulable podA pod the scheduler tried and failed to place. ItsPodScheduled condition is False with reason Unschedulable, and a FailedScheduling event says why.
Node autoscalers start from pods, not from graphs. A cluster at 95% CPU usage with every pod running gets no extra node, because nothing is waiting. A cluster at 10% usage gets one the moment a pod requests more CPU than any node has free. Autoscalers compare requests with allocatable, the same arithmetic the scheduler uses, and ignore measured usage in both directions.
That has three consequences. Requests have to be honest, because they are all the autoscaler sees. Something has to create the pods that need capacity, which is the horizontal pod autoscaler’s job, covered at the end. And a pod that is Pending for a reason no added node can fix, such as a node selector that matches no node group or a volume pinned to a zone the autoscaler cannot create nodes in, stays Pending; a good autoscaler recognises that and does not add nodes that would not help.
Cluster Autoscaler’s FAQ also warns against running it alongside a CPU-usage-based autoscaler on the same node groups, such as a cloud instance group autoscaler. The two make conflicting decisions about the same machines.
Cluster Autoscaler
node groupA set of identical machines that scales as a unit, such as a cloud auto scaling group. Every machine in it has the same capacity and labels.Cluster Autoscaler works on node groups you define in advance. Every 10 seconds by default (--scan-interval) it looks for unschedulable pods. For each node group it builds a template node, a picture of what another machine from that group would look like, and runs a simplified copy of the scheduler to ask whether the pending pods would fit on it. If more than one group would help, an expander chooses:
| Expander | Picks the group that |
|---|---|
least-waste (default) | Leaves the least idle CPU, then memory, after scale-up |
most-pods | Schedules the most pending pods |
least-nodes | Adds the fewest nodes |
priority | Has the highest user-assigned priority |
random | Any helpful group |
price | Costs least; works only on GCE, GKE and Equinix Metal |
Expanders can be chained since Cluster Autoscaler 1.23, for example --expander=priority,least-waste, where each one narrows the choice for the next. The default has not always been least-waste (early releases used random), so check the flag reference for the release you run. A grpc expander lets an external service decide.
Cluster Autoscaler then increases the group’s desired size and waits. It expects the added node to register within 15 minutes (--max-node-provision-time); if it does not, Cluster Autoscaler stops counting on it and may try another group. Registering the node is not its job: the machine’s boot process joins it to the cluster.
Two operational rules come from its design. Run the Cluster Autoscaler release whose minor version matches the cluster’s Kubernetes minor, because it embeds scheduler code from that release; for a 1.37 cluster that is a 1.37.x release. And it supports leader election, on by default with --leader-elect, so you can run several replicas with one active. With a single replica, a lost pod pauses scaling decisions until it is rescheduled; running nodes and pods are unaffected.
Karpenter
Karpenter skips the node group. It watches pending pods, adds up their requests and constraints (node selectors, affinity, tolerations, topology spread, volume zones), and launches a machine that fits them, choosing the instance type, size, zone and capacity type for that batch of pods. The upstream comparison puts it as auto-provisioning: you describe the limits of what may be launched instead of defining every shape in advance.
Karpenter is published by the Kubernetes project as a library that cloud providers build on; AWS and Azure ship implementations. Its core APIs are stable at v1:
- NodePool (
karpenter.sh/v1) describes what Karpenter may launch:requirementson node labels such as architecture, zone and capacity type,taints, anodeClassRefto the provider’s node class, resourcelimitsfor the whole pool, and adisruptionblock. - NodeClaim (
karpenter.sh/v1) is Karpenter’s record of one machine it launched or is launching, owned by a NodePool and paired with exactly one Node. - A node class holds provider-specific settings such as images and networks. Its kind and API group come from the provider, which is why
nodeClassRefnames agroup,kindandname.
apiVersion: karpenter.sh/v1
kind: NodePool
metadata:
name: default
spec:
template:
spec:
nodeClassRef:
group: karpenter.k8s.aws
kind: EC2NodeClass
name: default
requirements:
- key: kubernetes.io/arch
operator: In
values: ["amd64", "arm64"]
- key: karpenter.sh/capacity-type
operator: In
values: ["spot", "on-demand"]
expireAfter: 720h
limits:
cpu: "1000"
disruption:
consolidationPolicy: WhenEmptyOrUnderutilized
consolidateAfter: 30s
budgets:
- nodes: "10%"
Karpenter’s scope is wider than scaling. It replaces nodes that have drifted from their NodePool or node class (for example after an image update), expires nodes after expireAfter, 720 hours by default, and repairs unhealthy nodes when that feature is enabled. All of these are disruptions, and they go through the same controls as scale-down.
Scale-down and consolidation
Removing nodes is where autoscaling causes disruption, so both autoscalers are careful about it, and both reason only about requests.
Cluster Autoscaler considers a node unneeded when its pods’ CPU and memory requests are below 50% of allocatable (--scale-down-utilization-threshold), every pod on it could be placed on another node, and the node is not annotated cluster-autoscaler.kubernetes.io/scale-down-disabled: "true". After a node has been unneeded for 10 minutes (--scale-down-unneeded-time), Cluster Autoscaler taints it, evicts its pods through the Eviction API and deletes it. By default it removes non-empty nodes one at a time and empty nodes in batches of up to 10.
Karpenter calls this consolidation and sets it per NodePool:
consolidationPolicy: WhenEmptyOrUnderutilized, the default, considers every node and removes or replaces it whenever the pods would fit more cheaply elsewhere, including on a smaller replacement node.WhenEmptyremoves only empty nodes: nodes whose pods have no disruption cost, such as DaemonSet pods and pods annotated as cheap to disrupt.Balancedconsiders the same nodes asWhenEmptyOrUnderutilizedbut acts only when the savings are large enough to justify the disruption.consolidateAfteris how long a node must go without a pod being added or removed before it becomes a candidate,0sby default;Neverturns consolidation off.
Before deleting a node, Karpenter checks the NodePool’s disruption budget and simulates where the node’s pods would go. It then taints the node karpenter.sh/disrupted:NoSchedule, launches any replacement the simulation calls for and waits for it to be ready, and only then drains the node through the Eviction API.
What stops a node from being removed:
- Pods whose PodDisruptionBudget allows no disruption.
- Pods no controller owns, which would not come back. Cluster Autoscaler also refuses pods with local storage, and
kube-systempods without a budget, unless they are annotatedcluster-autoscaler.kubernetes.io/safe-to-evict: "true". - Pods that cannot fit anywhere else, because of resources, node selectors, affinity or host ports.
- Opt-outs:
cluster-autoscaler.kubernetes.io/safe-to-evict: "false"on a pod for Cluster Autoscaler, andkarpenter.sh/do-not-disruptfor Karpenter.
Disruption controls
Three layers limit churn, from the workload up to the cluster.
PodDisruptionBudgets are the application owner’s control and both autoscalers respect them, because both drain with the Eviction API. Karpenter goes further and avoids choosing a node for voluntary disruption at all if any pod on it has a blocking budget.
karpenter.sh/do-not-disrupt on a pod works like a single-pod blocking budget for Karpenter’s voluntary methods. The value "true" protects the pod for its whole life; a duration such as "30m" protects it for that long after it starts. Use it for work that loses everything if interrupted, such as a long training job. The annotation keeps a node out of consolidation, but it does not stop forceful methods (expiration, interruption and manual node deletion) from selecting the node. During their drain Karpenter still does not evict the annotated pod, so the node cannot finish terminating until the pod reaches Succeeded or Failed, the annotation’s duration elapses, or the NodeClaim’s terminationGracePeriod runs out.
apiVersion: batch/v1
kind: Job
metadata:
name: train
spec:
template:
metadata:
annotations:
karpenter.sh/do-not-disrupt: "true"
spec:
restartPolicy: Never
containers:
- name: train
image: busybox:1.37
command: ["sh", "-c", "sleep 3600"]
NodePool disruption budgets are the platform’s control. spec.disruption.budgets caps how many of a pool’s nodes Karpenter may disrupt at once, as a count or a percentage; the default is a single budget of nodes: 10%. Budgets can apply only to some reasons (Empty, Underutilized, Drifted, Unhealthy) and only during a cron schedule for a duration, which is how you freeze consolidation during business hours while still allowing it at night.
Protection needs a limit, or one stuck pod pins a node forever. The NodeClaim’s terminationGracePeriod caps how long a drain may take; when it expires, remaining pods are deleted even if a budget or do-not-disrupt was holding them. Karpenter’s documentation recommends setting it whenever expireAfter is set and pods use do-not-disrupt.
Headroom
An added node takes minutes to boot and join. Pods that must start in seconds cannot wait for that, so clusters keep spare capacity ready, and the standard trick uses priority. Run placeholder pods at a priority below everything else. They reserve capacity by their requests. When a real pod arrives and nothing fits, the scheduler preempts a placeholder and the real pod starts immediately. The placeholder’s replacement goes Pending, and that Pending pod triggers the autoscaler to add a node, restoring the buffer for the next arrival.
The class needs two properties. Its value must sit below every real workload, so that any ordinary pod at priority 0 or higher can preempt a placeholder. And preemptionPolicy: Never stops a Pending placeholder from displacing anything to win its capacity back.
Save this as headroom.yaml:
apiVersion: scheduling.k8s.io/v1
kind: PriorityClass
metadata:
name: headroom
value: -10
preemptionPolicy: Never
description: "Placeholder pods that hold spare capacity for real work."
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: headroom
spec:
replicas: 3
selector:
matchLabels:
app: headroom
template:
metadata:
labels:
app: headroom
spec:
priorityClassName: headroom
terminationGracePeriodSeconds: 0
containers:
- name: hold
image: busybox:1.37
command: ["sh", "-c", "sleep infinity"]
resources:
requests:
cpu: "2"
memory: 1Gi
Then an api Deployment with one replica requesting 2500m CPU, which fits on no worker while the placeholders hold 2 CPUs each:
kubectl apply -f headroom.yamlpriorityclass.scheduling.k8s.io/headroom created deployment.apps/headroom createdkubectl get pods -o wideNAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES headroom-7c5f94d7bd-mfqhl 1/1 Running 0 15s 10.244.3.2 kx-worker3 <none> <none> headroom-7c5f94d7bd-trkwr 1/1 Running 0 15s 10.244.1.2 kx-worker <none> <none> headroom-7c5f94d7bd-wgh9z 1/1 Running 0 15s 10.244.2.3 kx-worker2 <none> <none>kubectl apply -f api.yamldeployment.apps/api createdkubectl get pods -o wideNAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES api-758f67dc69-7zhtz 1/1 Running 0 15s 10.244.1.3 kx-worker <none> <none> headroom-7c5f94d7bd-j9v8k 0/1 Pending 0 15s <none> <none> <none> <none> headroom-7c5f94d7bd-mfqhl 1/1 Running 0 30s 10.244.3.2 kx-worker3 <none> <none> headroom-7c5f94d7bd-wgh9z 1/1 Running 0 30s 10.244.2.3 kx-worker2 <none> <none>kubectl get events --field-selector reason=PreemptedLAST SEEN TYPE REASON OBJECT MESSAGE 15s Normal Preempted pod/headroom-7c5f94d7bd-trkwr Preempted by pod 6c27c5a1-7c49-4e0d-835d-bdac1486fa07 on node kx-workerkubectl get events --field-selector reason=FailedSchedulingLAST SEEN TYPE REASON OBJECT MESSAGE 15s Warning FailedScheduling pod/api-758f67dc69-7zhtz 0/4 nodes are available: 1 node(s) had untolerated taint(s), 3 Insufficient cpu. 8s Warning FailedScheduling pod/headroom-7c5f94d7bd-j9v8k 0/4 nodes are available: 1 node(s) had untolerated taint(s), 3 Insufficient cpu. preemption: not eligible due to preemptionPolicy=Never.
The api pod displaced the placeholder on kx-worker and started. The evicted placeholder’s replacement is Pending with preemption: not eligible due to preemptionPolicy=Never: it waits rather than displacing anything. In a cluster with an autoscaler, that Pending placeholder is exactly what adds the next node. The buffer’s size is replicas times requests; to scale it with the cluster, the Cluster Autoscaler FAQ suggests the cluster-proportional-autoscaler to adjust the placeholder replica count. A zero termination grace period on placeholders makes room as fast as possible.
kubectl --context kind-kx apply -f headroom.yamlkubectl --context kind-kx get pods -o wide -l app=headroomkubectl --context kind-kx create deployment api --image=nginx:1.30kubectl --context kind-kx set resources deployment api --requests=cpu=2500m,memory=512Mikubectl --context kind-kx get events --field-selector reason=Preemptedkubectl --context kind-kx get pods -A --field-selector=status.phase=Pendingkubectl --context kind-kx delete deployment api headroomkubectl --context kind-kx delete priorityclass headroom
For your own kind cluster kx: copy a command and paste it into your terminal. Run in the simulator runs the same command in this page's simulated cluster instead; nothing on this page touches your machine. A kind cluster has no node autoscaler, so the displaced placeholder stays Pending instead of adding a node. Every kind node reports the host's full CPU count: raise the placeholder replicas or requests until they leave less than 2.5 CPU free on each worker, or the api pod fits without preempting.
Interaction with HPA
The horizontal pod autoscaler and a node autoscaler form a chain. Load rises, the HPA sees utilization above its target and adds replicas; replicas that do not fit go Pending; the node autoscaler adds nodes; the pods start. On the way down, the HPA removes replicas, nodes empty out, and consolidation removes them.
Requests hold the chain together, and wrong requests break both links at once. The HPA measures utilization as usage divided by request:
- Requests too low. Pods that request 50m but use 400m report 800% utilization, so the HPA adds replicas, and because each requests so little they all fit on existing nodes. Nothing is ever Pending, so no node is added, and the pods fight over CPU that is not there. Memory is worse: overcommitted nodes come under memory pressure and the kubelet starts evicting.
- Requests too high. Pods that request 2 CPU but use 200m make the HPA see low utilization while each replica occupies a large slice of a node. The cluster scales out for capacity nobody uses, and consolidation cannot pack the pods.
Timing matters too. The HPA reacts in seconds and an added node arrives in minutes, which is the gap headroom exists to cover. Size requests from observed usage, set HPA targets with room to absorb the boot time, and treat a pending pod as the autoscaler’s input rather than an error.
Actual state
Check your understanding
Your first answer to each check is the one that counts. After a miss you can answer again; passing every check reconciles the lesson.
Lesson not yet reconciled
Desired: 4 objectives, 0 metReconciled: 4 of 4 objectives met
- Explain how pending pods trigger node scale-up. (not yet met)
- Compare Cluster Autoscaler's node groups with Karpenter's per-pod instance selection. (not yet met)
- Predict when consolidation removes a node and what blocks it. (not yet met)
- Protect a workload from scale-down with PodDisruptionBudgets and the karpenter.sh/do-not-disrupt annotation. (not yet met)
Pass every check above to reconcile this lesson.
Every check has passed, so the desired state is met. First-try accuracy: 0 of 5. This lesson's review cards are in your queue.
Changed since the notes
This lesson draws on an earlier set of study notes. Where the documentation contradicts a claim in them, qualifies it or has moved past it, the claim is listed here with the corrected statement and the source it was checked against.
Show 13 corrections
The notes saidCluster Autoscaler as the node scaler
CorrectedCluster Autoscaler still works on EKS, but EKS best practices present Karpenter (karpenter.sh/v1 NodePool; AWS provider v1.15.x) as the faster, more flexible option, and EKS Auto Mode runs Karpenter-based node provisioning for you (NodePool with nodeClassRef eks.amazonaws.com/NodeClass). Lessons should cover Karpenter and Auto Mode.
Sourcedocs.aws.amazon.com/eks/latest/best-practices/cluster-autoscaling.html
The notes saidKarpenter Helm install --version v0.32.0 with karpenter.sh/v1beta1 NodePool and karpenter.k8s.aws/v1beta1 EC2NodeClass
CorrectedKarpenter v1.0 (Aug 2024) moved the APIs to karpenter.sh/v1 NodePool and karpenter.k8s.aws/v1 EC2NodeClass. v1.0 still accepted v1beta1 manifests for migration, and v1.1.0 dropped them. The most recent release as of 2026-11-19 is v1.15.2 (Nov 12, 2026); install from oci://public.ecr.aws/karpenter/karpenter with an explicit --version.
The notes saidconsolidationPolicy: WhenUnderutilized
CorrectedKarpenter v1.0 renamed WhenUnderutilized to WhenEmptyOrUnderutilized. consolidateAfter applies to both WhenEmpty and WhenEmptyOrUnderutilized (default 0s; 'Never' disables consolidation). expireAfter moved to spec.template.spec.expireAfter (720h or Never), and disruption.budgets cap how many nodes are disrupted at once. The Karpenter docs also list a Balanced policy that skips consolidations whose savings don't justify the pod disruption.
Sourcekarpenter.sh/docs/concepts/disruption/%20;%20https://karpenter.sh/docs/concepts/nodepools
The notes saidnodeClassRef: { name: default }
CorrectedIn karpenter.sh/v1, nodeClassRef needs group: karpenter.k8s.aws, kind: EC2NodeClass and name: default. Karpenter v1.1.0 and later strictly require group and kind.
The notes saidEC2NodeClass amiFamily: AL2
CorrectedA v1 EC2NodeClass requires amiSelectorTerms (e.g. '- alias: al2023@latest'); amiFamily is optional when you use an alias. Amazon EKS stopped publishing EKS-optimized AL2 AMIs on Nov 26, 2025 and publishes none for Kubernetes 1.33+, so use AL2023 or Bottlerocket.
The notes saidcluster-autoscaler image v1.28.0
CorrectedRun the Cluster Autoscaler minor version that matches the cluster's Kubernetes minor (1.37.0 is the most recent CA release as of 2026-11-19). Kubernetes 1.28 is no longer offered on EKS: standard support covers 1.34-1.37 and extended support 1.31-1.33.
The notes saidKarpenter installed in a 'karpenter' namespace with IRSA via eksctl
CorrectedKarpenter's getting-started guide installs into kube-system, which gives the controller the cluster's API Priority and Fairness FlowSchema priority, and grants AWS permissions with EKS Pod Identity (eksctl podIdentityAssociations). Alternatively, EKS Auto Mode (Dec 2024) runs Karpenter-based node provisioning as an AWS-managed capability.
The notes saidCluster Autoscaler expander list and default behavior
CorrectedThe Cluster Autoscaler FAQ lists random, most-pods, least-waste, least-nodes, price, priority and grpc, with least-waste as the default (older releases defaulted to random, so check the default for the version you run). price works only on GCE, GKE and Equinix Metal.
Sourcegithub.com/kubernetes/autoscaler/blob/master/cluster-autoscaler/FAQ.md
The notes saidAWS Node Termination Handler for Spot with CA
CorrectedEKS managed node groups enable Spot Capacity Rebalancing and drain Spot nodes themselves, so NTH isn't needed for managed node groups; it still applies to self-managed ASGs. With Karpenter, use its native interruption handling. Karpenter's docs allow NTH alongside it only for Spot rebalance recommendations, which Karpenter doesn't act on, and warn that this adds node churn.
The notes saidconsolidateAfter: 30s with consolidationPolicy: WhenUnderutilized fails karpenter.sh/v1beta1 validation (note 43 repeats the same block; grouped)
CorrectedConfirmed for notes 42 and 43. A karpenter.sh/v1beta1 CEL rule allowed consolidateAfter only with consolidationPolicy: WhenEmpty, so the API server rejects this NodePool. On karpenter.sh/v1 the equivalent valid block is consolidationPolicy: WhenEmptyOrUnderutilized with consolidateAfter: 30s.
The notes saidThe 'price' expander only works on GCE/GKE (and Equinix Metal); not available with --cloud-provider=aws
CorrectedConfirmed. The FAQ restricts the price expander to GCE, GKE and Equinix Metal. On AWS use least-waste (the default), priority, least-nodes or most-pods.
Sourcegithub.com/kubernetes/autoscaler/blob/master/cluster-autoscaler/FAQ.md
The notes said'The autoscaler runs as a single pod… if it fails, autoscaling stops' (CA supports leader election)
CorrectedCluster Autoscaler supports leader election (--leader-elect defaults to true), so you can run several replicas with one active leader. With a single replica, scaling decisions pause only until the pod is rescheduled; running nodes and pods are unaffected.
Sourcegithub.com/kubernetes/autoscaler/blob/master/cluster-autoscaler/FAQ.md
The notes said'Karpenter with Spot natively handles interruption' omits the required SQS interruption queue and EventBridge rules
CorrectedConfirmed. Karpenter handles interruptions only when you give it an SQS queue (settings.interruptionQueue / --interruption-queue) fed by EventBridge rules for Spot Interruption Warnings, Scheduled Change Health Events, Instance Terminating and Instance Stopping events. Without the queue it never sees the 2-minute Spot notice.
Every correction across the guide, by note and topic.
Sources
Checked against kubernetes.io and AWS documentation for Kubernetes 1.37 on .
- kubernetes.io/docs/concepts/cluster-administration/node-autoscaling
- kubernetes.io/docs/concepts/scheduling-eviction/pod-priority-preemption
- github.com/kubernetes/autoscaler/blob/master/cluster-autoscaler/FAQ.md
- github.com/kubernetes/autoscaler/blob/master/cluster-autoscaler/README.md
- karpenter.sh/docs/concepts/nodepools
- karpenter.sh/docs/concepts/disruption
- karpenter.sh/docs/concepts/scheduling
- karpenter.sh/docs/concepts/nodeclasses
- karpenter.sh/docs/getting-started/getting-started-with-karpenter
- docs.aws.amazon.com/eks/latest/userguide/automode.html
- docs.aws.amazon.com/eks/latest/userguide/create-node-pool.html
- docs.aws.amazon.com/eks/latest/userguide/managed-node-groups.html
- docs.aws.amazon.com/eks/latest/userguide/eks-ami-deprecation-faqs.html
- kubernetes.io/docs/concepts/cluster-administration/flow-control
Cluster autoscaling
↓ ↑ step, 1 to 7 scene, Esc leave