What Is OpenCost? Kubernetes Cost Allocation, Idle Cost and Right-Sizing with VPA, on a Local Cluster

I right-sized an over-provisioned Kubernetes workload. Its cost line fell, __idle__ grew and the node total held. OpenCost, requests, VPA and showback.

By Mirac Can Yılmaz 28 min read
What Is OpenCost? Kubernetes Cost Allocation, Idle Cost and Right-Sizing with VPA, on a Local Cluster - platform-engineering yazısının kapak görseli

I right-sized an over-provisioned Kubernetes workload and then asked OpenCost what had changed. The team's cost line went down, as I hoped. A line called __idle__ went up by the same amount, and the price of the node per hour did not move at all. Nothing was saved. The cost had changed owner.

That is the part of Kubernetes cost work I wanted to see with my own eyes before writing about it. Cost tools are good at telling you who is using what. They cannot shrink a bill on their own, because on a cluster made of nodes you pay for the nodes, and a node costs the same whether its pods use it or not. This post walks through the whole chain on one laptop: how OpenCost turns a node's price into team lines, why requests and not usage decide those lines, what the __idle__ and __unallocated__ lines mean, what the Vertical Pod Autoscaler recommends when you only let it recommend, and where the money actually comes back.

One thing up front. No cloud account was used and no pricing API was called. OpenCost priced the node from a rate card I wrote into a ConfigMap. Every dollar figure in the terminal images is that rate card multiplied by time. The numbers are configuration, not a bill, and I use them only to show which way each line moves.

What is OpenCost?

OpenCost is an open source cost monitoring tool for Kubernetes, a CNCF project that started as the allocation engine inside Kubecost. It runs as one deployment in the cluster, reads resource requests, usage and labels from Prometheus, takes a price for every node (from a cloud provider's public price list, or from your own rate card on-premises) and answers one question through an API: over this time window, how much of the cluster's cost belongs to each namespace, label, controller or pod?

The words you meet in its output:

  • Allocation: the share of node cost charged to a workload over a window. For CPU and memory it is the larger of what the container requested and what it used, multiplied by the price and the time.
  • __idle__: the part of the nodes' cost that no container requested or used. You pay for it anyway.
  • __unallocated__: workloads that do not carry the label or annotation you aggregated by. Their cost is real; the tool just cannot tell whose it is.
  • Efficiency: usage divided by request. Low efficiency means you are paying for room you do not use.
  • Showback: telling each team what it costs. Chargeback: moving that cost into the team's budget. Same data, different consequences.

The problem, and why it matters

A Kubernetes cluster usually arrives as one line on the cloud bill: some instances, some disks, some traffic. Ten teams share it. When the line grows, nobody can say which team grew it, so nobody acts, and the platform team ends up defending a number it does not control.

The second problem is quieter. Kubernetes reserves capacity on requests, not on usage. A team that copies cpu: 1 from a sizing document into a service that needs a fraction of that has reserved a whole core per replica. The scheduler treats that core as taken, the cluster autoscaler adds nodes when new pods do not fit, and the bill follows. The service runs fine, so nothing tells the team. The only symptom is a cluster that keeps growing while its CPU graphs stay flat.

Neither problem fixes itself. Dashboards of CPU usage look healthy exactly when requests are oversized, and asking teams to "be careful with resources" without showing them a number has never worked anywhere I have seen. What a cost tool adds is a per-team line that people can read, argue about and change.

What cost visibility gives you

In practice What I saw in the lab
A line per team the shared bill becomes something each owner can read aggregate=label:team split the node into payments, discovery, __unallocated__ and __idle__
Requests made visible over-sized services show up without anyone reporting them the same process cost far more in the namespace whose pods asked for a core each
An idle line capacity you pay for and nobody uses becomes a number with a name __idle__ was there from the first query; it grew when I right-sized
A label audit for free missing ownership labels show up as __unallocated__ every pod without a team label, system pods included, landed there
A starting point for right-sizing low efficiency points at which requests to look at VPA's recommendation for the oversized service was a small fraction of what it asked for

The cost: Prometheus has to keep enough history, and its storage and memory are now part of what you run. The rate card or the billing integration has to be maintained. And a team line is only as fair as the labels and the idle policy behind it, which is a conversation, not a setting.

How it works: one node, two teams, one rate card

Diagram: on the left, the inputs, a rate card in a ConfigMap (CPU 0.04 per vCPU-hour, RAM 0.005 per GiB-hour) and Prometheus with cAdvisor usage and the kube_* request and label series OpenCost exports itself. In the middle, the OpenCost cost model: node cost is capacity times rate times time, container cost is the larger of request and usage times rate times time, and idle is node cost minus the sum of container costs. On the right, the /allocation API with aggregate by namespace, label:team or controller and the includeIdle and shareIdle options; pods without the label go to __unallocated__. Below, two bars of the same 4 vCPU node. Before: checkout requests 2000m and uses a sliver, search is a thin slice, system and monitoring about one core, the rest idle. After applying the VPA target by hand: checkout is a thin slice, idle covers most of the node, the node price per hour is the same.

Where the numbers come from

OpenCost does not measure anything itself. It reads three things:

  1. Prices. On AWS, GCP and Azure it can look up the on-demand list price of each node's instance type. On-premises, or in a lab like this one, it reads a rate card: a price per vCPU-hour, per GiB-hour of memory, per GPU-hour and per GiB-hour of storage. I set CPU to 0.04 and RAM to 0.005. Those values are mine; any internal rate card works the same way.
  2. Requests and labels. OpenCost exports its own kube_* series (pod labels, namespace labels, container requests), so in this lab I did not install kube-state-metrics. Prometheus scrapes them from OpenCost.
  3. Usage. cAdvisor, built into the kubelet, reports what each container actually used. Prometheus scrapes it.

Then the model is short. A node costs its capacity times the rate for every minute it exists. Each container is charged the larger of its request and its usage, times the rate, for every minute it runs. What is left of the node is __idle__.

Requests, limits and why requests drive the bill

A request is a reservation. The scheduler places a pod only on a node with enough unreserved capacity for its requests, and from then on that capacity is not available to anyone else. A limit is a ceiling. A container over its CPU limit is throttled; a container over its memory limit is killed.

Cost follows the reservation, for a plain reason: the node was bought to hold it. If you request a core and use a tenth of it, the other nine tenths cannot be given to another pod, so they are yours. OpenCost encodes that with max(request, usage). A container that bursts above its request pays for the burst too, which is fair, because it used capacity somebody else reserved or nobody did.

Limits barely enter the bill. They matter for stability and for how noisy a neighbour can be. I set a memory limit on every container in the lab and no CPU limit, which is the common pattern: memory overuse kills, CPU overuse only slows.

Bin packing, and why right-sizing alone saves nothing

The scheduler packs pods onto nodes by their requests. A cluster autoscaler (or Karpenter on AWS) adds a node when a pod cannot be placed, and removes one when everything on it fits elsewhere. Both look at requests.

So the saving from smaller requests is indirect. It shows up only when the freed room lets the autoscaler run fewer or smaller nodes. On a fixed set of nodes, right-sizing moves cost from the team that over-asked to __idle__, and the bill stays where it was. That is the opening of this post, and it is the most useful thing the lab showed me: right-sizing is the first half of the job; bin packing and scale-down are the second.

Idle, shared or not

The __idle__ line is a policy question with a technical switch. Shown as its own line, it tells the platform team how much capacity it bought and nobody used. Shared (shareIdle=true), it is spread over the teams in proportion to their cost, so each team's line adds up to the whole bill. The first is honest about where the waste is; the second makes the numbers add up for finance. Most organisations I know show both and argue about which one goes into budgets.

The lab

One kind node on Colima, a small Prometheus, OpenCost with the rate card, and two teams that run the same busybox loop. checkout (team payments) asks for a core and 1 GiB per replica, the way a copied sizing document would. search (team discovery) asks for 50m and 32Mi. Two replicas each. Every phase is a script with assertions; the images below are its real output.

The lab writes its own kubeconfig and never changes the default context, because two other kind clusters were running on the same machine while I worked.

1. Prometheus, OpenCost and a rate card

The Prometheus chart runs with the server only: no Alertmanager, no Pushgateway, no node exporter, no kube-state-metrics, six hours of retention and no persistent volume. One extra scrape job points at OpenCost. The OpenCost chart gets the custom pricing block, the in-cluster Prometheus service and the UI switched off.

Terminal: helm installs p27-prometheus 31.0.0 into p27-monitoring and p27-opencost 2.5.35 into p27-opencost, both STATUS deployed. kubectl rollout status waits until deployment p27-opencost successfully rolled out. The rate card read back from the custom-pricing-model ConfigMap: description p27 internal rate card (made up, per hour), CPU 0.04, RAM 0.005, spotCPU 0.012, spotRAM 0.0015, storage 0.0001, provider custom. OpenCost's environment: PROMETHEUS_SERVER_ENDPOINT=http://p27-prometheus-server.p27-monitoring.svc.cluster.local:80, CLUSTER_ID=opencost-lab, CONFIG_PATH=/tmp/custom-config. Prometheus targets: kubernetes-api-servers, kubernetes-nodes, kubernetes-nodes-cadvisor, kubernetes-service-endpoints, opencost and prometheus, all up. PASS lines for the opencost scrape, the cAdvisor scrape and GET /healthz returning 200.

The two checks that matter are in the middle: Prometheus scrapes the opencost job, and it scrapes kubernetes-nodes-cadvisor. Without the first OpenCost has no requests or labels; without the second it has no usage. The first time I installed this, neither check was reached. More on that in "Where it broke".

2. Two teams, and a node that is full on paper

Terminal: two namespaces, p27-checkout with team payments and cost-center cc-1001, p27-search with team discovery and cost-center cc-2002. Four pods: two checkout-api pods each requesting cpu 1 and memory 1Gi with a 1Gi limit, two search-api pods each requesting 50m and 32Mi with a 64Mi limit. kubectl describe node, Allocated resources: cpu requests 3165m, memory requests 2738Mi. Then checkout is scaled to three replicas; the new pod stays Pending and the event reads: 0/1 nodes are available: 1 Insufficient cpu. preemption: 0/1 nodes are available: 1 No preemption victims found for incoming pod. PASS third replica Pending on requests, not on usage.

This is the scheduler's view of the cluster, and it is the one that costs money. The node has four cores. The pods on it use very little of them; you will see how little in the next step. But the requests add up to most of the node, so a third checkout replica cannot be placed: 0/1 nodes are available: 1 Insufficient cpu. On a cloud cluster with an autoscaler, this is the moment a new node is bought. Nothing in a CPU usage graph would explain why.

3. Reading the allocation API

OpenCost answers on /allocation. The parameters that matter: window (a duration like 30m or an explicit start,end), aggregate (namespace, controller, pod, label:<name> and others), accumulate=true to get one set for the whole window, and includeIdle / shareIdle for the idle line. The phase waits until twelve minutes of data exist after the pods became ready, then asks four questions.

Terminal: GET /allocation for the window 14:28 to 14:41 UTC aggregated by namespace with includeIdle=true. Columns CPU REQ, CPU USE, RAM REQ, RAM USE, CPU $, RAM $, TOTAL $. p27-checkout requests 2.000 cores and uses 0.016, requests 2048Mi and uses 1Mi, and has the largest total. __idle__ follows. kube-system requests 0.950 cores. p27-monitoring, p27-search (0.100 cores requested, 0.016 used, 64Mi requested), p27-opencost and local-path-storage are small. Aggregated by label:team: payments, __idle__, __unallocated__ (1.065 cores requested, all the pods without a team label) and discovery. Aggregated by controller for the two team namespaces: deployment:checkout-api cpuEfficiency 0.008, deployment:search-api cpuEfficiency 0.158.

Read the first table by columns, not rows. p27-checkout and p27-search have the same usage, because they run the same loop. Their requests differ, and the cost follows the requests. Checkout is the biggest line on the node, bigger than kube-system, for a process that does almost nothing.

The second table is the same data grouped by the team label. Everything without that label, the control plane, CoreDNS, Prometheus, OpenCost itself, went into __unallocated__. In a real cluster this is the first useful report you get from a cost tool: the list of workloads nobody has claimed. In mine it was the system pods. In a company cluster it is usually a few forgotten services too.

The third table is efficiency per Deployment, usage over request. Checkout's rounds to almost nothing. Search's is low as well, because even 50m is more than a sleeping shell loop needs. Efficiency is a pointer, not a verdict: a service sized for its daily peak will look inefficient at night, and that is correct.

The fourth question was about idle, and it taught me something about the API:

Terminal: aggregate=label:team with shareIdle=true but without includeIdle: payments, __unallocated__ and discovery keep their unshared values and the sum drops, because the idle cost is simply left out. With includeIdle=true and shareIdle=true: the same three lines are larger, there is no __idle__ line, and the sum matches the unshared total including idle. Assertions: checkout cpu request average 2 and usage average 0.0156; PASS checkout is billed on requests; PASS same process, checkout's line is far above search's; PASS __idle__ carries the node cost nobody requested; PASS pods without a team label are __unallocated__; PASS shareIdle alone drops __idle__ from the total, with includeIdle it is spread and the total holds.

shareIdle=true on its own did not spread the idle cost. It dropped it: the team lines stayed as they were, the __idle__ line disappeared, and the sum got smaller. Only with includeIdle=true as well did the idle cost get spread over the teams so that the lines add up to the node again. A report built on the first query would quietly lose part of the bill, and nobody would notice until finance compared it with the invoice. The phase now asserts both sums.

4. VPA in recommendation mode

The Vertical Pod Autoscaler has three parts: a recommender that watches usage and computes requests, an updater that evicts pods whose requests are far from the recommendation, and an admission webhook that rewrites requests when pods are created. I installed only the recommender and set updateMode: "Off" on both VPA objects. It recommends; nothing touches the pods.

Terminal: the VPA 0.17.0 chart deploys only the recommender, image registry.k8s.io/autoscaling/vpa-recommender:1.8.1. Two VPA objects with mode Off. With no metrics API, kubectl top says error: Metrics API not available, and the recommender logs Cannot get ContainerMetricsSnapshot from MetricsClient, the server could not find the requested resource (get pods.metrics.k8s.io). kubectl get vpa nevertheless shows PROVIDED True with cpu 25m and memory 250Mi for both workloads. Then metrics-server 3.14.0 with chart defaults: the pod stays 0/1 Running and logs Failed to scrape node, x509: cannot validate certificate for 172.20.0.5 because it doesn't contain any IP SANs. With --kubelet-insecure-tls, kubectl top shows the four pods using around 10m CPU each. The recommendations, next to the requests: checkout cpu request 1000m, target 25m; memory request 1024Mi, target 250Mi. Search cpu request 50m, target 25m; memory request 32Mi, target 250Mi. PASS VPA recommends less than checkout requests; PASS VPA recommends MORE memory than search requests; PASS updateMode Off, the pods still carry their original requests.

Three things in that image surprised me.

First, VPA published a recommendation before it had seen a single sample. With no metrics API in the cluster, kubectl get vpa already said PROVIDED True, 25m, 250Mi. Those are the recommender's floors: by default it never recommends less than 25m of CPU or 250Mi of memory per pod. A recommendation that looks finished and is made of defaults is easy to apply by mistake.

Second, metrics-server does not work on kind out of the box. The kubelet serves a self-signed certificate without IP addresses in it, and metrics-server refuses it with x509: cannot validate certificate for 172.20.0.5 because it doesn't contain any IP SANs. --kubelet-insecure-tls fixes it for a lab. On a real cluster the fix is a kubelet serving certificate with the right names, not that flag.

Third, the recommendation with real data was the same as the one without, for the same reason: this workload uses less than the floor. For checkout that still means "ask for a small fraction of what you ask for now", which is the useful part. For search it means "ask for more memory than you do now", which is the floor talking, not the usage. On small services the floor dominates. The recommender takes --pod-recommendation-min-cpu-millicores and --pod-recommendation-min-memory-mb if your services are genuinely that small; I left the defaults so that you can see them.

5. Right-size by hand, then ask again

I applied the VPA target to checkout by hand, 25m and 250Mi with a 500Mi memory limit, and waited for ten minutes of fresh data. Then the same query, for a window before the change and a window after, converted to a rate per hour so that windows of different length can be compared.

Terminal: kubectl set resources gives checkout-api requests of cpu 25m and memory 250Mi with a 500Mi limit, and the rollout completes. The before table, window 14:28 to 14:41 UTC: p27-checkout requests 2.000 cores and 2048Mi and is the largest line, __idle__ second. The after table, window 14:48 to 14:58 UTC: __idle__ is now the largest line, p27-checkout requests 0.050 cores and 500Mi and is one of the smallest, next to p27-search; p27-vpa appears with the recommender and metrics-server. The per-hour comparison: p27-checkout down, p27-search same, __idle__ up, everything else roughly the same, cluster (node) total same. PASS checkout's line went down; PASS __idle__ went up, the node is still paid for; PASS cluster total unchanged, right-sizing alone does not shrink a node bill. Then checkout scaled to three replicas: all three Running. PASS third replica scheduled after right-sizing.

Read the per-hour table from the bottom up. The cluster total is the same before and after, because it is the node's capacity times the rate card, and the node did not change. Inside that total, checkout's line fell from the largest team line to one of the smallest, and __idle__ grew by almost exactly what checkout gave back. Search did not move; it was not touched.

The team got what it wanted: its line is small now. The company got nothing yet. If this were a cloud cluster, the bill for the hour after the change would be the bill for the hour before.

The last lines of the image are where the saving starts. The third checkout replica that stayed Pending in step 2 now schedules on the same node. The node can hold more pods than before. On a cluster with an autoscaler, that is the difference between buying the next node and not buying it, and between a half-empty node that can be drained and one that cannot. Right-sizing makes room. Something else has to turn the room into fewer nodes.

6. Failures on purpose

The last phase breaks things the way they break in real clusters, and records what each failure looks like from the outside.

Terminal: six failures. 1, GET /allocation for a day in November 2025 returns {"code":200,"data":[{}]}, an empty set and no error. 2, window=last-tuesday returns Invalid 'window' parameter: illegal window: last-tuesday. 3, aggregate=label:owner puts every pod into a single __unallocated__ line. 4, PROMETHEUS_SERVER_ENDPOINT set to http://prometheus-server.prometheus-system.svc.cluster.local:80, the chart's default service name: the new pod is in CrashLoopBackOff and logs FTL Failed to create Prometheus data source: failed to query prometheus ... dial tcp: lookup prometheus-server.prometheus-system.svc.cluster.local, and the API answers nothing; kubectl rollout undo brings it back. 5, Prometheus scaled to zero: /allocation returns code 500, error computing allocations, Request Error: query error, Post to p27-prometheus-server failed. 6, Prometheus scaled back to one: the window from step 3 now returns no allocation sets. PASS history gone with the Prometheus pod: no persistent volume, no past.

In order:

  1. A window with no data is {"code":200,"data":[{}]}. Not an error. A scheduled report that asks for the wrong day will happily publish an empty table.
  2. A window OpenCost cannot parse is refused with Invalid 'window' parameter: illegal window: last-tuesday. Good: this one fails loudly.
  3. A label nobody set sends every pod to __unallocated__. The API does not tell you the label does not exist. A typo in label:tema looks exactly like a cluster where nobody is labelled.
  4. The wrong Prometheus address, here the chart's default service name instead of my release's, is the most likely mistake on a first install. OpenCost does not start: FTL Failed to create Prometheus data source, then CrashLoopBackOff. While it crash-loops, the API is simply not there.
  5. Prometheus gone while OpenCost runs is a 500 with the failing PromQL query in the message. OpenCost keeps no copy of its own here; Prometheus is the database.
  6. Prometheus back, on an emptyDir. It came up empty. The window I had read in step 3 now returns nothing. I chose no persistent volume to keep the lab small, and this is the price: cost history lives exactly as long as the Prometheus data it is computed from.

Limits and rules you only learn by hitting them

  • OpenCost needs Prometheus at start. It queries up when it starts and exits if that fails. A wrong endpoint is a crash loop, not a degraded mode.
  • clusterName in the Helm chart is the cluster DNS domain, cluster.local by default. It is not a display name. The display name is defaultClusterId.
  • History is Prometheus's retention. Six hours of retention means six hours of cost data. For monthly showback you need long retention, a remote store such as Thanos or Mimir, or a newer OpenCost setup that keeps its own data.
  • Windows are UTC and resolution matters. The chart's default query resolution is five minutes; for short lab windows I set queryResolutionSeconds: 60. A window shorter than the resolution returns very little.
  • An empty window is a 200 with empty data, not an error. A report that silently prints nothing for a day looks the same as a report for a day when nothing ran.
  • shareIdle=true needs includeIdle=true, or the idle cost is dropped from the total. Check that your team lines add up to the node cost.
  • __unallocated__ depends on what you aggregate by. Group by namespace and it is empty; group by a label and every pod without it lands there.
  • Labels must be on pods, not only on Deployments. OpenCost reads pod labels and namespace labels. A team label on the Deployment's own metadata is invisible to it.
  • List prices are not your price. Out of the box, cloud nodes are priced at on-demand list price. Reserved instances, savings plans, committed use discounts and negotiated rates only appear with the cloud billing integration.
  • VPA has floors (25m, 250Mi by default) and publishes them before it has data.
  • VPA in Auto mode evicts pods to apply new requests. With fewer than two replicas or a strict PodDisruptionBudget that can mean downtime. Recommendation mode first, always.
  • VPA and the Horizontal Pod Autoscaler should not act on the same metric. If HPA scales on CPU utilisation, which is usage over request, and VPA changes the request, they chase each other.

Moving a fleet, not a lab

One node and two teams is a lab. Fifty services across a few clusters is where this either becomes a habit or a dashboard nobody opens.

  1. Labels first. Decide the ownership labels (team, cost-center, maybe product) and enforce them at admission. A policy that rejects pods without a team label, in audit mode first, is the cheapest cost control you will ever deploy. The Kyverno and Cilium post shows the admission side.
  2. Showback before chargeback. Publish each team's line for a few months with idle shown separately. Let teams find the mistakes in the data. Charge only when the numbers are trusted.
  3. Decide the idle policy in writing. Who carries idle: the platform team, the teams in proportion, or a fixed overhead? Each choice changes behaviour. If teams never see idle, they have no reason to help bin packing.
  4. Prometheus is now a cost system. Give it retention, or a remote store, that matches the reporting period. The Prometheus and Grafana post covers the basics of running it.
  5. Right-size in a loop, not a project. VPA in recommendation mode on everything, a weekly report of the largest gaps between request and recommendation, and a pull request per service to change requests. The change is reviewed like any other.
  6. Then shrink the nodes. Turn on scale-down in the cluster autoscaler or consolidation in Karpenter, and check that pods can actually move: PodDisruptionBudgets that allow eviction, no local storage pinning pods, no single replica for anything important. This is where the bill changes.
  7. Spot for what can be interrupted. Batch jobs, CI runners, stateless replicas behind a load balancer. Price spot nodes separately in the rate card (spotCPU, spotRAM) or let the billing integration do it, and label them so the scheduler and the report both know.
  8. Reconcile with the real bill. OpenCost's cloud cost integration reads the provider's billing export (AWS Cost and Usage Report, GCP BigQuery billing export, Azure cost exports) and replaces list prices with what you actually paid. I did not run it here; it needs a real account and a billing export.

Frequently asked

What is the difference between OpenCost and Kubecost? OpenCost is the open source, CNCF-hosted cost allocation engine. Kubecost is the commercial product it came out of, built on the same engine, with extras on top: savings recommendations, alerts, a multi-cluster view, longer retention and enterprise access control. For a per-team cost line on one or a few clusters OpenCost is enough; the extras are about scale and workflow.

Does OpenCost work without a cloud provider? Yes. On-premises, or on kind as here, it uses a custom rate card: prices per vCPU-hour, GiB-hour of memory, GPU-hour and storage. The lines it produces are as good as that rate card.

Why does OpenCost charge for requests and not for usage? Because the node is reserved by requests. Capacity a pod requested cannot be given to another pod, so it is paid for whether it is used or not. OpenCost charges the larger of request and usage, so bursts above the request are charged too.

What is __idle__ in OpenCost? The part of the nodes' cost that no container requested or used. It is real money: capacity you bought and did not assign. You can show it as its own line or share it across teams with includeIdle=true&shareIdle=true.

What is __unallocated__? Workloads that do not have the label or annotation you are aggregating by. If you group by label:team, every pod without a team label is there. It is a list of unowned workloads.

Will right-sizing my pods reduce my Kubernetes bill? Only if it leads to fewer or smaller nodes. On a fixed number of nodes, smaller requests move cost from the team to idle. The bill drops when the cluster autoscaler or Karpenter can remove a node because the pods now fit on fewer.

Should I run VPA in Auto mode? Not first. Run it in Off mode, read the recommendations next to the requests for a while, apply them through pull requests, and only then decide whether automatic updates fit a service. Auto mode evicts pods to change their requests, and its floors and its view of history may not match how your service behaves under load.

What is the difference between showback and chargeback? Showback reports each team's cost without moving money. Chargeback puts that cost into the team's budget. Showback is how you find out whether the numbers are trusted; chargeback is what changes behaviour, and also what starts the arguments.

Where it broke

1. FTL Failed to create Prometheus data source: failed to query prometheus at http://p27-prometheus-server.p27-monitoring.svc.opencost-lab:80

My first install. I set clusterName: opencost-lab in the chart values, thinking it was a display name. The chart uses it as the cluster DNS domain and builds the Prometheus URL from it, so the lookup went to ...svc.opencost-lab and failed with no such host. OpenCost exits when its first Prometheus query fails, so the pod went into CrashLoopBackOff. The fix was to remove the line and set the name through defaultClusterId.

2. STATUS: deployed while the only OpenCost pod was crash-looping

Same install. helm upgrade --install --wait reported success. The chart's update strategy has maxUnavailable: 1, and with one replica that means zero ready pods is acceptable to Helm's wait. kubectl rollout status is what timed out and told me. The lab now runs both.

3. shareIdle=true and the sum got smaller

Not an error message, which is why it is dangerous. Without includeIdle=true, shareIdle=true dropped the idle cost instead of spreading it. The lab asserts that the shared total equals the unshared total with idle.

4. PROVIDED True with 25m and 250Mi, and no metrics in the cluster

VPA's recommendation before metrics-server existed. The recommender logged Cannot get ContainerMetricsSnapshot from MetricsClient and still published its floors as a recommendation. Read the recommender's logs, or check that kubectl top works, before trusting the numbers.

5. x509: cannot validate certificate for 172.20.0.5 because it doesn't contain any IP SANs

metrics-server with chart defaults on kind. The pod stays 0/1 and kubectl top says error: Metrics API not available. --kubelet-insecure-tls fixes it in a lab; proper kubelet serving certificates fix it in production.

6. {"code":500,"data":null,"message":"error computing allocations for [...]: Error Collection: ... Request Error: query error"

Prometheus scaled to zero. OpenCost stays up and every allocation query fails with the PromQL it tried to run. When it came back on its emptyDir, the earlier window returned data: no allocation sets in this window. The history had gone with the pod.

7. 0/1 nodes are available: 1 Insufficient cpu

Not a bug, the point of step 2. I include it because this is the line people search for when a cluster with flat CPU graphs refuses a pod. The answer is in kubectl describe node under "Allocated resources", not in a usage dashboard.

8. bind: address already in use on 127.0.0.1:4670

My own leftover. A kubectl port-forward I had started by hand was still holding the port when the phase script started its own, and the script's health check talked to my old forward instead. It happened to work, which is worse than failing. The helper now refuses to start when the port already answers.

9. A phase that printed only PASS lines and exited with 1

Also mine. The scripts kill their port-forwards in an EXIT trap, under set -e. When the port-forward had already died, kill returned non-zero inside the trap and became the script's exit code. kill ... || true fixed it. Tests need testing too.

10. sed: RE error: maximum repetition exceeds 255

I trimmed long log lines with sed -E 's/^(.{0,330}).*/\1/'. GNU sed accepts that; the BSD sed on macOS does not. cut -c1-330 does the same job everywhere.

The trade-off, side by side

Idle cost:

Idle as its own line Idle shared across teams
Plus waste has a name and an owner (the platform); teams see only what they asked for team lines add up to the whole bill; finance can use them directly
Minus team lines do not add up to the invoice; someone has to explain the gap every month waste is hidden inside every team's line; a team that right-sizes still pays for the others' idle
Where it fits showback, and any phase where you are still tuning bin packing chargeback, once requests are reasonable and idle is small

Right-sizing approach:

Requests by hand from reports VPA recommendation, applied by PR VPA in Auto mode
Plus full control; the owner decides a number from data, with a review step; no evictions you did not plan requests follow usage without anyone acting
Minus slow; drifts back as services change floors and short history can mislead; someone still has to open the PR evicts pods to apply changes; fights HPA on CPU; hard to reason about during an incident
Where it fits a few critical services with known load most stateless services batch and internal services with several replicas and a tolerant PDB

Node purchase:

On-demand nodes Spot / preemptible nodes
Plus stay until you remove them; simple capacity planning much cheaper capacity for the same instance types
Minus full price, every hour, used or not can be reclaimed at short notice; capacity can disappear in a zone; needs workloads that tolerate it
Where it fits stateful workloads, control planes, anything with a single replica batch jobs, CI runners, stateless replicas spread across zones

None of the columns wins by itself. In my own clusters idle is shown as a separate line, right-sizing goes through pull requests from VPA recommendations, and spot capacity is kept for things that can be restarted.

When to use which

  • Install a cost tool before you need it. The first useful report is the list of __unallocated__ workloads, and it costs nothing to read.
  • Use OpenCost when you want per-team lines on one or a few clusters and are happy to run Prometheus. Look at Kubecost or a commercial FinOps platform when you need many clusters in one view, savings workflows and access control.
  • Use a rate card on-premises, and as a first step in the cloud. Add the billing integration when the numbers start being used for money.
  • Show idle separately until bin packing is under control. Share it when it is small enough not to distort team lines.
  • Run VPA in recommendation mode everywhere, and change requests through review.
  • Measure success by node count, not by efficiency scores. Efficiency that does not lead to fewer nodes is a better report, not a smaller bill.

Your call

I show idle as its own line and keep chargeback out of it until the teams trust the numbers. That is for platforms where the same team owns the nodes and the cost tool; an organisation with a strong FinOps function may reasonably want shared idle from day one, so that every dollar has a team. Two things I would like to hear from real clusters:

  • Who carries idle cost in your cluster: the platform team, the product teams, or nobody because nobody sees it?
  • Do your teams' requests come from data, from a template, or from the last incident?

I am not after who is right. I want the pluses and minuses in the tables above to be visible to everyone who reads this, in words from real clusters, and the comments are where that happens: https://www.linkedin.com/in/mirac-can-yilmaz

Summary

  • OpenCost turns node prices into per-namespace, per-label and per-controller cost lines from Prometheus data. On-premises it uses a rate card; in the cloud it can use list prices and, with the billing integration, real prices.
  • Cost follows requests: a container is charged the larger of what it requested and what it used. Two copies of the same process cost very different amounts when their requests differ.
  • __idle__ is the part of the nodes nobody requested; __unallocated__ is the part nobody labelled. Both are worth reading before any chart.
  • shareIdle=true without includeIdle=true dropped the idle cost from the total in my run. Check that the lines add up.
  • VPA in recommendation mode gave a useful target for the oversized service, published its floors before it had any data, and recommended more memory than the small service asked for.
  • Right-sizing on a fixed node moved cost from the team to idle and left the node total unchanged. The money comes back only when bin packing and scale-down remove a node.

Next in the series

This is post 13 of Core Skills. Previous: What Is Velero?. Next: Kubernetes RBAC from zero, and an audit of who can actually do what in a cluster.

The code for this lab (Helm values, the two teams, the VPA objects, the phase scripts with their assertions and the table printers) is shared with Lab Access members on Buy Me a Coffee; the repo invite comes by email after you join: https://buymeacoffee.com/miraccanyilmaz/membership

About the author

Mirac Can Yılmaz

Mirac Can Yılmaz DevOps & Platform Engineer

I work as a DevOps and platform engineer with Kubernetes, GitOps (Argo CD), CI/CD and Terraform. Every post here was tried and measured in my own lab, on kind and Talos clusters: the commands, the errors and the numbers as they happened. The lab code is shared with Lab Access members on Buy Me a Coffee.

Hayatta en hakiki mürşit ilimdir.
Mustafa Kemal Atatürk