Simon Bisson
Contributing Writer

Kubernetes cost management for the real world

feature
May 8, 20236 mins

How much will Kubernetes cost to run? That question has become much easier to answer for Azure Kubernetes Service, thanks to OpenCost integration.

An IT technician works on laptop in data center, with other IT staff in the background.
Credit: Gorodenkoff / Shutterstock

Microsoftโ€™s decision to make Kubernetes a foundational service in Azure is paying off, not only for Microsoft but also for the rest of the Kubernetes ecosystem. Thatโ€™s because the company is investing its engineers and money in more than its own projects, supporting and contributing to upstream tools and capabilities.

Sometimes that investment is used as a lever, with the aim of improving the ecosystem for users, but other times itโ€™s about ensuring that we can run our cloud native applications more economically and, more importantly, with the minimum impact on the climate.

One key area of Microsoftโ€™s investment in Kubernetes has been cost management tooling. Kubernetes is an orchestrator, scaling up and down its use of compute on demand. That makes it hard to predict how much Kubernetes will cost to run, especially in a public cloud where youโ€™re mixing virtual server types and billing rules, with changing demands in memory, networking, and storage. Yes, your application will scale to the limits youโ€™ve set, but how does that affect your bottom line?

Adding FinOps to Kubernetes

As engineers we donโ€™t typically pay close attention to costs. After all, most of the time the bill for what we build and run is someone elseโ€™s problem. But the same could be said about operations and security, until DevOps and DevSecOps came along. With cloud services we can use the same techniques we use to monitor our applicationsโ€™ performance to monitor costs, taking advantage of the increasingly important FinOps. This new discipline gives us new visibility into how much running our code costs, and new ways to ensure that those costs are charged back to the right departments. Using FinOps tooling weโ€™re able to directly tie code to bills, rather than bundling it all into one IT operational expense.

This is where the open-source OpenCost tooling starts to shine. Sponsored by the Cloud Native Computing Foundation, the home of Kubernetes, OpenCost is a tool for measuring and allocating the costs of Kubernetes applications, with the option of helping you keep them under control. OpenCostโ€™s contributors come from across the Kubernetes ecosystem, with monitoring providers like New Relic and Grafana Labs at one end, and the hyperscale cloud providers AWS, Google Cloud, and Azure at the other. Microsoft has announced support for OpenCost in Azure Kubernetes Service, Azureโ€™s managed Kubernetes platform.

OpenCost allows you to drill down through your Kubernetes installation and operations to find out which containers, pods, deployments, etc. are costing you the most. Having real-time cost allocation like this gives you the ability to go beyond simply tuning your application for performance, instead optimizing for costs. This approach lets you find the sweet spot where your users get the best performance while costs are kept in check. Itโ€™s a balancing act, and one that can take some time to get right, but itโ€™s another compelling tuning parameter for your applications.

Working with OpenCost in AKS

While OpenCost will have production support for AKS from May 2023, a special build was made available for Kubecon EU to help you get started. There is some configuration required once itโ€™s been installed, setting the appropriate permissions for working with Azure.

OpenCost uses the Azure Consumption Price Sheet API to get real-time pricing data for your account. That ensures it takes account of appropriate discounts, such as using reserved instances. You can set this up by adding an Azure role to your account that gives OpenCost access to your billing details as a service principal, via your billing account ID. Once you have created this Azure role, save its key and secret for use with OpenCost. You configure OpenCost to access this data via either YAML or Helm, depending on which you used to set up your installation. If you have a custom pricing relationship with Azure, youโ€™ll need your existing offer ID to get access to your pricing through the API.

Usefully OpenCost can deliver data to Prometheus, which gives you a time series database that can store both signals from Kubernetes and pricing data from OpenCost. This makes financial information part of your observability platform, so you can watch for conditions that equate to high cost and treat them as a failure. Thereโ€™s even a kubectl plugin that can query OpenCost data about your services, so you can start to script operations based on historic costs.

Using cost data to manage Kubernetes

With real time data through the OpenCost API thereโ€™s scope for automated management models based on cost. If costs spike, why not use them as an input to KEDA, the Kubernetes autoscaler, and treat a high cost as an event that can scale down a cluster? There are even options in this for providers like Azure, using OpenCost as a way to deliver dynamic pricing to users.

Why is Microsoft embracing the introduction of tooling that helps its customers spend less, not more? The company may have little choice, given that AWS and Google Cloud also are partners in the OpenCost project. However, itโ€™s a change that fits with CEO Satya Nadellaโ€™s recent statement that Microsoft was โ€œhelping [its customers] realize more value from their tech spend.โ€ By ensuring that customers can align their Kubernetes spending with usage, thereโ€™s an opportunity to dynamically optimize the use of Azure infrastructure.

Microsoft could also improve customer retention, giving it the opportunity to win future business, and at the same time keep its own capital expenditure under control. Running massive cloud data centers is expensive, and building out new capacity is even more costly. Itโ€™s in the best interests of both Microsoft and its customers to align on an operating model that allows both to spend, if not less, then at least just the right amount for their needs.

Building OpenCost into Azure will give both Microsoft and customers better visibility into resource usage and allow Azure to plan future expansions more carefully. In the light of Microsoftโ€™s promise of long-term support for Kubernetes, itโ€™s clear that cloud native development is here to stay, and that itโ€™s now subject to the same controls as any other enterprise platform. Weโ€™re no longer experimenting, weโ€™re building businesses and services, and those need to operate in a predictable manner if theyโ€™re to become profitable for us and for Azure.

The future for Kubernetes on Azure is going to be boring, which shouldnโ€™t surprise us. After all, Kubernetes is infrastructure, and boring is the price we pay for maturity and enterprise acceptance. Whatโ€™s interesting, as we move into a Kubernetes-powered future, is what weโ€™ll do with that infrastructure and what weโ€™ll build on top of it.

Simon Bisson

Author of InfoWorld's Enterprise Microsoft blog, Simon Bisson prefers to think of โ€œcareerโ€ as a verb rather than a noun, having worked in academic and telecoms research, as well as having been the CTO of a startup, running the technical side of UK Online (the first national ISP with content as well as connections), before moving into consultancy and technology strategy. Heโ€™s built plenty of large-scale web applications, designed architectures for multi-terabyte online image stores, implemented B2B information hubs, and come up with next generation mobile network architectures and knowledge management solutions. In between doing all that, heโ€™s been a freelance journalist since the early days of the web and writes about everything from enterprise architecture down to gadgets. He is the author of Azure AI Services at Scale for Cloud, Mobile, and Edge: Building Intelligent Apps with Azure Cognitive Services and Machine Learning.

More from this author