Managing Your Kubernetes Spending: Meet Kubecost

Albert Weng
4 min readMay 17, 2024

Today, let’s look at Kubernetes monitoring from a different perspective: the boss’s perspective.

As businesses become increasingly digital, the number of solutions they use also grows, making IT cost estimation more challenging. In the past, it was easier to calculate costs based on hardware, software, and so on. However, with the emergence of cloud-native architecture, many services from different departments run on the same platform, leading to resource contention (unless the company has unlimited money :) ).

Watch Your Wallet!”

At this point, the IT is often tasked with calculating the usage of each service. The next budget allocation will then be charged proportionally (meaning departments need to contribute to the maintenance costs).

For a Kubernetes platform, a more precise cost solution is needed. In this article, we’ll explain the basic usage and deployment of the open-source project Kubecost.

Here are the topics covered in this article:

Here’s what we’ll cover:

  1. Basic Introduction
  2. Deployment
  3. Simple Operations
  4. Conclusion

1. Basic Introduction

Kubecost’s main job is to help you keep an eye on and manage the costs and capacity of your Kubernetes environment. It also contributes the OpenCost open-source project. These projects are all about tracking and managing the costs of cloud infrastructure and containers, making it easier to monitor, visualize, and allocate costs specifically for Kubernetes.

※ OpenCost and Kubecost Relationship:

OpenCost implements the cost allocation engine created by Kubecost. This engine is one of the most frequently used features in Kubecost. OpenCost is actually a CNCF sandbox project, so it’s free for everyone to use.

※ Differences between OpenCost & Kubecost

=> Kubecost provides more detailed and accurate cost figures. In addition, Kubecost offers recommendations, governance, alerts, and support for federated clusters, SaaS platforms, and commercial support.

=> OpenCost, on the other hand, serves as the cost allocation engine for Kubecost and has its own UI. Its goal is to become the “Prometheus of cloud cost monitoring,” allowing other solutions to leverage its data for various operations.

※ Kubecost Free vs. Enterprise :

Free : Cost allocation, unified cost monitoring, optimized insights, alerts and governance, tailored for Kubernetes teams, full control and ownership of data, sourced from open-source.

Enterprise : Includes all features of the free version plus cross-Kubernetes cluster unified view, retention of long-term metrics, access control through SSO/SAML, high availability mode, advanced custom pricing, advanced integration with other solutions, and enterprise-level support.

2. Deployment

#---------------------------------------------
# S2-1. obtain yaml
#---------------------------------------------
[master]# wget https://raw.githubusercontent.com/kubecost/cost-analyzer-helm-chart/develop/kubecost.yaml
#---------------------------------------------
# S2-2. Edit (with storageclass)
#---------------------------------------------
[master]# vim kubecost.yaml
...
storageClassName: managed-nfs-storage
#---------------------------------------------
# S2-3. deploy
#---------------------------------------------
[master]# kubectl create -f kubecost.yaml
[master]# kubectl get all -n kubecost
#---------------------------------------------
# S2-4. Access UI
#---------------------------------------------
[master]# kubectl port-forward -n kubecost svc/kubecost-cost-analyzer 9090:9090
=> http://127.0.0.1:9090

3. Simple Operations

#-------------------------------------------
# S3-1. Namespace status
#-------------------------------------------
Overview => Namespace => (click)namespace_name
#-------------------------------------------
# S3-2. Performance estimation of the entire cluster
#-------------------------------------------
Monitor => Cluster
#-------------------------------------------
# S3-3. overall improvement suggestions
#-------------------------------------------
Savings => Explore savings
#-------------------------------------------
# S3-4. Health status
#-------------------------------------------
Healthy

4. Conclusion

Overall, based on my experience using it, I’d suggest that businesses go for the enterprise version of Kubecost in formal setups. It not only helps in better cost calculation but also offers many helpful suggestions for improvement in the latest version. Especially in public cloud setups, it can be a great alternative to the platform’s own billing modules.

Cost monitoring is becoming more like a handy tool for management. If you’re on a tight budget and can’t go for the enterprise plan, OpenCost is a good option. It serves as a good justification when asking for budget approvals from higher-ups.

※ References:

--

--

Albert Weng

You don't have to be great to start, but you have to start to be great