Skip to main content
Running workloadsLesson 9 of 14

Adding and Removing Nodes (Cluster Autoscaler vs Karpenter)

The HPA adds Pods, but someone has to add the machines they run on. Follow one Pending Pod through Cluster Autoscaler and Karpenter, then watch both remove nodes again, and see what stops them.

Pending Pods1
Nodes2
AutoscalerWatching
Kubernetes clusterCloud providerPending Podweb · 2 CPU requestkube-schedulerUnschedulablePDBweb minAvailableCluster AutoscalerNode group sizesKarpenterReads Pod needsNodePool+ EC2NodeClassnode-1Fullnode-2Mostly idlenode-3New VMNode groupFixed instance typeCompute APICreate / delete VMSpot noticeInterruption eventsUnschedulable
RequestWatchAppears in a later step

What you will learn

  • Node autoscalers react to unschedulable Pods, not to CPU
  • Cluster Autoscaler resizes node groups from templates
  • Karpenter picks an instance for the Pods from a NodePool
  • Why a new node takes minutes
  • Scale-down, consolidation, and what blocks it
  • Handling spot interruptions

Cluster Autoscaler vs Karpenter​

Cluster AutoscalerKarpenter
Unit it managesNode groups (ASG, node pool, VM scale set)NodeClaims from a NodePool
Instance typeFixed per groupChosen per batch of Pods from allowed requirements
How it scales upSimulates the Pod on each group's template, raises desired sizeCalls the compute API directly
Scale-downNode under utilization threshold and Pods fit elsewhere, for 10 min by defaultConsolidation: delete, or replace with cheaper (consolidationPolicy, consolidateAfter)
Stop a Pod's node from going awaycluster-autoscaler.kubernetes.io/safe-to-evict: "false"karpenter.sh/do-not-disrupt: "true"
Stop a node from going awayNode annotation cluster-autoscaler.kubernetes.io/scale-down-disabled: "true"Node annotation karpenter.sh/do-not-disrupt: "true", or a budget of nodes: "0"
Spot interruptionsLeft to the provider or a separate handlerBuilt in, with an interruption queue
Where it runsMany cloudsAWS, Azure, and other providers with a Karpenter integration

Try it yourself​

kubectl get pods -A --field-selector=status.phase=Pending # Who is waiting for a node
kubectl describe pod <pod> # Events: TriggeredScaleUp / NotTriggerScaleUp, or Karpenter's
kubectl get nodes -L node.kubernetes.io/instance-type,topology.kubernetes.io/zone

# Cluster Autoscaler
kubectl -n kube-system get configmap cluster-autoscaler-status -o yaml # Scale-up / scale-down state per group

# Karpenter
kubectl get nodepools # Pools, readiness, used resources
kubectl get nodeclaims # One per launched node: type, zone, capacity type
kubectl get ec2nodeclasses # AWS: image, subnets, security groups
kubectl annotate pod <pod> karpenter.sh/do-not-disrupt=true # Protect a Pod's node from consolidation

Check yourself

  1. Every node is at 30% CPU usage, yet a new Pod stays Pending and a node is added. Why?
  2. Pods need a GPU type that no existing node group offers. What does Cluster Autoscaler do?
  3. A mostly idle node is never removed. Which is the most likely cause?

Further reading: Cluster Autoscaler FAQ · Karpenter NodePools · Karpenter disruption · Node autoscaling on kubernetes.io · Scaling with Load (HPA) · Managed Kubernetes — Who Runs What · Draining Nodes and Upgrading the Cluster