Cost Analysis of GKE Cluster using Kube Cost

Bhavishya Gupta
Google Cloud - Community
4 min readNov 17, 2022

Multiple time customers ask for a detailed view of Kubernetes cost for all workloads hosted on multiple pods across multiple clusters. Analysing K’8 cost becomes crucial to successfully implement chargeback model when multiple business units are involved for large enterprises.

While there are few tools out in market including cloud native cost analysis, one of the tools which gives the most holistic view is Kubecost.

Expectation Setting

By the end of this blog, you would be able to install Kubecost on GKE Cluster, analyse cost associated with all the Pod’s, Namespace, store the data on any backend.

Prerequisites

For this demo, we would be using a GKE Cluster hosted on GCP. Assumption is, we have admin privileges to perform operations on GCP cluster.

What is Kubecost?

Kubecost is a tool to analyse K’8 cost for clusters hosted on premise, or any cloud providers. Kubecost comes with multiple integration options and provides detailed view of Cost and also Cluster health. Kubecost Capabilities can be further extended with integrating to Prometheus, Grafana and multiple other tools. It also gives recommendations on cost savings and cost optimisation . Detailed documentation can be found HERE.

Installation of Kubecost

Kubecost can be installed using a Helm chart provided by Kubecost.

  1. Follow the below steps after logging in to you Kubernetes Cluster.

kubectl create namespace kubecost
helm repo add kubecost
https://kubecost.github.io/cost-analyzer/
helm install kubecost kubecost/cost-analyzer — namespace kubecost — set kubecostToken=”YmhhdmlzaHlhZ3VwdGE1MUBnbWFpbC5jb20=xm343yadf98"

2. Enable Port-forward (You can use ingress to redirect to console)

kubectl port-forward — namespace kubecost deployment/kubecost-cost-analyzer 9090

3. Login to Console and view the data using <IPAddress>:9090. In our case we have forwarded to localhost, hence its localhost:9090

Cost Analysis

  1. You can view cost based on pods, namespace, labels or any custom filter you wish to create. Below we are aggregating data based on Namespaces for last 7 days. We can aggregate data upto 90 days and store it in any custom location like GCS bucket.

2. Kubecost proposes Savings & cost optimisation opportunity based on the utilisation data of pods. It provides reports around resizing the pods, local disks and cluster nodes, based on utilisation. Below is the snippet of savings option.

3. Kubecost also provides Overall Health Status and scope for the K’8 Cluster.

4. Kubecost also provides a detailed reporting option with advanced filters. These reports can be saved in external bucket and also sent via email.

5. It can also be integrated with Prometheus , Grafana to further extend the capabilities, with options to set currency as per the location.

Conclusion

One of the best feature of Kubecost is, it allows to split cost of some common namespaces such as Kube system, kube public and equally add to all other namespaces. Kubecost also allows to further drill down cost based on labels to add to granularity. Overall its a great tool to visualise cost of multiple Kubernetes cluster in an enterprise. It has some cost associated based on the number of clusters which are covered in the different Kubecost Plans found HERE.

--

--