Gaming industry under DDoS attack. Get DDoS protection now. Start onboarding
  1. Home
  2. Developers
  3. Optimizing K8s cluster costs with Kubecost

Optimizing K8s cluster costs with Kubecost

  • By Gcore
  • March 21, 2023
  • 2 min read
Optimizing K8s cluster costs with Kubecost

I will always remember the first time I started playing around with Kubernetes as a personal hobby and looked at my costs a month later. This was around when I was first dipping my feet into the waters of the DevOps tools ecosystem and container orchestration with Kubernetes. I had no idea that I would look at my billing statement and see a $1300 charge just sitting there leftover from forgetting to shut down a cluster.

Safe to say that I’ve grown quite a bit since then and I’m quite a bit more meticulous about shutting down unused resources, but that experience made me realize just how important cost estimation is for projects. When you venture into enterprise-level scale, there is a lot more at stake than a bit of personal money to be lost. Cost estimation is extremely important when managing stakeholder expectations and guidelines.

With that in mind, I’d like to introduce you to an interesting new tool I found called Kubecost.  

What is Kubecost?

Kubecost is a cost-optimization and estimation tool that gives you real-time visibility into how resources are being spent across your clusters in seconds, so you can take action based on current information. With it, you can easily see the cost of resources being consumed by individual applications and teams.

It also allows you to get an overhead view of your infrastructure by assigning out of cluster cloud assets (e.g. databases and storage buckets) to teams, products, services, and other native k8s concepts in order to measure the full cost of your cloud operations.

Using tools like Kubecost allows you to maintain a continuous watch over your spending and even set up notification via Slack and other channels to quickly catch cost overruns and infrastructure outage risks before they become a problem.

Let’s try it out

We are going to run through a quick demonstration of how to get Kubecost installed in your cluster to begin monitoring your costs.

The easiest way to install Kubecost into your cluster is via the Helm install on the Kubecost website.

Prerequisites

  • A Helm client installed (We are using Helm 3)
  • For clusters with RBAC enabled, run the following commands to grant necessary permissions:
kubectl create clusterrolebinding cluster-admin-binding --clusterrole=cluster-admin --user=<your-userid> 
kubectl create clusterrolebinding cluster-self-admin-binding --clusterrole=cluster-admin --serviceaccount=kube-system:default

Step 1: Install Kubecost

Running the following commands will also install Prometheus, Grafana, and kube-state-metrics in the namespace supplied. View install configuration options here.

Helm 2

helm repo add kubecost https://kubecost.github.io/cost-analyzer/ helm install kubecost/cost-analyzer --namespace kubecost --name kubecost --set kubecostToken="amRib2hybWFuQG91dGxvb2suY29txm343yadf98"

Helm 3

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

Step 2. Enable Port Forward

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

Step 3. 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

You can see my implementation here, which has a Agones game server running as well as Telepresence:

Next Steps

Kubecost has an open core model and its commercial product is built on top of the open-source project available on Github. Therefore, you’re free to play around with it as much as you like before spinning up the enterprise version in production. From here, I would start playing around with Kubecost in your own environment and try setting up notifications and cost optimizations. I hope you enjoyed this article and stay tuned for more!

Discover more with Gcore Managed Kubernetes

Related articles

What's the difference between multi-cloud and hybrid cloud?

Multi-cloud and hybrid cloud represent two distinct approaches to distributed computing architecture that build upon the foundation of cloud computing to help organizations improve their IT infrastructure.Multi-cloud environments involve us

What is multi-cloud? Strategy, benefits, and best practices

Multi-cloud is a cloud usage model where an organization utilizes public cloud services from two or more cloud service providers, often combining public, private, and hybrid clouds, as well as different service models, such as Infrastructur

What is cloud migration? Benefits, strategy, and best practices

Cloud migration is the process of transferring digital assets, such as data, applications, and IT resources, from on-premises data centers to cloud platforms, including public, private, hybrid, or multi-cloud environments. Organizations can

What is a private cloud? Benefits, use cases, and implementation

A private cloud is a cloud computing environment dedicated exclusively to a single organization, providing a single-tenant infrastructure that improves security, control, and customization compared to public clouds.Private cloud environment

What is a cloud GPU? Definition, types, and benefits

A cloud GPU is a remotely rented graphics processing unit hosted in a cloud provider's data center, accessible over the internet via APIs or virtual machines. These virtualized resources allow users to access powerful computing capabilities

What is cloud networking: benefits, components, and implementation strategies

Cloud networking is the use and management of network resources, including hardware and software, hosted on public or private cloud infrastructures rather than on-premises equipment. Over 90% of enterprises are expected to adopt cloud netwo

Subscribe to our newsletter

Get the latest industry trends, exclusive insights, and Gcore updates delivered straight to your inbox.