Demo showing how OpenCost maps Kubernetes resource requests and usage to dollar costs, using UI and API to find overprovisioning and enable rightsizing and scaling to reduce waste.
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:
kubectl get pods -n opencostNAME READY STATUS RESTARTS AGEopencost-5b676b669f-pc9hk 2/2 Running 3 78m
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.
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:
kubectl describe deploy web -n 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:
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):
kubectl describe deploy cache -n team-data
Example (trimmed) output:
Name: cacheNamespace: team-dataReplicas: 1 desired | 1 updated | 1 total | 1 availablePod Template: Containers: redis: Image: redis Limits: cpu: 500m Requests: cpu: 250m memory: 1GiConditions: Progressing True NewReplicaSetAvailable Available True MinimumReplicasAvailableEvents: Normal ScalingReplicaSet 38m deployment-controller Scaled up replica set cache from 1 to 2 Normal ScalingReplicaSet 34m deployment-controller Scaled down replica set cache from 2 to 1
Although Redis requests 250m CPU and 1Gi memory, this example only has a single replica.Deployment resource-request summary
Deployment
Namespace
Replicas
CPU request (per pod)
Memory request (per pod)
Total CPU requested
web
team-frontend
3
500m
512Mi
1.5 CPU
api
team-backend
2
100m
128Mi
0.2 CPU
cache
team-data
1
250m
1Gi
0.25 CPU
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 insightsYou 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):
# Scale frontend web down to 1 replicakubectl scale deployment web -n team-frontend --replicas=1# Scale cache up to 2 replicaskubectl scale deployment cache -n team-data --replicas=2
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.
OpenCost API for automationIf 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:
Automated alerts when request-to-usage ratios indicate overprovisioning.
ConclusionFor 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