Optimize Cloud Costs
Reduce cloud spend on Kubernetes workloads through visibility, right-sizing, autoscaling, spot capacity, and quotas — without breaking SLOs.
When to Use
- Cloud costs growing without corresponding business value
- Need cost allocation by team, app, or environment
- Resource requests/limits misaligned with actual usage
- Manual scaling causing over-provisioning
- Implementing showback/chargeback or a FinOps culture
Inputs
- Required: running cluster, cloud billing API access, metrics-server or Prometheus
- Optional: historical usage, allocation requirements, SLOs, budget targets
Procedure
Step 1 — Deploy cost visibility
Install Kubecost or OpenCost (Helm), wired to Prometheus, and configure cloud billing integration (AWS Athena/CUR, GCP service account, Azure config). Initial cloud sync can take 24-48h. Verify the UI shows cost by namespace/deployment/pod and the allocation API returns data.
Step 2 — Analyze utilization
Compare requests vs actual usage (kubectl top pods, Kubecost request-sizing recommendations at /model/savings/requestSizing?window=7d). Identify over-provisioned and idle resources. Wait at least 7 days of data before acting.
Step 3 — Horizontal Pod Autoscaling (HPA)
Scale replicas on CPU/memory or custom metrics for stateless, scalable workloads. Set sensible min/max replicas and target utilization based on P95/P99, not average.
Step 4 — Vertical Pod Autoscaling (VPA)
Right-size per-pod requests/limits. Start in "Off" (recommendation) mode, review for ~30 days, then apply gradually. Never run VPA and HPA on the same metric.
Step 5 — Spot / preemptible instances
Move fault-tolerant, stateless workloads to spot capacity for large savings. Never databases, stateful, or single-replica critical services. Always use PodDisruptionBudgets and node affinity/taints.
Step 6 — Resource quotas and budget alerts
Apply ResourceQuotas per namespace/team and LimitRanges for defaults. Configure budget alerts in Kubecost/cloud billing. Start with showback (informational) before chargeback.
Validation
Common Pitfalls
- Aggressive right-sizing causing OOMKills/throttling — apply gradually.
- HPA + VPA on the same metric conflict.
- Spot for stateful/critical services.
- Acting on too little data (need 7-30-90 day windows).
- Sizing on average instead of P95/P99 (burst throttling).
- Ignoring egress, storage (unused PVCs), and total cost of ownership.
- Quotas too restrictive; chargeback before teams trust the data.
Related
- conduct-post-mortem — for cost-incident retrospectives
1---2name: optimize-cloud-costs3description: "Use when cloud/Kubernetes spend is growing without matching value — for cost visibility (Kubecost/OpenCost), right-sizing, HPA/VPA autoscaling, spot/preemptible instances, resource quotas, budget alerts, and showback/chargeback FinOps. Triggers: cloud costs, FinOps, right-sizing, over-provisioning, Kubecost, spot instances, cost allocation."4version: 1.0.05license: MIT6tags: [cost-optimization, finops, kubecost, hpa, vpa, spot-instances, kubernetes, resource-management]7source: https://github.com/pjt222/agent-almanac/tree/main/skills/optimize-cloud-costs8derived_from: awesomeclaude9metadata:10 source: https://skillmd.com/skills/aashutosh396/optimize-cloud-costs11---1213# Optimize Cloud Costs1415Reduce cloud spend on Kubernetes workloads through visibility, right-sizing, autoscaling, spot capacity, and quotas — without breaking SLOs.1617## When to Use1819- Cloud costs growing without corresponding business value20- Need cost allocation by team, app, or environment21- Resource requests/limits misaligned with actual usage22- Manual scaling causing over-provisioning23- Implementing showback/chargeback or a FinOps culture2425## Inputs2627- Required: running cluster, cloud billing API access, metrics-server or Prometheus28- Optional: historical usage, allocation requirements, SLOs, budget targets2930## Procedure3132### Step 1 — Deploy cost visibility33Install Kubecost or OpenCost (Helm), wired to Prometheus, and configure cloud billing integration (AWS Athena/CUR, GCP service account, Azure config). Initial cloud sync can take 24-48h. Verify the UI shows cost by namespace/deployment/pod and the allocation API returns data.3435### Step 2 — Analyze utilization36Compare requests vs actual usage (`kubectl top pods`, Kubecost request-sizing recommendations at `/model/savings/requestSizing?window=7d`). Identify over-provisioned and idle resources. Wait at least 7 days of data before acting.3738### Step 3 — Horizontal Pod Autoscaling (HPA)39Scale replicas on CPU/memory or custom metrics for stateless, scalable workloads. Set sensible min/max replicas and target utilization based on P95/P99, not average.4041### Step 4 — Vertical Pod Autoscaling (VPA)42Right-size per-pod requests/limits. Start in "Off" (recommendation) mode, review for ~30 days, then apply gradually. Never run VPA and HPA on the same metric.4344### Step 5 — Spot / preemptible instances45Move fault-tolerant, stateless workloads to spot capacity for large savings. Never databases, stateful, or single-replica critical services. Always use PodDisruptionBudgets and node affinity/taints.4647### Step 6 — Resource quotas and budget alerts48Apply ResourceQuotas per namespace/team and LimitRanges for defaults. Configure budget alerts in Kubecost/cloud billing. Start with showback (informational) before chargeback.4950## Validation5152- [ ] Cost visibility tool reporting per-namespace/team allocation53- [ ] Right-sizing recommendations reviewed against SLOs54- [ ] HPA configured with appropriate min/max and percentile targets55- [ ] VPA validated in Off mode before applying56- [ ] Spot only on fault-tolerant workloads with PDBs57- [ ] Quotas and budget alerts in place5859## Common Pitfalls6061- Aggressive right-sizing causing OOMKills/throttling — apply gradually.62- HPA + VPA on the same metric conflict.63- Spot for stateful/critical services.64- Acting on too little data (need 7-30-90 day windows).65- Sizing on average instead of P95/P99 (burst throttling).66- Ignoring egress, storage (unused PVCs), and total cost of ownership.67- Quotas too restrictive; chargeback before teams trust the data.6869## Related7071- conduct-post-mortem — for cost-incident retrospectives