2024-10-20Hünkar Döner

EKS Autoscaling: Karpenter vs Cluster Autoscaler

EKSKarpenterAutoscalingPerformance
E

EKS Autoscaling: Karpenter vs Cluster Autoscaler

One of the biggest promises of Kubernetes is autoscaling. The system grows when traffic increases and shrinks when it decreases. For years, the standard tool for this job was Cluster Autoscaler (CA). However, CA had some limitations. AWS developed Karpenter to solve this problem.

In this article, we will compare these two tools and explain why you should switch to Karpenter.

How Cluster Autoscaler (CA) Works?

CA relies on AWS's "Auto Scaling Groups" (ASG) feature.

  1. A pod cannot be scheduled and falls into "Pending" state.
  2. CA notices this and tells the associated ASG "Give me 1 more server".
  3. ASG launches an EC2 compliant with the predefined template (Launch Template).

Disadvantages:

  • Slow: It can take minutes for a new node to arrive and be ready.
  • Not Flexible: It opens only the instance type (e.g., m5.large) you selected in ASG. It might open a large server even for a small pod.

How Karpenter Works?

Karpenter does not use ASG. It talks directly to the EC2 Fleet API.

  1. Notices the Pending pod.
  2. Analyzes the pod's resource needs (CPU, RAM) and constraints (e.g., must be Spot, must be ARM).
  3. Finds the cheapest and most suitable instance type from the AWS inventory to meet this need.
  4. Launches that instance directly and joins it to the cluster.

Advantages:

  • Very Fast: Readies nodes in seconds (Just-in-time).
  • Cost Effective: Selects the server that exactly fits the need (Right-sized).
  • Bin Packing: Places pods compactly, optimizes node count.
  • Consolidation: When traffic drops, it moves pods from emptying nodes to other nodes and shuts down the empty node, providing savings.

Which One to Use?

We indisputably recommend Karpenter for all newly established Amazon EKS clusters. It offers faster, cheaper, and smarter scaling. Migration to Karpenter is quite easy for your existing clusters using CA.