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
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 Autoscaler | Karpenter | |
|---|---|---|
| Unit it manages | Node groups (ASG, node pool, VM scale set) | NodeClaims from a NodePool |
| Instance type | Fixed per group | Chosen per batch of Pods from allowed requirements |
| How it scales up | Simulates the Pod on each group's template, raises desired size | Calls the compute API directly |
| Scale-down | Node under utilization threshold and Pods fit elsewhere, for 10 min by default | Consolidation: delete, or replace with cheaper (consolidationPolicy, consolidateAfter) |
| Stop a Pod's node from going away | cluster-autoscaler.kubernetes.io/safe-to-evict: "false" | karpenter.sh/do-not-disrupt: "true" |
| Stop a node from going away | Node annotation cluster-autoscaler.kubernetes.io/scale-down-disabled: "true" | Node annotation karpenter.sh/do-not-disrupt: "true", or a budget of nodes: "0" |
| Spot interruptions | Left to the provider or a separate handler | Built in, with an interruption queue |
| Where it runs | Many clouds | AWS, 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
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