Kubernetes

Kubernetes and Cloud Cost Optimization

March 7, 2023

Kubernetes is a powerful cloud-native automation tool that allows the environment to automate system configurations such as scaling up and down. Employing Kubernetes best practices can result in substantial cost savings when compared to static or manually managing systems.

The effectiveness of this automation in saving and limiting costs is directly related to the appropriate configuration being applied to an environment. Therefore, regular feedback and adjustment is important in assuring that configurations are optimized to achieve the desired cloud spend. So how is this done?

Monitoring Cloud Resources

The self-service and rapid elasticity aspects of cloud systems break the command and control traditionally managed by IT services, where costs and resources are relatively centrally controlled.

The NIST model of cloud computing considers the essential characteristic of cloud computing to be Self Service: “A consumer can unilaterally provision computing capabilities, such as server time and network storage, as needed automatically without requiring human interaction with each service provider.”

In addition, another NIST model essential characteristic, “rapid elasticity,” is how and why cloud systems have become known for cost overruns: “Capabilities can be elastically provisioned and released, in some cases automatically, to scale rapidly outward and inward commensurate with demand. To the consumer, the capabilities available for provisioning often appear to be unlimited and can be appropriated in any quantity at any time.”

The “measured service” essential characteristic comes to the rescue and is core to cloud cost monitoring and optimization: “Cloud systems automatically control and optimize resource use by leveraging a metering capability at some level of abstraction appropriate to the type of service (e.g., storage, processing, bandwidth, and active user accounts). Resource usage can be monitored, controlled, and reported, providing transparency for both the provider and consumer of the utilized service.”

Still, if the consumer, operator or end-user does not or cannot access the measured service to understand cost, it is easy to overspend.

The value of Kubernetes cloud cost monitoring and optimization

Kubernetes is a cloud-native tool and carries with it the inherent benefits and dangers of cloud systems.

Kubernetes is designed to automate ‘right sizing’ a cloud environment. This entails scaling systems up and down in response to demand on the system’s CPU and Memory needs. The danger is that this inherent automation can scale up without oversight and drive costs up to new and unexpected heights. It is possible to manually set limits on resource consumption – but again, without oversight, this could cause performance issues (out of memory, out of CPU).

Now you know there’s a problem, here’s the solution.

Two approaches to cost monitoring and management

  • Manual: You see the cost, make an adjustment afterward. You use metrics to evaluate resource use and manually calculate costs, using a tool like Kubecost.

  • Automated: You evaluate costs and automatically tune the system to maintain appropriate limits using AI-driven software..

What are Kubernetes Best Practices?

On the technical side of things:

  • Configure the system with application appropriate limits on Memory and CPU.
  • Explore the optimization space to find better ROI (e.g. tuning instance types).
  • Enable a metrics engine and trigger alerts when limits are being approached.
  • Set a review cadence to assure the initial system configuration continues to be optimal.

When it comes to cost ownership:

  • Have an “honor system.” Assume that individuals and teams are aiming for and have the necessary tools and insight to deploy and manage a system that is optimized for cost and performance.
  • Implement showback. Metrics and cost are centrally managed. Costs are shared with individuals and teams to help them to deploy and manage a system that is optimized for cost and performance.
  • Implement chargeback. Operating budgets are allocated to individuals or teams. Costs are charged against team operating budgets to require optimizing for cost.

Automating cloud cost optimization

You can do this manually. Although Kubernetes is an automation engine that can be readily tuned on myriad parameters, the typical approach to optimizing K8s is very manual. Look at metrics → evaluate costs → edit system configuration → repeat. Even with reasonable data from a metrics engine, the myriad options from instance types and sizes, multiple tuning parameters and more make evaluating cloud pricing far from straightforward.

© All rights reserved — cs.fyi