Skip to main content
Many platform engineers are surprised to discover their Kubernetes clusters are wasting money — not because workloads aren’t running, but because they are overprovisioned. Teams commonly request resources far above actual usage (for example, requesting 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:
For a complete cross-namespace view:
OpenCost’s dashboard (and API) provides a visual and programmatic breakdown of cluster cost by CPU, memory, and storage. You can drill down by namespace, deployment, and pod. In this example cluster we have three application namespaces with workloads: 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.
Let’s inspect each deployment to see the requested resources that drive cost.
  • team-frontend (web) — five replicas
  • team-backend (api) — two replicas
  • team-data (cache) — one replica
Summary: requested resources and total impact Describe the web deployment in team-frontend:
Each web pod requests 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:
Each API pod requests 100m CPU and 128Mi memory. With two replicas, total requested CPU is 200m (0.2 CPU). Describe the cache deployment in team-data:
The cache pod requests 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.
Optimizing the cluster in this example is straightforward. For instance, scale down the frontend and scale up the cache:
After making these changes, refresh the OpenCost UI. As the new pods start and Prometheus collects fresh metrics, the cost allocation will reflect the updated requested resources and namespace-level costs should normalize. You can also query OpenCost’s API directly for automation. The example below requests a one-hour window aggregated by namespace and formats selected fields with jq:
Example output (one JSON object per namespace):
The API outputs the same allocation data you see in the GUI and can be used to automate reports or integrate cost checks into CI/CD pipelines and governance workflows. That was our demo on OpenCost. Use the UI for quick exploration and the API for automation. Links and references

Watch Video

Practice Lab