Skip to content

Kubernetes application for exporting Kubecost cost allocation metrics

License

Notifications You must be signed in to change notification settings

infrable-io/k8s-kubecost-exporter

Repository files navigation

K8s Kubecost Exporter

MIT License Maintained by Infrable GitHub Actions - Go GitHub Actions - Helm

k8s-kubecost-exporter is a Kubernetes application that exposes cost allocation metrics retrieved from Kubecost.

Cost allocation metrics are retrieved from the Kubecost Allocation API and made available via a metrics HTTP endpoint (/metrics). Applications that can extract custom metrics from OpenMetrics endpoints (Prometheus, Datadog, New Relic etc.) can be configured to scrape this endpoint.

For an architecture overview of Kubecost, see the following documentation:

Development

k8s-kubecost-exporter works in conjunction with Kubecost.

For deploying k8s-kubecost-exporter locally via Minikube, see the following documentation:

For deploying Kubecost locally via Minikube, see the following documentation:

Optionally, you can install New Relic's infrastructure monitoring agent via Helm using the following documentation:

See the Standard Go Project Layout GitHub repository for a canonical layout of Go applications upon which this repository is based.

The official container image (Dockerfile) contains only the binary executable, so for debugging purposes, a Dockerfile (Dockerfile.debug), is provided based on Alpine Linux.

Unit Testing

Unit testing is facilitate by gomock, a mocking framework for Go.

Mocked interfaces are generated using the following command:

$ mockgen -package main -source client.go -destination client_mock.go

Testing

To test the Go code, run the following:

$ go test

To test the Helm chart, run the following:

$ helm lint deploy/helm/kubecost-exporter
$ helm package deploy/helm/kubecost-exporter
$ kubectl create namespace kubecost-exporter
$ helm install kubecost-exporter kubecost-exporter-<version>.tgz --namespace kubecost-exporter \
  --set image.registry="" \
  --set image.repository="kubecost-exporter" \
  --set image.tag="latest" \
  --wait
$ helm test kubecost-exporter --namespace kubecost-exporter

NOTE: The container image can be built locally and made available to Minikube by running the following:

$ eval $(minikube -p minikube docker-env)
$ docker build -t kubecost-exporter:latest .