Kubecost creates Kubernetes resource-granular models of current and historical Kubernetes spending. These models can be used to provide monitoring of resource allocations and cost transparency in Kubernetes environments that support multiple applications, teams, and departments. In this recipe, we will take a look at the basic steps to get Kubecost up and running:
- Add the Kubecost chart repository to the local Helm repository list:
$ helm repo add kubecost https://kubecost.github.io/cost-analyzer/
- Install Kubecost into the kubecost namespace using the Helm install command:
$ helm install kubecost/cost-analyzer --namespace kubecost --name kubecost --set kubecostToken="dGVzdEB0ZXN0LmNvbQ==xm343yadf98"
- Verify that all pods are running. As you can see, this project also deploys its own instances of Prometheus and Grafana:
$ kubectl get pods -nkubecost
NAME READY STATUS RESTARTS AGE
cost-analyzer-checks-1571781600-6mhwh 0/1 Completed 0 7m1s
kubecost-cost-analyzer-54bc969689-8rznl 3/3 Running 0 9m7s
kubecost-grafana-844d4b9844-dkdvn 3/3 Running 0 9m7s
kubecost-prometheus-alertmanager-85bbbd6b7b-fpmqr 2/2 Running 0 9m7s
kubecost-prometheus-kube-state-metrics-857c5d4b4f-gxmgj 1/1 Running 0 9m7s
kubecost-prometheus-node-exporter-6bsp2 1/1 Running 0 9m7s
kubecost-prometheus-node-exporter-jtw2h 1/1 Running 0 9m7s
kubecost-prometheus-node-exporter-k69fh 1/1 Running 0 9m7s
kubecost-prometheus-pushgateway-7689458dc9-rx5jj 1/1 Running 0 9m7s
kubecost-prometheus-server-7b8b759d74-vww8c 2/2 Running 0 9m7s
If you have an existing Prometheus deployment, node-exporter pods may get stuck in Pending mode. In that case, you need to use different ports for Kubecost to be deployed; otherwise, pods will not be able to get the requested pod ports.
Now you have the Kubecost cost analyzer installed with a bundle of components required to operate it in a Kubernetes environment.