Skip to main content
Many platform engineers are surprised to learn their Kubernetes clusters are wasting money — not because pods are idle, but because workloads are overprovisioned. A team may request 2 CPUs per pod while actually using 50 millicores. Multiply that across dozens of deployments and the wasted spend adds up. The root cause is visibility: without tooling you can’t easily map spend to the team, namespace, or workload responsible. OpenCost fixes this by mapping Kubernetes resource usage to dollar cost per namespace, deployment, and pod in (near) real time. In this walkthrough we’ll:
  • Verify OpenCost and Prometheus are running.
  • Inspect the OpenCost UI.
  • Map pod and deployment resource requests to the costs OpenCost attributes.
  • Show how to make changes (scale/rightsizing) and where to look for the impact.
  • Demonstrate the OpenCost API for automation.
Prerequisites
  • A running Kubernetes cluster.
  • OpenCost deployed in the opencost namespace.
  • Prometheus available (OpenCost consumes Prometheus metrics).
Check that the OpenCost pod is running:
OpenCost consumes metrics from Prometheus. In this environment Prometheus runs in the prometheus-system namespace. For day-to-day exploration use the OpenCost UI — it provides a visual breakdown and lets you drill down by namespace, deployment, or pod. Below is an example OpenCost dashboard showing namespace cost allocation.
The image shows a cost allocation dashboard from OpenCost, displaying a chart and table that breaks down costs by namespace for a selected date. It includes details on CPU, GPU, RAM, personal volume, efficiency, and total costs in USD.
List relevant pods across namespaces so we can map costs back to workloads:
Summary of the running workloads (observations from the pod list):
  • team-frontend: several web replicas (3 total in this sample).
  • team-backend: two api replicas.
  • team-data: a single cache replica (Redis).
Inspect each deployment’s resource requests — OpenCost attributes cost primarily from resource requests (requests/limits) rather than instantaneous CPU usage, so requests drive allocated cost. Inspect the frontend deployment (web) in team-frontend:
In this deployment the container requests 500m CPU and 512Mi memory and the deployment is configured with 3 replicas (500m * 3 = 1.5 CPU requested across the namespace). Those requests drive the cost allocation, even if actual usage is much lower. Inspect the backend API deployment:
Example (trimmed) output:
The backend API requests 100m CPU and 128Mi memory per replica, so with 2 replicas it requests ~200m CPU in total. Inspect the cache deployment in team-data (Redis):
Example (trimmed) output:
Although Redis requests 250m CPU and 1Gi memory, this example only has a single replica. Deployment resource-request summary Why is Team Frontend more expensive in OpenCost? OpenCost attributes cost based on resource requests (and observed usage) to allocate spend to namespaces and workloads. Team Frontend requested 500m per replica across three replicas (1.5 CPUs total requested), while Backend requested only 100m per replica with two replicas (0.2 CPUs total). Those request differences explain the larger cost for frontend.
OpenCost maps requested resources (requests/limits) and observed usage to cost. Over-requesting increases allocated cost even if actual usage is low — that’s why rightsizing requests and replica counts matters.
Actionable steps: scale or rightsize based on OpenCost insights You can use the cost signals to change replica counts or adjust requests. For example, scale the frontend down and scale the cache up to better match demand (and to move costs where they belong):
Example responses:
Return to the OpenCost UI and refresh. As Prometheus metrics are aggregated you should see namespace and deployment costs adjust to reflect the new requested resources and replica counts.
The image is a cost allocation dashboard from OpenCost displaying a pie chart and a table showing namespace daily costs, with details on CPU, GPU, RAM, PV, efficiency, and total cost.
OpenCost API for automation If you prefer automation or integration, OpenCost exposes an API you can query. Example: get compute allocation aggregated by namespace over the last hour and format results with jq:
Sample JSON output (trimmed):
Use cases for the API:
  • Scheduled cost reports.
  • CI/CD gates to prevent cost spikes from PRs.
  • Automated alerts when request-to-usage ratios indicate overprovisioning.
Conclusion For exploration and fast triage, the OpenCost UI is convenient; for automation and programmatic workflows, use the API. Either way, OpenCost provides the visibility needed to identify overprovisioning, allocate cost to teams, and take concrete remediation steps like rightsizing requests or adjusting replica counts. Links and references

Watch Video

Practice Lab