Kost is a tool built at Grafana Labs to estimate the cost of workloads running in our k8s clusters.
Caution
This is still highly experimental and somewhat tightly coupled to how Grafana Labs manages and monitors our k8s infrastructure. We'd love to support other teams and organizations, but do not have the bandwidth to implement it. If you want to adopt the tool, please fill out an issue and connect with us!
kost
is somewhat tightly coupled to how Grafana Labs manages our k8s environments.
Specifically, the following assumptions need to be met:
- K8s resources defined in a standalone repository
- Mimir to store cloudcost-exporter metrics for cost data
- GitHub Actions to detect changes and run the cost report
While these are what we use internally and require, in theory the bot should work so long as you have:
- Two manifest files that you can compare changes
- Prometheus compliant backend with cost metrics
- A CI system to run the bot when changes happen
- HTTP access to a prometheus server that has cloudcost-exporter metrics available
- For example, navigate to
https://<grafana-address>/connections/datasources/
, identify the Prometheus (or Mimir!) datasource to use, and copy the value ofPrometheus server URL
.
- For example, navigate to
- A local copy of the repository that stores kube-manifest files
- See flux docs a similar structure to what Grafana Labs uses
- If you have a Mimir instance running on Grafana Cloud, create an access policy with a token with
metrics:read
permissions - Create a yaml file with basic auth creds to use (see below).
- Replace
<user>
with the the username of the datasource account. For example, after finding the datasource to use inhttps://<grafana-address>/connections/datasources/
, find the username underAuthentication
>Basic authentiaction
>User
. - Replace
<password>
with the token you created earlier.
- Replace
basic_auth:
username: <user>
password: <password>
There are two entrypoints that you can run:
- estimator
- bot
Estimator is a simple cli that accepts two manifest files and a set of clusters to generate the cost estimator for.
Bot is what is ran in GitHub Actions today and requires the kube-manifest
repository to be available locally.
To check the cost on a single cluster, run the following command:
go run ./cmd/estimator/ \
-from $PWD/pkg/costmodel/testdata/resource/Deployment.json \
-to $PWD/pkg/costmodel/testdata/resource/Deployment-more-requests.json \
-http.config.file /tmp/dev.yaml \
-prometheus.address $PROMETHEUS_ADDRESS \
<cluster>
To check the cost across multiple clusters, run the following command:
go run ./cmd/estimator/ \
-from $PWD/pkg/costmodel/testdata/resource/Deployment.json \
-to $PWD/pkg/costmodel/testdata/resource/Deployment-more-requests.json \
-http.config.file /tmp/dev.yaml \
-prometheus.address $PROMETHEUS_ADDRESS \
<cluster-1> <cluster-2>
Set the following environment variables:
KUBE_MANIFESTS_PATH
: path tografana/kube-manifests
HTTP_CONFIG_FILE
: path to configuration created in PrereqsPROMETHEUS_ADDRESS
: Prometheus compatible TSDB endpointGITHUB_PULL_REQUEST
: GitHub PR to create comment onGITHUB_EVENT_NAME
: set topull_request
GITHUB_TOKEN
: set to a token that is able to comment on PRsCI
: set totrue
go run ./cmd/bot/