Kubernetes Cost Reporting Using Kubecost

Kubernetes Cost Reporting Using Kubecost

What is Kubecost?

Kubecost is a tool that gives you real-time visibility into your resource utilization and provides you with a detailed breakdown of your costs. Kubecost runs anywhere K8s runs; Kubecost helps you monitor and manage cost and capacity in kubernetes environments. Kubecost integrate with your infrastruture to help your team track, manage, and reduce spend.

Is Kubecost Open Source?

Kubecost operates with an open core model whereby the commercial product is built on top of the Kubecost open source project available on Github. In fact, it can be deployed with a single Helm install. Essentially, Kubecost sits inside a company’s infrastructure, which allows it to monitor costs in real-time, and has the added benefit that data doesn’t have to be shared remotely.

Why Kubecost?

  • Kubecost allows you to see allocated spend across all native Kubernetes concepts.
  • Unified cost monitoring-all services form AWS, GCP, and Microsoft Azure are supported.
  • Kubecost automatically generates insights you can use to save 30-50% or more on your infrastructure spend, without exposing your private information.
  • Real-time alerting functionality and recurring reports.

Kubecost Architecture Overview

Below are the major components deployed with the Kubecost Helm chart, excluding certain Enterprise components such as durable storage:

  1. Kubecost Cost-Analyzer Pod

    a. Fronted-runs Nginx and handles routing to Kubecost backend Prometheus/Grafana

    b. Kubecost server - backend for API calls

    c. Cost-model - provides cost allocation calculations and metrics, both reads and writes to Prometheus

  1. Prometheus

a. Prometheus server - time-series data store for cost & health metrics

b. Kube-state-metrics - provides Kubernetes API metrics, e.g. resource requests

c. Node-exporter - provides node-level utilization metrics for right-sizing
recommendations and cluster utilization[Optional]

d. Pushgateway - provides the ability for users to push new metrics to Prometheus[Optional]

e. Alertmanager - used for custom alerts[Optional]

  1. Network costs - optional DaemonSet for collecting network metrics learn more

  2. Grafana - provides supporting dashboards for Kubecost product[Optional]

Today, the core Kubecost product can be run with just components 1, 3a, and 3b.

See an overview of core components in this diagram:

arch.png

Enterprise architecture overview

The most common implementation of durable storage in the Kubecost application is with Thanos. Below is a high-level reference for the required components. More information on each Thanos component can be found here.

thanos-architecture.png

How to install Kubecost

Before you begin Ensure that you have installed Helm client(version 3.0+).

Multiple ways to install Kubecost you can be found here. You can install to write following command:

  • helm3
kubectl create namespace kubecost
helm repo add kubecost https://kubecost.github.io/cost-analyzer/
helm install kubecost kubecost/cost-analyzer --namespace kubecost --set kubecostToken="c2FjaGlucGFyaWhhcjk4MTIwQGdtYWlsLmNvbQ==xm343yadf98"
  • Enable port-forward
kubectl port-forward --namespace kubecost deployment/kubecost-cost-analyzer 9090

Having installation issues? View our Troubleshooting Guide.

  • See the data You can now view the deployed frontend by visiting the following link. Publish :9090 as a secure endpoint on your cluster to remove the need to port forward.

http://localhost:9090/

Kubecost's Core Features

Overview

The default page on Kubecost is an Overview dashboard that contains multiple unmovable panels as shown below:

6234a006e3803db71b1d7fcd_kubecost-main-dashboard-overview-with-panels-and-charts_lightbox.png

Cost Allocation

Kubecost allows you to see allocated spend across all native Kubernetes concepts, so you can provied your teams with Transparent, accurate cost data reconciled with your actual cloud bill.

cost-allocation (1).png

Assets

6234a0e59747d496c7b1c798_kubescost-assets-menu_lightbox.png

Savings

6234a13aa1df62a053c3c62d_kubecost-savings-menu_lightbox.png

Health

Cluster health ratings are an assessment of infrastructure reliability and performance risks. Scores range from 1-100.

6234a6e77655fe8350cec6f7_kubecost-cluster-health-rating-menu-main-dashboard_lightbox.png

Conclusion

I believe that Kubecost is an indispensable tool when managing Kubernetes clusters. It gives us a quick and efficient way to visualize the detailed cost for the clusters of our clients, and we can always keep a low bill while maintaining an optimized cluster. What makes Kubecost unique is its simplicity in deploying the tool and using it.

Resources

Did you find this article valuable?

Support Sachin Parihar by becoming a sponsor. Any amount is appreciated!