Kubernetes / Contributed

3 Kubernetes Best Practices to Help You Save Money Now

21 Mar 2022 10:00am, by

When thinking about cost management and optimization in Kubernetes ownership, configuration is critical. As one of the five key enablers of business success, next to security, compliance, reliability and scalability, the ability to make the most of your budgetary allocations comes from avoiding dangerous misconfigurations. 

Problems with configuration are among the top concerns in Kubernetes, primarily because they can introduce significant risk to the cloud native environment while also wasting a lot of dollars. In this way, proper configuration of Kubernetes plays a major role in the amount of money organizations spend. So, understanding best practices around cost optimization in containers demands a quick study on configuration concerns and the importance of budgetary alignment. 

How Much Does a Kubernetes Workload Cost, Anyway?

1. Allocate Cost

The first step here is to figure out what each individual workload costs. But this is not always a simple process, because Kubernetes nodes themselves are not simple. Nodes, which are the virtual or physical worker machines in Kubernetes (depending on the cluster), are what ultimately dictate the size of your bill. But that said, these nodes do not map neatly to the workloads you run them on. 

Kubernetes nodes are ephemeral and dynamic, capable of being created and destroyed as the cluster scales up or down — or replaced entirely in the event of an upgrade or failure. To make matters more complicated, Kubernetes performs something called “bin packing,” which places workloads into the nodes based on what it identifies as the most efficient use of the available resources — almost like a game of Tetris. Mapping a specific workload to a specific compute instance remains highly challenging. While efficient bin packing in Kubernetes can be a great cost saver, dividing up the spend is hard when the resources on a given node are shared across multiple applications. 

2. Right-Size Resources

Robert Brennan
Robert Brennan is director of open source software at Fairwinds, the Kubernetes governance and security company. He focuses on the development of software that abstracts away the complexity of underlying infrastructure to enable an optimal experience for engineers. Before Fairwinds, he worked as a senior software engineer for Google in AI and natural language processing. He is the co-founder of DataFire.io, an open source platform for building APIs and integrations, and LucyBot, developer of a suite of automated API documentation solutions deployed by Fortune 500 companies. He is a graduate of Columbia College and Columbia Engineering where he focused on machine learning.

Before Kubernetes, organizations could rely on cloud cost tools to provide visibility into the underlying cloud infrastructure. These days, Kubernetes provides a new layer of abstraction on top of cloud resource management, which can be a black box to traditional cloud cost monitoring tools. As a result, organizations need to find a way “under the hood” of Kubernetes to perform proper cost allocation among applications, products and teams.

When applications are deployed into Kubernetes, users need to know how much memory and CPU should be allocated to their application. This is the place where initial mistakes are often made, as teams either fail to specify these settings or they configure them way too high. Because developers are often tasked with writing code and shipping quickly, they will often omit seemingly-optional configuration concerns, such as CPU and memory requests and limits. But this leads to big problems and a grave departure from best practices. 

Ignoring this piece of the configuration puzzle leads to issues with reliability, including increased latency and even downtime. Even if developers do take the time to specify memory and CPU settings, they often overcompensate by allocating an overly generous amount to the application, to ensure the application has all the resources it needs on hand. In this way, developers tend to believe, “the more compute, the better.” But it’s not just about shipping faster and with less risk. Kubernetes clusters have to be configured with the right memory requests and limits to ensure applications run and scale efficiently. This step avoids wasted dollars. 

Without Kubernetes, cost controls and visibility in place, as well as a solid feedback loop to get that information in front of the development team, a developer’s potentially overgenerous CPU and memory settings will be honored. And your organization will foot the large bill for cloud computing. Even though Kubernetes does its best to play Tetris as effectively as possible with your resources by co-locating them in a way that optimizes resources, it can only do so much when faced with unclear memory and CPU expectations or over-allocated resources. 

3. Empower Teams

Developing a full-service ownership model for Kubernetes is a major best practice and empowers development teams to own and run their applications in production. Operations teams can therefore focus on building an excellent platform for development teams. In Kubernetes, service ownership helps with efficiency and reliability by offering feedback to engineering teams through things like automation, actionable advice, alerts and toolchain integrations. This workflow shift asks teams to make productive decisions as they continue to follow best practices. 

Teams who build, deploy and run their applications have more autonomy and fewer hand-offs with other users. Again, the service ownership model helps developers understand more clearly how the software they build impacts both the customer and the operational overhead of cost. When it comes to improving cost management and collaboration for savings, service ownership of Kubernetes, which includes proper oversight and configuration, reduces the complexity of containerized workloads and puts the power of best practices back into the hands of developers. 

Feature image provided by author.