2 CPUs while using 50m), and when you multiply that across dozens of deployments, the bill grows quickly.
The root cause is visibility. Without per-resource cost allocation you can’t easily tell which team or workload is responsible for spend. OpenCost maps Kubernetes resource requests and usage to dollar cost in real time — per namespace, deployment, and pod — so you can identify and act on cost drivers.
In this lesson we examine a sample stack and show how OpenCost reveals where the cost comes from and how simple changes can reduce it.
OpenCost runs in its own namespace and relies on a Prometheus stack for metrics. Inspect OpenCost and Prometheus pods:
team-frontend, team-backend, and team-data.
Kubernetes scheduling and cost allocation are typically based on resource requests. Over-requesting CPU and memory directly increases your accounted cost, even if actual runtime usage is low.
- team-frontend (
web) — five replicas - team-backend (
api) — two replicas - team-data (
cache) — one replica
Describe the
web deployment in team-frontend:
500m CPU and 512Mi memory. With five replicas, total requested CPU is 2.5 cores — this is why team-frontend appears as the most expensive namespace.
Describe the api deployment in team-backend:
100m CPU and 128Mi memory. With two replicas, total requested CPU is 200m (0.2 CPU).
Describe the cache deployment in team-data:
250m CPU and 1Gi memory (limits 500m / 2Gi).
Why is team-frontend the most expensive?
Because cost allocation is typically based on requested resources. Five frontend replicas each requesting 500m yields 2.5 CPU total, which translates directly into higher cost compared to backend (0.2 CPU) and data (0.25 CPU).
If you need reliability (for example for a database), it’s reasonable to request more resources. But for stateless frontends, you can often right-size requests and replicas.
Before changing replica counts or resource requests in production, validate performance and run load tests. Rightsizing without testing can affect availability.
jq:
- OpenCost — https://www.opencost.io/
- OpenCost API docs — https://docs.opencost.io/api/
- OpenCost docs — https://docs.opencost.io/
- Prometheus — https://prometheus.io/
- Kubernetes — https://kubernetes.io/
- jq — https://stedolan.github.io/jq/