Karpenter

Karpenter is a flexible, fast autoscaler that launches right-sized nodes directly, without preset node groups.

Karpenter is a modern, open-source cluster autoscaler built by AWS. Instead of scaling fixed node groups, it looks at pending pods and launches the exact EC2 instances that fit them — often faster and cheaper.

How it differs from Cluster Autoscaler

  • No predefined node groups — Karpenter picks instance types on the fly from a broad set.
  • It consolidates workloads by replacing several small nodes with fewer larger ones (or vice versa) to cut cost.
  • It provisions nodes in seconds, improving scale-up latency.

You configure it with two resources: a NodePool (what kinds of nodes are allowed) and an EC2NodeClass (AWS-specific settings like AMI and subnets).

Example

Example · yaml
apiVersion: karpenter.sh/v1
kind: NodePool
metadata:
  name: default
spec:
  template:
    spec:
      requirements:
        - key: karpenter.sh/capacity-type
          operator: In
          values: ["spot", "on-demand"]
        - key: kubernetes.io/arch
          operator: In
          values: ["amd64"]
      nodeClassRef:
        name: default
  limits:
    cpu: "1000"
  disruption:
    consolidationPolicy: WhenEmptyOrUnderutilized

When to use it

  • A machine learning team uses a Karpenter NodePool with GPU instance types so training jobs get right-sized GPU nodes in under 60 seconds.
  • A platform team consolidates underutilized nodes using Karpenter's disruption controller, which bin-packs workloads and removes excess nodes automatically.
  • A startup switches from Cluster Autoscaler to Karpenter to provision Spot instances across 30 instance families, dramatically reducing compute costs.

More examples

Install Karpenter with Helm

Installs Karpenter from the public ECR OCI registry, configuring it to manage nodes for the 'prod' cluster.

Example · bash
helm upgrade --install karpenter oci://public.ecr.aws/karpenter/karpenter \
  --version 1.0.0 \
  --namespace kube-system \
  --set settings.clusterName=prod \
  --set settings.interruptionQueue=prod-karpenter \
  --set controller.resources.requests.cpu=1 \
  --set controller.resources.requests.memory=1Gi

NodePool with Spot and On-Demand

A NodePool that provisions Spot-preferred nodes across c, m, and r instance categories with automatic consolidation enabled.

Example · yaml
apiVersion: karpenter.sh/v1
kind: NodePool
metadata:
  name: default
spec:
  template:
    spec:
      requirements:
      - key: karpenter.sh/capacity-type
        operator: In
        values: ["spot", "on-demand"]
      - key: karpenter.k8s.aws/instance-category
        operator: In
        values: ["c", "m", "r"]
  limits:
    cpu: "200"
  disruption:
    consolidationPolicy: WhenEmptyOrUnderutilized

EC2NodeClass for node configuration

Defines the EC2 configuration Karpenter uses when launching nodes, specifying AMI, IAM role, subnets, and security groups via tag selectors.

Example · yaml
apiVersion: karpenter.k8s.aws/v1
kind: EC2NodeClass
metadata:
  name: default
spec:
  amiSelectorTerms:
  - alias: al2023@latest
  role: KarpenterNodeRole-prod
  subnetSelectorTerms:
  - tags:
      karpenter.sh/discovery: prod
  securityGroupSelectorTerms:
  - tags:
      karpenter.sh/discovery: prod

Discussion

  • Be the first to comment on this lesson.