Sub topic 16
Keeping EKS Costs Under Control
This chapter assumes you have read the earlier chapters on compute options and on scaling pods and nodes. You should know what a managed node group is, how the Horizontal Pod Autoscaler (HPA) works, and what Karpenter does. The goal here is to find where an EKS bill comes from and to apply the main levers in a sensible order.
Where the Money Goes
An EKS bill is a collection of ordinary AWS line items. Only one of them is specific to EKS.
| Cost driver | How it is charged | Typical share |
|---|---|---|
| EKS control plane | Flat hourly fee per cluster (about $0.10 per hour at the time of writing) | Small |
| Extended support | Higher hourly fee (about $0.60 per hour) for clusters on versions past standard support | Small, but avoidable |
| Worker nodes | EC2 instance hours, or Fargate vCPU and memory per second | Usually the largest |
| EBS volumes | GB-months provisioned, plus IOPS and throughput above the baseline | Medium |
| Load balancers | Hourly fee per ALB or NLB, plus capacity units | Medium |
| NAT gateways | Hourly fee plus a per-GB processing fee | Often a surprise |
| Data transfer | Cross-AZ and internet egress, per GB | Often a surprise |
| CloudWatch | Log ingestion and storage, metrics | Small to medium |
Check current prices on the AWS pricing pages before you plan. The ratios matter more than the exact numbers. Nodes dominate, so most of your savings come from running fewer, better-used nodes at a lower price per hour.
The Order of Operations
Apply the levers in this order. Each step makes the next one safer.
Commitments come late on purpose. If you buy a Savings Plan before right-sizing, you commit to capacity you would otherwise have removed.
Step 1: Measure
You cannot cut what you cannot see. Two things make EKS costs visible.
- Cost allocation tags. Tag node groups, volumes and load balancers with
team,envandapp. Activate those tags as cost allocation tags in the Billing console. Tags on EC2 instances show who owns a node, but not which pods used it. - Pod-level allocation. AWS offers split cost allocation data for EKS in Cost and Usage Reports. It divides node cost among pods by their CPU and memory use. Open-source tools such as OpenCost and Kubecost do something similar inside the cluster.
Start by finding your top three namespaces by cost. Most clusters have a few large workloads and a long tail of small ones.
Step 2: Right-Size Pod Requests
The scheduler places pods using their requests, not their actual use. A pod that requests 2 vCPU but uses 0.2 vCPU still blocks 2 vCPU on the node, and you pay for all of it. Over-requesting is the most common source of waste on EKS.
Compare requests with real use:
kubectl top pods -A --sort-by=cpu
kubectl top nodeskubectl top needs the Metrics Server add-on. For history, use Container Insights or Prometheus, because a single snapshot hides peaks.
Set requests near typical use, and set memory limits equal to memory requests, because memory is not compressible:
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
spec:
replicas: 2
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
- name: web
image: nginx:stable
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
memory: 128MiThis example sets no CPU limit. A CPU limit throttles the container even when the node has idle CPU. Many teams set only a CPU request and leave the limit off, but follow your platform's policy if it requires limits.
The Vertical Pod Autoscaler (VPA) can run in recommendation-only mode (updateMode: "Off"). It then suggests request values without restarting pods.
Step 3: Autoscale Pods and Nodes
Right-sized requests only save money if the node count follows demand.
- The HPA changes the number of pod replicas based on metrics such as CPU use.
- The Cluster Autoscaler or Karpenter changes the number of nodes so pods fit.
Karpenter has a cost advantage because it picks instance types that match the pending pods, and it consolidates. Consolidation removes empty nodes and replaces underused nodes with fewer or cheaper ones. The NodePool below allows Spot and On-Demand capacity and both CPU architectures. It assumes you already created an EC2NodeClass named default.
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", "arm64"]
nodeClassRef:
group: karpenter.k8s.aws
kind: EC2NodeClass
name: default
limits:
cpu: "100"
disruption:
consolidationPolicy: WhenEmptyOrUnderutilized
consolidateAfter: 1mThe limits field caps total CPU for this pool. It acts as a safety net: a runaway deployment cannot buy unlimited nodes. Karpenter prefers Spot when both capacity types are allowed, so the pool above will mostly launch Spot nodes.
Consolidation evicts pods, so set PodDisruptionBudgets on important workloads. Without them, consolidation can take down all replicas of a service at once.
Step 4: Choose Cheaper Capacity
Spot Instances
Spot capacity costs much less than On-Demand, but AWS can reclaim it with a two-minute warning. It suits stateless, replicated, restart-tolerant work such as web replicas, batch jobs and CI runners. It does not suit single-replica databases.
For managed node groups, list several instance types so Spot can draw from more capacity pools. A group with one type is interrupted more often.
apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig
metadata:
name: demo
region: us-east-1
managedNodeGroups:
- name: spot-1
instanceTypes: ["m5.large", "m5a.large", "m4.large"]
spot: true
minSize: 0
maxSize: 6
desiredCapacity: 2
labels:
capacity: spotKeep a small On-Demand node group for system components and stateful pods, and let Spot absorb the rest.
Graviton
Graviton instances (names with a g, such as m6g or m7g) use Arm processors and usually give better price-performance than comparable x86 instances. The catch is that your container images must support arm64. Build multi-architecture images, or check that every image you run publishes an arm64 variant. Official images such as nginx:stable do.
Fargate
Fargate removes node management, but you pay per pod for the vCPU and memory you request, rounded up to the nearest supported size. It becomes expensive for steady, high-utilization workloads, and it does not support DaemonSets or EBS volumes. Use it for small or bursty workloads where the operational savings outweigh the higher unit price.
Step 5: Commit Baseline Usage
After right-sizing, look at the minimum usage that runs all month. Cover that baseline with a Compute Savings Plan. It applies to EC2 and Fargate regardless of instance family, size or Region, so it keeps working when Karpenter changes instance types. Leave the variable part of your usage On-Demand or Spot. Savings Plans do not apply to Spot instances' discounted rates in a useful way, so size the commitment against On-Demand baseline only.
Step 6: Trim the Hidden Costs
These items are small individually but add up.
- NAT gateways. Pods in private subnets that pull images from the internet or call AWS APIs pay NAT processing fees. Add VPC endpoints for S3 (a free gateway endpoint) and for ECR, and add interface endpoints for other heavy services. Interface endpoints have their own hourly fee, so enable them only for services with real traffic.
- Cross-AZ traffic. Traffic between Availability Zones is charged per GB in each direction. Chatty services spread across zones can cost more than expected. Topology-aware routing and
topologySpreadConstraintshelp, but balance savings against availability. - Load balancers. Each Ingress that gets its own ALB pays its own hourly fee. Share one ALB across many Ingresses with an IngressGroup:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: web
annotations:
alb.ingress.kubernetes.io/scheme: internet-facing
alb.ingress.kubernetes.io/target-type: ip
alb.ingress.kubernetes.io/group.name: shared
spec:
ingressClassName: alb
rules:
- http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: web
port:
number: 80Every Ingress with the same group.name shares one ALB.
- EBS volumes. Choose gp3 over gp2, since gp3 is cheaper per GB and lets you set IOPS separately. Check for unattached volumes. A StorageClass with
reclaimPolicy: Retainleaves volumes behind after you delete the claim. - Logs. Control plane logs and Container Insights can produce large CloudWatch bills. Enable only the log types you need, and set a retention period on every log group.
- Version support. Keep clusters on a version in standard support to avoid the extended support fee.
To remove the demo cluster:
eksctl delete cluster -f cluster.yamlCommon Mistakes
- Buying Savings Plans before right-sizing, which locks in waste.
- Running Spot with one instance type and no PodDisruptionBudget.
- Setting requests from a guess and never reviewing them.
- Leaving log groups on "never expire".
- Running one cluster per team for isolation that namespaces would provide.
Exercise
A cluster has 10 nodes at 20% average CPU use. Every pod requests far more CPU than it uses. A colleague proposes buying a one-year Compute Savings Plan for all 10 nodes. What should you do first, and why?
Show answer
Right-size the pod requests first, then let the autoscaler (Cluster Autoscaler or Karpenter) reduce the node count. Only then buy a Savings Plan sized to the new, smaller baseline. Buying the plan first would commit you to paying for capacity you are about to remove.
Exercise
You move a stateless web Deployment to Spot nodes. Name two settings or practices that keep it available when AWS reclaims a node.
Show answer
Any two of: run multiple replicas spread across nodes and zones; allow several instance types so Spot has more capacity pools; set a PodDisruptionBudget; keep a small On-Demand node group for critical pods.