Opscraft
Amazon EKS · Lesson 5 of 11 · 4 min read

Autoscaling: Cluster Autoscaler vs Karpenter

Cluster Autoscaler

Watches for unschedulable pods and increases the desired capacity of existing node groups (ASGs) whose instance type would fit them; scales down underused nodes after a delay. Limitations: you pre-define node groups (instance types, sizes, AZs), scaling goes through ASGs (slower), and mixing many instance types means many node groups.

Karpenter

Karpenter watches pending pods and launches right-sized EC2 instances directly (via EC2 Fleet), choosing from many instance types based on the pods' requirements — CPU/memory, architecture, zone, capacity type, GPUs.

Enlarge diagramPending pods6 × 2 CPU, arm64okKarpenterreads NodePoollimitsEC2 Fleetc7g.4xlarge, SpotPods scheduledseconds laterLater: consolidation replaces or removes under-used nodes; expireAfter keeps nodes fresh.
Figure 1. Karpenter: pending pods describe what they need; Karpenter picks and launches an instance that fits, and later consolidates.
Swipe sideways to see all of it, or tap to open it full screen.
apiVersion: karpenter.sh/v1
kind: NodePool
metadata: { name: general }
spec:
  template:
    spec:
      requirements:
      - { key: kubernetes.io/arch,          operator: In, values: [arm64, amd64] }
      - { key: karpenter.sh/capacity-type,  operator: In, values: [spot, on-demand] }
      - { key: karpenter.k8s.aws/instance-category, operator: In, values: [c, m, r] }
      - { key: karpenter.k8s.aws/instance-generation, operator: Gt, values: ["5"] }
      nodeClassRef: { group: karpenter.k8s.aws, kind: EC2NodeClass, name: default }
      expireAfter: 720h                     # replace nodes every 30 days (fresh AMIs)
  limits: { cpu: "1000", memory: 4000Gi }   # cap total capacity
  disruption:
    consolidationPolicy: WhenEmptyOrUnderutilized
    consolidateAfter: 1m
    budgets:
    - nodes: "10%"                          # disrupt at most 10% of nodes at once
---
apiVersion: karpenter.k8s.aws/v1
kind: EC2NodeClass
metadata: { name: default }
spec:
  role: KarpenterNodeRole-acme-prod
  amiSelectorTerms: [{ alias: al2023@latest }]
  subnetSelectorTerms:        [{ tags: { karpenter.sh/discovery: acme-prod } }]
  securityGroupSelectorTerms: [{ tags: { karpenter.sh/discovery: acme-prod } }]

Key features:

  • NodePool — constraints for nodes Karpenter may create (instance types/families, capacity type, zones, architectures), limits, disruption policy. EC2NodeClass — AWS-specific settings (AMI, subnets, security groups, IAM role, block devices, user data).
  • Consolidation — continuously replaces or removes underused nodes and bin-packs pods onto fewer/cheaper instances — major cost savings.
  • Drift — nodes whose spec no longer matches (new AMI, changed NodeClass) are replaced automatically, respecting disruption budgets and PDBs — the mechanism for rolling AMI updates.
  • Spot — diversified instance types, interruption handling via an SQS queue receiving EC2 Spot interruption/rebalance events (Karpenter cordons and drains the node before reclaim), with on-demand fallback.

Running Spot safely: many instance types and AZs, PDBs on every service, multiple replicas, graceful shutdown, critical/stateful workloads on on-demand (capacity-type requirement), and accept that pods will be moved.

Cluster Autoscaler Karpenter
Scales Existing node groups (ASGs) Launches instances directly
Instance choice Fixed per node group Chosen per pending pods from many types
Speed Slower (ASG) Fast
Bin-packing / consolidation Basic scale-down Active consolidation and right-sizing
Spot handling Via ASG mixed instances Native, with interruption queue
Enlarge diagramCluster AutoscalerKarpenterScales existing ASGsInstance types fixed per groupSlower, minutesMany node groups to manageLaunches EC2 directlyPicks from many types, SpotFast, bin-packs wellConsolidation saves cost
Figure 2. Cluster Autoscaler grows the node groups you defined; Karpenter chooses the instance itself.
Swipe sideways to see all of it, or tap to open it full screen.

Pod-level autoscaling

HPA for replicas (CPU/memory via metrics-server, custom metrics via Prometheus Adapter), KEDA for event-driven scaling (SQS queue depth, Kafka lag, cron) including scale to zero, VPA for right-sizing requests.