Start your free 14-day ContainIQ trial

Kubernetes Cost Monitoring | Best Practices and Tools

July 3, 2022

Kubernetes allows applications to scale effectively and allocate resources dynamically. However, these same factors can make it difficult to understand what exactly is contributing to costs.

Karl Hughes
Software Engineer, & Author

A recent survey conducted by CNCF in collaboration with FinOps foundation revealed an uptick in Kubernetes-related bills across the board in 2021. What’s appalling from the survey result is that most respondents were unable to monitor, manage, or predict Kubernetes cost-effectively.

To put it simply, measuring costs correctly in Kubernetes environments is complex.

Kubernetes workloads are dynamic, which poses a challenge when it comes to calculating the cost of resources utilized by your applications correctly. We typically deploy applications to a multi-tenant Kubernetes cluster, which further adds to complexities in getting correct cost estimation about resource usages. With a cloud vendor it would be easy to know that your Kubernetes cluster is costing you $100 a day, but can be challenging to estimate how many resources, i.e, compute and memory, a team or project is using.

Let’s quickly take a look at some of the challenges of managing costs with Kubernetes:

  • Given the dynamic resource needs of the applications deployed to Kubernetes, it’s not easy to accurately and fairly estimate the cost for a multi-tenant Kubernetes cluster unless you use specific tools like Kubecost or Harness. We’ll talk about these tools later in the article.
  • Even though everything gets boiled down to compute, memory, and load balancers, other external factors, shared resources, and cluster management fees can further complicate your Kubernetes cluster costs estimation.

Breaking Down Costs

It’s worth knowing your managed Kubernetes cluster costs upfront rather than getting shocked after receiving your monthly bills. In this article, we’ll discuss best practices and tools for implementing cost optimization and gaining accurate visibility for your Kubernetes workloads.

Resource Management in Kubernetes vs. Traditional Architectures

You can break down the typical cost of running an application on a managed Kubernetes cluster into the following components:

If we compare the cost between Kubernetes and on-premises traditional architecture, then we can break down conventional application costs into computing, storage, and networking at a high level. But it’s more than that if you drill down further—you have to hire more people now to manage the entire infrastructure yourself, not only that you have to pay additionally for buying software licenses.

What Cloud Providers Include by Default

It’s not common knowledge, but each cloud vendor charges for standard services like control planes differently. For example, Azure AKS and DigitalOcean don’t charge you for the compute resources used for the control plane.

On the other hand, GKE and EKS charge for the control plane resources. Additionally, GKE added a management fee of $0.10 per cluster per hour, regardless of cluster size and topology. Knowing all the known and unknown factors that can impact Kubernetes cluster cost can be overwhelming.

Tips to Manage Kubernetes Cloud Costs

The following are some of the best practices that teams can follow to optimize their Kubernetes cloud costs:

Tools to Manage Kubernetes Costs

Clearly for a task as complex as ascertaining and managing your Kubernetes costs, you need a tool that can do some of the heavy lifting for you.

Harness

Harness is a modern software delivery platform powered by AI. It has built-in capabilities to manage your cloud bills with its Cloud Cost Management feature. Features include:

  • Providing deep, actionable insights into your Kubernetes cluster idle and unallocated resources.
  • The ability to shut down non-production idle resources with its cloud AutoStopping feature.
  • Detecting and flagging anomalies in your cloud consumptions by analyzing historic spend patterns.

Kubecost

Kubecost is the most popular open-source tool to get a real-time bird’s eye view of Kubernetes costs. It uses preconfigured Grafana dashboards with its own opinionated setup (which can be tailored to your needs) for monitoring Kubernetes cluster costs. You can easily install it using a Helm chart.

To point out its highlights, Kubecost:

  • Is a unified Kubernetes cost monitoring solution supporting all major cloud providers.
  • Automatically generates Kubernetes cost optimization recommendations via its UI or API. These recommendations can be dynamically applied for immediate results.
  • Provides real-time alerting capabilities so that teams can take control of their Kubernetes-related costs and stay within budgeted limits.
  • Breaks down the cost allocation to Kubernetes resources such as deployments, namespaces, labels, pods, and containers (but not limited to these). You can transparently and accurately share the cost among your teams and tally it with your cloud bills as well.

Loft

Loft’s Kubernetes platform has excellent features to help manage your resource costs. Two in particular—sleep mode and auto-delete—can help you reduce Kubernetes costs:

  • Sleep mode can scale down your lower environments by putting namespaces to sleep and purging all pods inside a namespace during periods of inactivity.
  • Auto-delete, as the name suggests, directly deletes the namespaces and virtual clusters that are idle, old, and unused for a while.

Final Thoughts

While it’s pretty common among engineering teams to overprovision resources to run their Kubernetes clusters, it may not be a sustainable approach—someone has to pay at the end. So whether you are a seasoned professional or just starting your Kubernetes journey, you can’t overlook the costs of running a Kubernetes cluster.

By now, you should have a more solid idea of some of the methods that your teams can use to limit and optimize their Kubernetes cluster costs. Teams can right-size their nodes and pods or use tools like Kubecost or Harness to get cost visibility for their Kubernetes workloads.

Start your free 14-day ContainIQ trial
Start Free TrialBook a Demo
No card required
Karl Hughes
Software Engineer, & Author

Karl is the Founder & CEO of Draft where he works to create engaging and thoughtful content for software engineers. Prior to his current role, he was the CTO at The Graide Network where he led an incremental transition from legacy offshore web application to microservice architecture. Karl has a Bachelors in Mechanical Engineering from the University of Tennessee at Knoxville.

READ MORE