Implementing Cost Optimization
1. Right-Sizing Resources
| Anti-pattern | Fix |
| Over-requested CPU | VPA recommendations |
| No requests | Causes node bin-packing failure |
| CPU limit hurts latency | Drop CPU limit for latency-critical pods |
2. Using Spot Instances
nodeSelector: { karpenter.sh/capacity-type: spot }
tolerations:
- { key: spot, operator: Exists, effect: NoSchedule }
Warning: Spot can be reclaimed in 2 minutes. Use only for stateless, restartable workloads; install AWS Node Termination Handler.
3. Implementing Cluster Autoscaler
helm install cluster-autoscaler autoscaler/cluster-autoscaler \
--set autoDiscovery.clusterName=prod \
--set awsRegion=us-east-1
| Tool | Detail |
| Cluster Autoscaler | Per-ASG/node group |
| Karpenter | AWS, GCP — instance-shape-aware, faster |
4. Configuring Pod Disruption Budgets
See §30.11 — required for safe scale-down during cluster autoscaling.
5. Using Vertical Pod Autoscaler
See §32 — run in Off (recommend-only) mode for rightsizing analysis without churn.
6. Scheduling Workloads Efficiently
| Technique | Detail |
| Bin packing | Use MostAllocated scoring |
| Descheduler | Re-balance over time |
| Mixed instance types | Karpenter picks cheapest |
7. Implementing Resource Quotas
See §54.2 — prevent runaway workloads from inflating cluster size.
8. Using Storage Classes Wisely
| Tier | Use |
| gp3 / pd-balanced | General workloads (cheaper than io1/io2) |
| st1 | Throughput-optimized; logs |
| Snapshots over backups | Cheaper than full PV copies |
9. Cleaning Up Unused Resources
kubectl get pvc -A | grep -v Bound
kubectl get pv | grep Released
helm list -A | awk '$8=="deployed" {print}'
| Tool | Detail |
| kor | Find unused ConfigMaps, Secrets, PVCs |
| k8sgpt | Detect misconfigurations + cost issues |
10. Monitoring Cost Allocation
| Tool | Detail |
| OpenCost | CNCF; per-ns/label cost; Prometheus integration |
| Kubecost | UI, chargeback, savings recs |
| Vantage | Multi-cloud cost mgmt |