Fairwinds | Blog

How to Accelerate Your Kubernetes Cost Journey Through Best Practices

Written by John Hashem | Mar 23, 2023 2:02:22 PM

Organizations are moving to the cloud and building new cloud-native applications and services in Kubernetes to increase the scalability and availability of new offerings. Others are working on digital transformation projects, refactoring legacy applications to meet changing customer expectations and requirements. According to Flexera’s 2022 Tech Spend Pulse, 70% of respondents have increased willingness to move to the cloud — at the same time that they’re seeing increased demand in their industry. But 55% are experiencing challenges with ensuring spend efficiency. So how can organizations move to cloud and Kubernetes while making sure that they are controlling costs? Let’s look at specific ways you can apply best practices to manage your K8s costs effectively. 

Bring smiles to your finance team instead of missing labels

Kubernetes v.1.26 actually supports clusters that have  up to 5,000 nodes, but you  might have pieces of your application and your website all spread across many different nodes. You need to be able to slice your workloads up into smaller chunks to be able to track costs effectively. And if you don’t label your workloads correctly, you’ll miss broader coverage of what resources are being expended and where. 

Label structure and values are designed to be used internally to Kubernetes, so the label structure and values are constrained for more efficient use by Kubernetes. Using Kubernetes annotations, you can also add metadata to Kubernetes objects. That data helps you do troubleshooting because it can:

  • Include a link to a relevant Slack channel

  • Identify the owner of a specific service

  • Describe the source for the service

  • Add a link to a ticketing system

  • And more!

Having the right labels applied helps you better understand your Kubernetes costs, while adding annotations will help you implement better metrics and identify who to contact in your organization if something goes awry.

Fairwinds Insights can make it easier for you to apply labels and then use those labels to track your costs. Make sure that you pick your keys carefully as that will help you create a consistent hierarchy of values. This will help you to group costs more effectively in your report and limit the number of line items you need to review.

Apply labels automatically

The admission controller acts as a Kubernetes gatekeeper; it intercepts requests to the Kubernetes API server after the request is authenticated and authorized, but before the persistence of the object. Admissions controllers can be mutating, validating, or both. Mutating controllers are able to modify related objects to the requests they admit, while validating controllers cannot. 

Polaris is an open source tool that acts as an admission controller. Because the Polaris admission controller includes a mutating webhook, it can modify requests sent to the server, including adding, changing, or removing objects based on policy criteria. It also inspects requests and can determine whether they should be deployed or not. 

A mutating admission controller can enable you to apply best practices to every deployment. For example, if you have a policy requiring labels, a mutating admission controller can make sure your cluster workloads are labeled. If your workload doesn’t have a label, the admission controller can send it back or apply a label before deploying it to your Kubernetes cluster.

Rightsize your workloads for greater efficiency

The scheduler in Kubernetes places workloads based on the size of the thing you are deploying. Because Kubernetes automatically adapts to your workload’s resource utilization, it’s important to rightsize your resource requests and limits. When you set sensible limits and requests on how much CPU and memory each of your pods uses, you can increase the utilization of your infrastructure, while at the same time making sure that your application performs smoothly. 

Setting initial resource requests and limits can be challenging, though. Goldilocks is another open source tool that helps you correctly set resource requests and limits. Fairwinds Insights has Goldilocks and Prometheus built in to help you with rightsizing, so your applications running on Kubernetes clusters run as efficiently and reliably as possible. When you have your memory requests and limits configured appropriately, you can put more pods on fewer Kubernetes workloads. And if you are using a Cluster Autoscaler, extra nodes are removed if they are unused, which saves you time and money. 

Don’t make your Kubernetes cost journey more difficult 

Use open source tools, labels, Kubernetes annotations, and Fairwinds Insights to make your cost journey more efficient. When you enforce labeling and other Kubernetes best practices using an admission controller, such as Polaris or Fairwinds Insights, you’ll save time, resources, and frustration by enabling your developers to create secure, cloud efficient, and reliable applications. 

Not using Fairwinds Insights yet?  Try out our free tier for environments up to 20 nodes, two clusters, and one repo.