DEV Community

Cover image for Kubernetes Multi-Cluster Part 5: Cost Optimization
Lukas Gentele for Loft Labs, Inc.

Posted on • Originally published at loft.sh

Kubernetes Multi-Cluster Part 5: Cost Optimization

By Elly Obare

This article is the fifth part of a series focused on Kubernetes multi-cluster technology. Part one introduced the series, including the goals and responsibilities of multi-cluster setups. Part two covered how to manage the cluster lifecycle, and part three looked at access control, while part four focused on developer experience and self-service provisioning.

Developers desire deployment environments that are feature-rich, reliable, and accessible from anywhere—tapping into the power of the multi-cluster. With organizations consistently migrating their workloads to Kubernetes and embracing self-service for developers, the key concern now is how to achieve cost optimization and cost monitoring for multi-clusters within an organization.
As illustrated in the previous articles, cluster setups require sound planning, design, and deployment. This can be difficult to achieve without also monitoring and optimizing their costs.

As a continuation of our multi-part series on Kubernetes multi-cluster setups, this article will focus on approaches to the management and optimization of cluster-related costs. It will also suggest some tools that can not only effectively monitor usage and related costs but also effectively reduce such costs through features such as sleep mode and auto delete.

Before going into the details of cost optimization, the next section will provide a brief refresher on the multi-cluster concept and why it’s important.

What Is Kubernetes Multi-Cluster?

Kubernetes is an open source platform that creates clusters that run and manage workloads. More specifically, it’s an orchestration tool for automated deployments of containerized workloads and services.

Kubernetes multi-cluster, on the other hand, refers to creating multiple clusters when running workloads and defining resource isolation, continued availability, and resource flexibility. Kubernetes multi-cluster technology allows organizations to provision their workloads in several clusters rather than just one, a strategy known as Kubernetes multi-cluster orchestration. It's simply provisioning workloads in several Kubernetes clusters (going beyond a single cluster).

To run a Kubernetes multi-cluster seamlessly, a business needs to coordinate the planning, delivery, and management of several Kubernetes clusters by leveraging tools and platforms, like CAST AI and Loft, that we’ll examine later in this article.

Why Do You Need a Kubernetes Multi-Cluster?

Multi-cluster strategy goes beyond simple static workload deployments. Mainly, a multi-cluster deploys services across multiple locations while increasing flexibility in infrastructure access for large teams. Since multiple cluster setups can be created from multiple hosts in the same data center or even in a single cloud provider across different regions, organizations can shift their workloads from one cluster to another cluster easily and transparently. Ease in migration of workloads helps solve cluster disasters, scaling, critical infrastructure downtimes, and optimization.

Therefore, organizations need Kubernetes multi-cluster topologies to manage workloads that they need to run in different regions, eliminate cloud blast radius, manage regulatory requirements, introduce isolation, and enforce security around clusters and tenants.

If you need more of a refresher about the Kubernetes multi-cluster and its importance, you should have a look at the previous articles in this series. But regardless of the background reading, you should already have enough of an idea of how to set up an enterprise-grade multi-cluster environment and how you might benefit from cost optimization recommendations.

Cost Optimization for Kubernetes Multi-Cluster

Developing and deploying applications in Kubernetes clusters may be relatively straightforward. However, as the workloads and clusters scale, the need emerges to optimize running resources and monitor for wastage to reduce the costs of running your environments. Cost monitoring and optimization ensures that enterprises efficiently utilize resources relating to compute, memory, pods, namespaces, services, controllers, and others, without accruing huge bills.

The following are some actions that teams can consider to optimize their cluster resources and keep Kubernetes cloud costs checked:

  • Managing node density: The number of nodes running in a cluster is critical for cost optimization. Therefore, it’s important to ensure your team is running the right size, number, and type of node in your Kubernetes cluster.
  • Maintaining Pod sizes: To manage the cost of your Kubernetes clusters, resource requests and limits can be used to avail enough resources for optimal performance, but not so much for wastage. Examine your pod usage and application performance over time to consider rightsizing your pods through requests and limits.

  • Autoscaling: Kubernetes features autoscaling capabilities to keep the right cluster resources running, such as the size and number of pods, nodes, and clusters depending on the needs. Features like the Horizontal Pod Autoscaler (HPA) and cluster autoscaler are all you need to keep your clusters fit for on-demand needs and to efficiently manage your costs.

In short, cost monitoring and optimization help eliminate the root inefficiencies that result in overspending by rightsizing Kubernetes cluster resources based on the actual needs of your teams and the nature of the projects being run.

Tools for Efficient Cost Optimization and Monitoring

Here are some tools to consider that can help manage your team’s Kubernetes resource spending.

Kubecost

Kubecost is an open source tool that provides a granular view of Kubernetes costs. Kubecost breaks down and tracks costs related to the finer Kubernetes cluster resources, including namespaces, individual pods, and running containers. It provides detailed visibility into Kubernetes resources and operational insights within the clusters.

From the cost center utility, Kubecost allows teams to monitor every single unit that can impact costs. It features a built-in visualization tool—Grafana—for monitoring Kubernetes cluster costs.
It has a number of key features that make it great for cost monitoring:

  • It’s a unified Kubernetes cost monitoring tool that is vendor agnostic. Kubecost tracks costs for Kubernetes deployments in AWS, AKS, and other common multi-cloud environments.
  • The tool auto-generates cost optimization recommendations visible from its UI or APIs, so cluster admins can apply these recommendations for immediate results.
  • It also features real-time alerting capabilities for teams to take control of their Kubernetes-related costs and stay within budget.

CAST AI

CAST AI is an automated platform that analyzes your Kubernetes clusters for top performance and cost optimization. It can cut your cluster costs by half through fast and predictable automated cost monitoring. This tool features autoscaling on the go, real-time rightsizing of nodes and pods, and spot-price automation among many other features to keep your cluster costs as low as possible.
With CAST AI, you can track running instances and visualize their associated costs through the in-product dashboard and Prometheus, which is supported.

Furthermore, CAST AI integrates seamlessly with major cloud Kubernetes cluster environments such as AKS, EKS, GKE, and Kops, running on an AI-driven cost optimizer to give finer details of your cluster costs.

Loft

Loft is an open source platform that offers managed self-service solutions for smoothly creating and scaling Kubernetes clusters. Loft features cost optimization on autopilot, self-service cluster provisioning, secure Kubernetes multi-tenancy, enterprise-grade access control, etc.

This tool has quality features to help developer teams manage their resource costs. Sleep mode and auto-delete in particular are powerful features geared towards managing your resource costs. Loft monitors your environments to identify idle namespaces, virtual clusters, and container workloads that scale your cluster costs upwards.

When enabled, sleep mode acts on the resources in your Kubernetes namespaces, putting them to sleep through its inactivity monitoring and detection capability. This mode lets any idle workload—in other words, when no process depends on the workload or after a certain period of inactivity—sleep automatically. Sleep mode can be customized by a user or a team, depending on how they use their resources. Sleep mode can also be set to wake workloads up.

Sleep mode alone can lead to savings of up to seventy percent of the cost that the dev and other pre-production workloads may incur. Sleep mode will watch for any wastage of CPU and memory and only persist namespaces that are needed.

Meanwhile, Loft’s auto-delete feature also helps to optimize your cluster resource costs by identifying and deleting idle, old, or unused namespaces and virtual clusters, keeping your clusters clean. For instance, in switching between projects and environments, your developers have forgotten to turn things off, or maybe resources are being wasted by demo environments and pull requests that are already stale. Auto-delete can come in handy for these situations.

Conclusion

Whether you’re experienced with Kubernetes or just beginning your journey, staying on top of your Kubernetes cluster running costs is paramount to stay in operation. The task of cost monitoring and optimization for cluster environments requires dedicated platforms and tools, such as Loft, which comes with intuitive features for visualization.

This article explained the basics of cost monitoring and cluster cost optimization and their importance. It also walked you through approaches to managing and optimizing cluster-related costs, and introduced some tools for effectively monitoring and reducing usage and associated costs through features such as sleep mode and auto-delete.

Photo by Annie Spratt on Unsplash

Top comments (0)