QA
Intermediate LevelDocker & Deployment

How do Cluster Autoscaler and Karpenter auto-scale cloud worker nodes?

❓ Interview Prompt: Compare Kubernetes Cluster Autoscaler vs Karpenter for node provisioning speed, instance type flexibility, and cost optimization.

When pods cannot be scheduled due to insufficient cluster resources, node autoscalers provision new worker VMs automatically.

Cluster Autoscaler (CA) — Traditional Approach:

•
Works with: Pre-defined Node Groups (ASGs on AWS, MIGs on GCP).
•
Scale-up: Detects unschedulable pods and increases Node Group size.
•
Scale-down: Removes underutilized nodes (< 50% utilization for 10 min).
•
Limitation: Limited to Node Group's pre-configured instance types — cannot mix instance families dynamically.
•
Speed: ~2–5 minutes to provision a new node.

Karpenter — Modern Approach (AWS):

•
No Node Groups: Directly calls EC2 APIs to provision any instance type.
•
Just-in-Time Provisioning: Matches pending pod requirements and provisions the exact right instance type — spot or on-demand.
•
Bin Packing: Evaluates all pending pods together and chooses the most cost-efficient instance.
•
Drift Detection: Automatically replaces nodes when the provisioner configuration changes.
•
Speed: ~60 seconds to provision a new node (faster than CA).
•
Cost Savings: Automatically selects spot instances; consolidates underutilized nodes.

Code Implementation Example

yaml
# Karpenter NodePool — defines what instances Karpenter can provision
apiVersion: karpenter.sh/v1beta1
kind: NodePool
metadata:
  name: general
spec:
  template:
    spec:
      nodeClassRef:
        apiVersion: karpenter.k8s.aws/v1beta1
        kind: EC2NodeClass
        name: default
      requirements:
        - key: karpenter.sh/capacity-type
          operator: In
          values: ["spot", "on-demand"]   # prefer spot, fall back to on-demand
        - key: node.kubernetes.io/instance-type
          operator: In
          values:
            - m5.large
            - m5.xlarge
            - m5.2xlarge
            - m6i.large         # Karpenter picks the cheapest available
        - key: kubernetes.io/arch
          operator: In
          values: ["amd64", "arm64"]    # also consider Graviton!
  limits:
    cpu: 1000                   # max 1000 CPU cores across all nodes
  disruption:
    consolidationPolicy: WhenUnderutilized
    consolidateAfter: 30s
💡Karpenter NodePool: provision spot/on-demand across 4 instance types, auto-consolidate underutilized nodes after 30s.
🎯 Interview Key Takeaway

Karpenter provisions nodes ~3x faster than Cluster Autoscaler with any instance type — enabling spot instance cost savings and automatic bin-packing consolidation.

#Kubernetes#Karpenter#Cluster Autoscaler#Node Scaling#Cost Optimization#Intermediate
Back to all Docker & Deployment Questions→

More Docker & Deployment Interview Questions

Beginner LevelDocker & Deployment

How do Docker Multi-Stage Builds minimize image size and improve security?

Beginner LevelDocker & Deployment

What is the difference between a Docker Container and a Virtual Machine (VM)?

Beginner LevelDocker & Deployment

What is the difference between a Docker Image and a Docker Container?