k8s-cost-waste-alerts

by Oreon Information Technology

Helm chartv0.2.2App 0.1.0MITVerified publisher

What a Kubernetes cluster costs and where the money is wasted - cluster cost and showback per namespace with node prices from flat rates, an instance-type price list or OpenCost, requests far above usage, unrequested node capacity, savings levers (right-sizing, consolidation, spot, commitments), idle volumes and load balancers, and HPAs at their limits. Recording rules, alerts and a Grafana dashboard.

About this chart

k8s-cost-waste-alerts

What a Kubernetes cluster costs, who uses it, and where the money is wasted, as Prometheus rules and a Grafana dashboard. No SaaS and no cloud billing export: kube-state-metrics and the kubelet's cAdvisor metrics, which kube-prometheus-stack already scrapes, plus node prices from a flat rate, your instance-type price list, or OpenCost.

AlertFires whenDefault
NamespaceCPUOverRequesteda namespace leaves more than 70 % of its CPU requests unused (24 h average) and requests at least 2 coreswarning, 1h
NamespaceMemoryOverRequestedsame for memory, at least 4 GiB requestedwarning, 1h
ClusterCPUUnderCommitted / ClusterMemoryUnderCommittedless than 40 % of allocatable capacity is requested across the cluster (nodes oversized or autoscaler not scaling in)info, 6h
UnusedPersistentVolumeClaima PVC has not been mounted by any pod for 7 daysinfo, 7d
UnusedLoadBalancerServicea LoadBalancer service has had no ready endpoints for a daywarning, 1d
HPAAtMaxReplicasan HPA has sat at maxReplicas for 2 hoursinfo, 2h
HPAMinEqualsMaxan HPA has minReplicas equal to maxReplicas (autoscaling off)info, 1h
ContainersWithoutCPURequestsrunning containers in a namespace have no CPU requestinfo, 1h
DeploymentScaledToZeroa Deployment has had zero replicas for 7 daysinfo, 7d

Recording rules (costwaste:*) price every node, then give:

  • Cluster cost per month and the split into requested (what pods reserve) and unrequested capacity (paid for, used by nobody).
  • Showback per namespace: requests priced at the node each pod runs on.
  • Waste per namespace: requests above real usage, in money. The headline figure leaves out the system namespaces in excludeNamespaces; an "all namespaces" figure sits next to it.
  • Savings levers per month: right-sizing, consolidating unrequested capacity, moving on-demand nodes to spot, committing the steady baseline, idle volumes and idle load balancers. They overlap, so read them as separate options, not a total.
  • Cluster commitment ratios, idle PVCs and LoadBalancers, HPAs at their limits, containers without requests.

The dashboard shows all of it: cost tiles, a savings table, cost by namespace, a node table (instance type, spot or on-demand, cost, how much is requested), monthly run-rate trends, and the namespace table.

Pricing sources

pricing.sourceNode price comes fromNeeds
static (default)cpuCoreHour × vCPUs + memoryGiBHour × GiB, the same for every nodenothing
instanceTypepricing.instanceTypes (on-demand $/hour per node.kubernetes.io/instance-type), spot nodes discounted by spotDiscount; unknown types fall back to the static ratesnode labels in kube-state-metrics (below)
opencostOpenCost's node_total_hourly_cost, node_cpu_hourly_cost, node_ram_hourly_cost, kubecost_node_is_spot: the cloud provider's price list, spot includedOpenCost scraped by the same Prometheus

With instanceType, kube-state-metrics has to export the node labels. In kube-prometheus-stack:

kube-state-metrics:
  metricLabelsAllowlist:
    - nodes=[node.kubernetes.io/instance-type,karpenter.sh/capacity-type,eks.amazonaws.com/capacityType,cloud.google.com/gke-spot,cloud.google.com/gke-preemptible,kubernetes.azure.com/scalesetpriority]

Spot and preemptible nodes are recognised from the Karpenter, EKS, GKE and AKS labels above (all sources) or from OpenCost.

pricing:
  source: instanceType
  currency: USD
  instanceTypes:
    m6i.large: 0.096
    m6i.xlarge: 0.192
    m6i.2xlarge: 0.384

An instance price is split into CPU and memory in the ratio of cpuCoreHour to memoryGiBHour, so keep those two at sensible list prices even when the source is not static.

OpenCost, and some agents, re-export kube-state-metrics series under their own job. The rules deduplicate them (max without (job, instance, …)), so installing OpenCost next to kube-state-metrics does not count requests or capacity twice.

Install

helm repo add oreonit https://oreondev.github.io/helm-charts
helm install cost oreonit/k8s-cost-waste-alerts -n monitoring \
  --set prometheusRule.labels.release=kube-prometheus-stack \
  --set pricing.currency=GBP --set pricing.cpuCoreHour=0.026 --set pricing.memoryGiBHour=0.0035

The over-requested alerts use a 24-hour average, so they start firing a day after install. The dashboard is useful after a few minutes.

Values

KeyDefaultDescription
prometheusRule.labels{}Prometheus Operator ruleSelector labels
prometheusRule.interval1mRecording rule interval
dashboard.*enabled, grafana_dashboard: "1"Dashboard ConfigMap for the Grafana sidecar
excludeNamespaceskube-.*|gmp-.*|gke-.*|monitoring|kyvernoSystem namespaces: the alerts, the headline waste figure and the savings levers leave them out
pricing.currencyUSDUSD, GBP or EUR (dashboard unit)
pricing.cpuCoreHour0.032Price of one vCPU-hour
pricing.memoryGiBHour0.0043Price of one GiB-hour
pricing.sourcestaticstatic, instanceType or opencost (see Pricing sources)
pricing.instanceTypes{}On-demand $/hour per instance type (instanceType source)
pricing.spotDiscount0.65Discount of spot on on-demand: prices spot nodes (instanceType) and the spot lever
pricing.storageGiBMonth / loadBalancerHour0.10 / 0.025Prices for the idle-volume and idle-load-balancer levers
savings.spotEligibleShare0.5Share of on-demand node spend that could run on spot
savings.commitmentDiscount0.3Discount of a 1-year commitment on the 7-day minimum of on-demand spend
savings.idleHeadroom0.2Share of unrequested capacity kept as headroom (not counted as saveable)
thresholds.cpuWasteRatio / memoryWasteRatio0.7Unused share of requests that triggers the over-requested alerts
thresholds.minCpuRequestCores / minMemoryRequestGiB2 / 4Ignore namespaces requesting less than this
thresholds.clusterCpuCommitRatio / clusterMemoryCommitRatio0.4Under-committed threshold
alerts.<name>.enabled / severity / forsee tablePer-alert switches
alertLabels{}Labels added to every alert (team, routing)

How to read it

  • Over-requested namespaces are the usual first win: memory requests set "to be safe" decide how many nodes you pay for. Right-size with VPA recommendations, then let the autoscaler remove nodes.
  • Under-committed cluster with over-requested namespaces means both problems at once: fix requests first, then node pool minimums and machine types.
  • Prices are a model, not an invoice. OpenCost gets you list prices per node; discounts you already have (Savings Plans, CUDs, enterprise agreements) are not in them, so the commitment lever overstates the saving if a commitment already covers the baseline.
  • Unrequested capacity only turns into savings when nodes go away: right-size requests first, then let the autoscaler or Karpenter consolidate.
  • UnusedLoadBalancerService needs kube-state-metrics 2.6 or newer (kube_endpoint_address); on older versions it stays silent rather than guessing.

Background: GKE cost optimisation levers, EKS cost optimisation, cost observability and FinOps. If you want the findings turned into a prioritised savings plan with the changes made, that is the cloud cost optimisation review.

Licence

MIT. Maintained by Oreon IT.

Deploy k8s-cost-waste-alerts with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has k8s-cost-waste-alerts on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartk8s-cost-waste-alerts is pinned at v0.2.2 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below
opentenant validate opentenant.yaml
terraform init && terraform apply