Kubecost : Manage and Reduce K8s cost

Manage K8s cost across multiple clouds and on-prem infra on one place

ยท

3 min read

Kubecost : Manage and Reduce K8s cost

What is KubeCost ?

Kubecost, a product which you can be used to manage your kubernetes cluster cost. It divides your cost according to namespace, deployments, service. You can also divide costs based on different teams or environment. The fun part it is open source software. As a result it is built on top of Prometheus and Grafana

Significant Features

Cost Management at one place

You can monitor cost of all the cluster together here, be it on AWS, GCP, Azure or on-premise.

Optimization Insights

It provides you possible optimisation for your cluster resources and help reduce cost by 30-50 % that too without sharing a single bit of information about your infra.

For example: It not only predicts monthly bills but analyses and tells about unused resources, so you can then optimise your nodes accordingly.

Alerts for Expense and Resources Overuse

Get real-time updates about budget overrun, unknown expenses, or under-used resources directly to your email or slack.

Privacy of your expenditure data

You install it on the cluster and keep your data . No sending any bit of data to any of kubecost API or remote service.

Hands On Demo using a cloud provided cluster -

  1. Once you have your Kubernetes cluster up and running
    minikube start
    

Once you complete this we open Lens IDE and connect to the minikube cluster ( kubeconfig file located at ~/.kube/config )

  1. You can follow the installation steps to add kubecost to your cluster.

How to install ?

You need to install it only on the Control Plane node.

  • Create a new namespace for kubecost using kubectl
    kubectl create namespace kubecost
    

Method 1: Using Helm

  • Add from helm repo

    helm repo add kubecost https://kubecost.github.io/cost-analyzer/
    
  • Finally install to you cluster

    helm install kubecost kubecost/cost-analyzer --namespace kubecost --set kubecostToken="bmlnZWZpNzg0MEBnYW1lNGhyLmNvbQ==xm343yadf98"
    

Method 2: You can use a manifest file also to install this

kubectl apply -f https://raw.githubusercontent.com/kubecost/cost-analyzer-helm-chart/master/kubecost.yaml --namespace kubecost

kubecost-demo-3.png

The above installation will create kubecost new deployments, services and pods in namespace kubecost

  • Wait until cost-analyser pod is in running state kubecost-demo-5.png

  • After installation complete, you need to port-forward to port 9090 to access the kubecost app installed on your kubernetes cluster on your localhost.

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

Open localhost:9090 It should show you the kubecost dashboard

kubecost-demo-6.png visit kubecost installation doc for more info

Navigating the Dashboard

  • Once installed the program will take some time (10-15 mins) to analyse and generate statistics based on your usage data.

  • It starts showing your monthly kubernetes costs, monthly savings, cost inefficiency etc., including cost of running kubecost pods itself.

Overview

kubecost-demo-7.png

If you notice the values have changes after 15 mins.

  • It also has a detailed cost allocation view based on mutiple parameters like namespace , CPU, GPU , RAM etc.

kubecost-demo-8.png

Cost Allocation

It has cost allocation distributed based on namespace, CPU, GPU, RAM and other parameters.

kubecost-demo-8.png

Savings

It suggest multiple ways to save cost by right-sizing your cluster, detecting under-utilisized resources and much more

image.png

Health

Here the health score is present. It runs multiple health test for calculating this score.

image.png

Alerts

Here you can setup alert about cost limit, health status, resource utilisation.

image.png

Hurray ๐ŸŽ‰๏ธ ! You just learnt about kubecost .



The Fun Part it is Open Source ๐ŸŽ‰๏ธ


References :

ย