cost-stack
by QuenchWorks
Hardened Kubernetes cost monitoring stack: OpenCost (the CNCF cost model) reading cluster metrics from a bundled Prometheus, plus Grafana with that Prometheus provisioned as a datasource. Prometheus scrapes container usage from the kubelet (cAdvisor) and OpenCost's own pricing and allocation metrics; OpenCost serves cost allocation on <release>-opencost:9003. No operator, no CRDs. Every image is QuenchWorks-hardened, nonroot, CVE-gated, pinned by digest and cosign-signed.
About this chart
Quenchworks cost-stack
Kubernetes cost monitoring in one install: OpenCost prices every pod, namespace and node from metrics in a bundled Prometheus, and Grafana comes with that Prometheus already provisioned as its datasource. No operator and no CRDs; every pod runs nonroot on a read-only root filesystem, and every image is CVE-gated, cosign-signed and pinned by digest.
kubelet cAdvisor (container usage) ---\
OpenCost /metrics (prices, requests) ---> <release>-prometheus:9090
OpenCost --(PromQL)--> <release>-prometheus --> /allocation on <release>-opencost:9003
Grafana --(Prometheus datasource)--> <release>-prometheus
OpenCost emits the pod, node and request metrics it needs, so no kube-state-metrics or node-exporter is bundled. Prometheus gets a ClusterRole to discover pods and nodes and to read the kubelet's cAdvisor through the API server.
Install
helm install cost oci://ghcr.io/quenchworks/charts/cost-stack
kubectl port-forward svc/cost-opencost 9003:9003
curl -s 'http://127.0.0.1:9003/allocation/compute?window=1d&aggregate=namespace'
Allocation fills in after Prometheus has a few scrapes (a minute or two). Grafana:
kubectl get secret cost-grafana -o jsonpath='{.data.admin-password}' | base64 -d; echo
kubectl port-forward svc/cost-grafana 3000:3000
Values
| Key | Default | Notes |
|---|---|---|
opencost.enabled | true | Any opencost chart value under opencost. passes through. |
opencost.clusterId | default-cluster | Cluster name in the cost data. |
opencost.cloudProvider | detected | Set aws, azure, gcp, ... to override. |
prometheus.enabled | true | Any prometheus chart value under prometheus. passes through. |
prometheus.persistence.size | 8Gi | TSDB volume. |
prometheus.config.prometheusYaml | 3 jobs | Self, annotated pods (OpenCost), kubelet cAdvisor. Keep the last two. |
grafana.enabled | true | Any grafana chart value under grafana. passes through. |
grafana.auth.adminPassword | generated | Kept in <release>-grafana. |
ingress.enabled | false | Fronts Grafana unless ingress.serviceName says otherwise. |
The wiring ConfigMaps have fixed names, so run one cost-stack per namespace. Keep
grafana.datasources empty; the stack provides the Prometheus datasource itself. To use a
Prometheus you already run, set prometheus.enabled=false, opencost.prometheus.endpoint to
its URL and opencost.extraEnvVarsCM=""; that Prometheus must scrape cAdvisor and OpenCost.
Verify the images
cosign verify ghcr.io/quenchworks/images/opencost \
--certificate-identity-regexp 'https://github.com/quenchworks/.+' \
--certificate-oidc-issuer https://token.actions.githubusercontent.com
Deploy cost-stack with OpenTenant
Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has cost-stack 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.
- Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
- Place the chartcost-stack is pinned at v0.0.19 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
- 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