Rightsizing and cost trade-offs
Right-size for demand and reliability
Rightsizing adjusts resource requests and limits to better match workload requirements. Start with usage distributions, burst behavior, startup peaks, OOM events, throttling, latency and error rates, not just average CPU. Imagine a catalog Pod requesting 500m CPU and using 200m in an observed steady period. It looks over-requested, but you need representative traffic and headroom before reducing it. Memory usage and limits require separate attention because memory exhaustion can terminate containers. Define the service-level objective (SLO) and approved rollback thresholds first.
Observed CPU=200m; request=500m; utilization=40%Candidate request=250m; same usage=80%Account for interactions with autoscaling
HPA resource utilization depends on requests. For four replicas each using 200m with a 50% target, the idealized formula ceil(current replicas × observed utilization / target) gives four replicas with a 500m request, and seven with a 250m request. Actual HPA decisions also use tolerance, missing metrics, readiness, bounds and stabilization behavior. Vertical Pod Autoscaler (VPA) recommends or updates requests depending on its mode and version; coordinate with HPA to avoid conflicting control loops for the same metric. Prefer reviewing recommendations first. Do not promise that lower requests reduce replicas or node cost.
Old: ceil(4 × 40 / 50) = 4New: ceil(4 × 80 / 50) = 7Assumes identical current usage and valid metrics; ignores stabilization and toleranceTest whether a node can actually be removed
For three 4-core/8-GiB nodes, a synthetic workload set requests 9 cores and 10 GiB in total. After review, requests drop to 7 cores and 10 GiB. The aggregate arithmetic lower bound drops from three nodes to two, but indivisible Pod shapes, topology spread, taints, DaemonSet overhead, PDBs, storage affinity and failure reserves may prevent a node removal. For example, three Pods each needing 3 cores cannot fit on two 4-core nodes even if memory fits. Use actual scheduler and capacity evidence before consolidating; a bin-packing lower bound is not a packing solution.
Before: max(ceil(9/4), ceil(10/8)) = 3After: max(ceil(7/4), ceil(10/8)) = 23 Pods × 3 cores: each occupies a separate 4-core nodeChoose the capacity type with interruption costs in mind
Spot or preemptible capacity can be reclaimed and might be unavailable when needed. A checkpointable batch worker can be a candidate, but a latency-sensitive single replica without recovery evidence is not. Diversify eligible capacity, test retries and checkpoints, maintain reliable fallback and compare the total cost per successful job. For a hypothetical job costing $4 on stable capacity and $2 per Spot attempt, two attempts cost $4 before storage and delay. Savings commitments involve payment terms, utilization risk and coverage; require authorized financial review and a verified forecast instead of buying from a tutorial. Budget alerts can lag and are not universal hard spending caps.
Stable job: $4Spot attempts: 2 × $2 = $4 before extra costsUnknown retry probability or interruption tolerance -> HOLDCompare measured outcomes and residual costs
A candidate design reduces modeled hourly node spend from $12 to $8, but adds $1 of network and $0.50 of logging cost. Net estimated reduction is $2.50 per hour if all other components stay unchanged. Forecast a low/base/high demand range, including capacity spikes and idle periods. Track retained PVCs, snapshots, load balancers, public IPs, egress, monitoring, managed control-plane fees and independently billed resources. Review ownership and retention before removing an orphan candidate. Never delete shared or unverified resources to chase a savings target. Realized savings require subsequent billing evidence, not a recommendation dashboard.
12 - (8 + 1 + 0.50) = 2.50 USD/hour estimated reductionApprove a bounded experiment, not a blind change
Compare the old and new configuration under representative load. For this fictional SLO use p95 latency at most 200 ms, error rate at most 1%, no OOM events, and verified resilience and rollback. A change that saves $2.50 but raises p95 to 250 ms fails. Missing telemetry also means HOLD. Start with a small approved canary, retain the previous reviewed configuration and verify both performance and actual cost effects. Developer effort, operational toil and risk belong in the decision, too. The offline exercise evaluates declared gates, not actual workloads or cloud billing. Next: platform engineering and internal developer platforms.
p95=180 ms; errors=0.5%; OOM=0; evidence complete -> candidatep95=250 ms -> HOLDFurther reading
- https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/ — Requests and limits
- https://kubernetes.io/docs/concepts/workloads/autoscaling/horizontal-pod-autoscale/ — HPA request-based utilization
- https://kubernetes.io/docs/concepts/workloads/autoscaling/vertical-pod-autoscale/ — Vertical resizing and recommendations
- https://docs.aws.amazon.com/eks/latest/best-practices/cost-opt-compute.html — Capacity optimization and Spot trade-offs
- https://docs.aws.amazon.com/eks/latest/best-practices/cost-opt-networking.html — Networking costs and availability trade-offs
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Rightsizing and cost trade-offs — knowledge check
Choose changes using usage and SLO evidence
At fixed CPU use, reducing a CPU request does what to HPA CPU utilization?
Does an aggregate two-node lower bound prove the Pods fit?
Which workload is a candidate for interruptible capacity?
A candidate exceeds its latency SLO but is cheaper. What is the decision in the lab?
What proves realized savings?