Sub topic 16
Keeping EKS Costs Under Control
This chapter assumes you can create a cluster with eksctl, you know how managed node groups work, and you have seen the Cluster Autoscaler or Karpenter scale nodes. Most of an EKS bill comes from a few places, so you can control it by working through them in order.
Where the Money Goes
The sources below are roughly ordered by size.
| Cost source | Typical driver | Main lever |
|---|---|---|
| EC2 worker nodes | Instance size and count, running hours | Right-sizing, Spot, Graviton, Savings Plans |
| Control plane | A flat hourly fee per cluster | Fewer clusters, supported versions |
| NAT gateways and data transfer | Cross-AZ and internet traffic | VPC endpoints, zone-aware traffic |
| Load balancers and EBS volumes | Forgotten or idle resources | Cleanup, shared load balancers |
The control plane charge is per cluster, so many small clusters cost more than fewer shared ones with namespaces. A cluster running a Kubernetes version past standard support is billed a higher control plane rate. Upgrading on schedule is therefore also a cost control.
Right-Size Requests First
The scheduler places pods by their resource requests, not by actual usage. Inflated requests leave nodes mostly empty, and the autoscaler keeps them anyway. Compare requests with real usage (this needs the Metrics Server add-on):
kubectl top pods -A
kubectl top nodesThen set requests close to observed usage:
resources:
requests:
cpu: 250m
memory: 256Mi
limits:
memory: 512MiSetting a memory limit equal to or above the request is safe. A tight CPU limit can throttle a pod even when the node has spare CPU, so many teams omit it.
Use Cheaper Capacity
Spot Instances can cost much less than On-Demand, but AWS can reclaim them with a two-minute warning. Use them for stateless, restartable pods. Offer several instance types so Spot has more capacity pools to draw from:
apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig
metadata:
name: demo
region: us-east-1
managedNodeGroups:
- name: ng-spot
instanceTypes: ["m5.large", "m5a.large", "m4.large"]
spot: true
minSize: 0
maxSize: 6
desiredCapacity: 1
labels:
capacity: spotKeep a small On-Demand node group for system pods and stateful workloads. Select Spot with a nodeSelector on capacity: spot.
Graviton (Arm) instances such as m6g.large usually give better price-performance. Your images must be built for arm64, or as multi-architecture images, or the pods will fail to start.
For steady baseline load, Compute Savings Plans lower the On-Demand rate in return for a one- or three-year spend commitment. Buy them only for usage you are sure will continue, and cover the rest with autoscaling.
Find Waste and Attribute Spend
- Tag clusters and node groups, then activate those tags as cost allocation tags in Billing to see spend per team.
- Look for unattached EBS volumes left behind after deleting workloads whose reclaim policy was
Retain. - Replace one load balancer per service with a shared ALB using Ingress rules.
- Add VPC endpoints for S3 and ECR so image pulls and S3 traffic avoid NAT gateway data charges.
- Delete dev clusters when you finish, or scale their node groups to zero overnight.
Scaling a node group to zero looks like this:
eksctl scale nodegroup --cluster demo --name ng-1 --nodes 0 --nodes-min 0Exercise
A deployment requests 2 CPU per pod but uses about 0.2 CPU. The cluster autoscaler keeps adding nodes. Which step reduces cost first, and why?
Show answer
Lower the pod's CPU request to near the observed usage. The scheduler and autoscaler size the cluster from requests, not usage, so the inflated request forces extra nodes. Spot or Savings Plans only make those unneeded nodes cheaper.