Taming the EKS Beast: How I Saved 60% on Cloud-Spend

Salek Ali
4 min readFeb 13, 2025

--

I used Karpenter.
That’s it — roll credits.
Or! Stick around and learn how you can get the same results.

Karpenter, an open-source cluster autoscaler, is a game-changer for anyone looking to scale EKS clusters dynamically without breaking the bank.
In this post, I’ll explain how Karpenter works and how you can implement it to save massively on your EKS costs.

📚 This tutorial is at an intermediate difficulty level 📚

What Is Karpenter, and Why Should You Care?

In the wild world of Kubernetes, managing cluster resources efficiently can be chaotic. Thankfully, Amazon Elastic Kubernetes Service (EKS) gives you a managed Kubernetes service to handle much of the grunt work. But if you want to level up your game and get those clusters scaling like a pro, it’s time to call in the big guns: Karpenter.

Karpenter is an advanced cluster autoscaler developed by AWS. It takes a modern approach to scaling by focusing on workload-specific requirements rather than node groups (as is the case in the Kubernetes Cluster Autoscaler).

Key Benefits

  1. Faster Scaling: Karpenter reacts to workload changes in seconds, ensuring your cluster remains highly responsive.
  2. Optimised Resource Allocation: It minimises resource wastage by provisioning nodes best suited for the workload.
  3. Cost Savings: Karpenter achieves significant cost reductions by right-sizing nodes dynamically.
  4. Simplicity: Karpenter eliminates the need to manually manage multiple ASGs (Auto Scaling Groups) or node groups.

How Does Karpenter Work?

At its core, Karpenter works by dynamically provisioning EC2 instances based on the real-time demands of your Kubernetes pods instead of predefined scaling policies. Here’s a simplified workflow:

  1. Pods remain unscheduled due to insufficient resources.
  2. Karpenter detects the scheduling issue and analyses the pod’s resource requests (CPU, memory, and node affinity).
  3. It launches the optimal EC2 instance to accommodate the workload.
  4. Once workloads are completed, Karpenter automatically terminates unused nodes to avoid idle costs.

A Step-by-Step on Getting Karpenter Running on EKS

Prerequisites

Before we dive in, you need to have:

  1. An EKS Cluster: You can set it up using eksctl or your favourite IaC tool.
  2. AWS CLI: Installed and configured. No AWS CLI? No party.
  3. kubectl: Installed and configured to talk to your cluster.
  4. IAM Permissions: Admin-level, because we mean business.
  5. Helm: Our favourite Kubernetes package manager.

Step 1: Set Up ServiceAccount and IAM Role for Karpenter

1. Create a Namespace for Karpenter

kubectl create namespace karpenter

2. Create the ServiceAccount with IAM Role

Use the following command to create a Kubernetes ServiceAccount with an attached IAM role:

eksctl create iamserviceaccount \
--cluster <CLUSTER_NAME> \
--namespace karpenter \
--name karpenter \
--attach-policy-arn arn:aws:iam::aws:policy/AmazonEKSWorkerNodePolicy \
--attach-policy-arn arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly \
--attach-policy-arn arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore \
--attach-policy-arn arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy \
--role-name <KARPENTER_IAM_ROLE_NAME> \
--approve

Replace <CLUSTER_NAME> and <KARPENTER_IAM_ROLE_NAME> with your cluster’s name and desired role name.
This creates the IAM role and associates it with the karpenter ServiceAccount in the karpenter namespace.

Step 2: Install Karpenter in EKS

1. Add the Karpenter Helm Repository

helm repo add karpenter https://charts.karpenter.sh
helm repo update

2. Install Karpenter Helm Chart

Replace <CLUSTER_NAME> and <AWS_REGION> with your cluster’s name and region.

helm install karpenter karpenter/karpenter \
--namespace karpenter \
--set serviceAccount.create=false \
--set serviceAccount.name=karpenter \
--set clusterName=<CLUSTER_NAME> \
--set clusterEndpoint=<CLUSTER_ENDPOINT> \
--set aws.defaultInstanceProfile=<INSTANCE_PROFILE_NAME>

You can get the cluster endpoint with the following command:

aws eks describe-cluster --name <CLUSTER_NAME> --region <AWS_REGION>

Step 3: Create Provisioner and EKS Node Template

Provisioners tell Karpenter how to scale your cluster.

In this example (available on my Github), we created a provisioner with a node template with subnet and security group selection, based on specific tags.
Save this to a file (e.g., provisioner.yaml) and apply it:

kubectl apply -f provisioner.yaml

Step 4: Test Karpenter

Time to put Karpenter to the test. Deploy a sample workload:

Sample Deployment

Apply the deployment:

kubectl apply -f karpenter-demo.yaml

Now watch your pods and nodes spring to life:

kubectl get pods -o wide
kubectl get nodes

If everything’s working, Karpenter should immediately start spinning up new nodes.

Step 5: Monitor and Optimise

Monitor Karpenter using CloudWatch metrics and Karpenter logs. You can also set up Grafana to visualise metrics in dashboards.

Conclusion

Karpenter is an excellent solution for optimising Kubernetes clusters. With Karpenter you can enable your cluster to adjust resources dynamically — adding nodes when demand spikes and scaling down to save costs during quieter periods. By following this guide, you’ll have your Kubernetes clusters scaling efficiently and saving you a few bucks along the way.

I’ll be posting more of these guides, going over a wide range of difficulty, so subscribe below! My newsletter sends out friendly emails when I make new posts.

Want to learn more about how I can assist you with your cloud and DevOps needs? Visit my homepage to get in touch and let’s find out how I can support your next project!

--

--

No responses yet