interview-prep

Crisp answer: Karpenter is a node provisioner for Kubernetes that provisions exactly the right EC2 instances for pending pods in under 60 seconds. Unlike Cluster Autoscaler, it does not use ASGs — it calls EC2 RunInstances directly, selecting the optimal instance type per pod batch.

Key differences:

Cluster Autoscaler Karpenter
Speed 3-5 minutes Under 60 seconds
Instance selection Fixed per node group Dynamic per pending pods
ASG dependency Yes, manages ASGs No, directly calls EC2
Spot handling Basic Native, interruption handling
Consolidation Limited Automatic node consolidation
Provisioner config ASG-based NodePool and EC2NodeClass CRDs

Karpenter configuration:

# NodePool: defines what nodes Karpenter can provision
apiVersion: karpenter.sh/v1
kind: NodePool
metadata:
  name: default
spec:
  template:
    spec:
      nodeClassRef:
        group: karpenter.k8s.aws
        kind: EC2NodeClass
        name: default
      requirements:
      - key: karpenter.sh/capacity-type
        operator: In
        values: ["spot", "on-demand"]
      - key: kubernetes.io/arch
        operator: In
        values: ["amd64"]
      - key: karpenter.k8s.aws/instance-category
        operator: In
        values: ["c", "m", "r"]    # compute, memory, balanced families
      - key: karpenter.k8s.aws/instance-generation
        operator: Gt
        values: ["2"]              # 3rd gen or newer
  limits:
    cpu: 1000                      # max vCPUs in this node pool
  disruption:
    consolidationPolicy: WhenUnderutilized
    consolidateAfter: 30s
---
# EC2NodeClass: AWS-specific node configuration
apiVersion: karpenter.k8s.aws/v1
kind: EC2NodeClass
metadata:
  name: default
spec:
  amiSelectorTerms:
  - alias: al2023@latest           # latest Amazon Linux 2023 EKS AMI
  role: KarpenterNodeRole
  subnetSelectorTerms:
  - tags:
      karpenter.sh/discovery: my-cluster
  securityGroupSelectorTerms:
  - tags:
      karpenter.sh/discovery: my-cluster

Consolidation:

Karpenter actively consolidates nodes. After a scale-down in workloads it will:

  1. Identify underutilised nodes
  2. Check if pods can be binpacked onto fewer nodes
  3. Cordon and drain the underutilised nodes
  4. Terminate the EC2 instances

This happens continuously, keeping cost at minimum without manual intervention.

Spot interruption handling:

When AWS signals a spot interruption (2-minute warning), Karpenter:

  1. Cordons the spot node immediately
  2. Starts draining pods gracefully
  3. Provisions an on-demand replacement in parallel
  4. Completes the handover before the 2-minute deadline

What to say in the interview:

"Karpenter is AWS's answer to the limitations of Cluster Autoscaler. The speed difference alone is significant — under 60 seconds versus 3-5 minutes means burst workloads get capacity almost immediately. The bigger advantage is dynamic instance selection: Karpenter looks at all pending pods and picks the EC2 instance type that best fits them rather than being constrained to a pre-defined node group's instance type. For spot users, the native interruption handling is excellent — it starts provisioning a replacement before the spot instance is terminated. I would choose Karpenter over Cluster Autoscaler for any new EKS cluster."


My notes