FinOps for Kubernetes

Jaydeep Ayachit
6 min readMar 2, 2024

Introduction

As more and more organizations are adopting cloud native ways to deliver services and migrate/run their workloads in Kubernetes, understanding costs, spends and optimization becomes important. It is particularly challenging in Kubernetes environments due to its complexity, dynamic nature of the running workloads, and abstraction over the infrastructure.

FinOps is a practice and culture for teams to manage their cloud costs. In FinOps model, everyone takes ownership of their cloud usage and costs and optimize it to the best.

In this article we will look at the challenges of applying FinOps principles to Kubernetes environments. We will also look at some of the best practices and recommendations for effective FinOps strategy.

Why FinOps for Kubernetes

Many organizations are now aware of FinOps practices and takes cloud cost monitoring and optimization seriously. The cloud providers provide necessary support in terms of itemized bill, using tags and labels to allocate and track costs etc. However, it is not uncommon to find out that Kubernetes environments costs are more than anticipated. This may be because of overprovisioning without understanding the baselines or could be because of lack of proper monitoring to track and optimize costs. Kubernetes environments are often shared between multiple teams and applications. Such shared resources, often create challenges with cost allocation and tracking.

In the traditional way, cloud providers charge you based on the server instance provisioned or database instance provisioned. For Kubernetes you are charged for the control plane nodes, data nodes and other infrastructure (storage, load balancer etc) used by the cluster. The traditional way of cost allocation does not necessarily work here since you can’t allocate cost based on tag or label when the environment is shared between multiple parties. To find the cost for a container that runs in the cluster, you need to find out what resources from the underlying infrastructure are consumed by the container. Add to this satellite costs like nodes, storage, licenses.

Challenges

Let’s see some of the challenges that Kubernetes environments poses while applying FinOps principles.

Abstraction: Kubernetes introduces abstraction between your workloads and the underlying infrastructure. The abstraction is transparent and makes it challenging to allocate costs to customer, team, or application.

Cost allocation: In a traditional cloud environment, you can assign one or more tags to non-container resources. This makes tracking and accountability easy as you can map any resource to team, cost center, application, environment etc. In Kubernetes environment, clusters are shared, with applications run by more than one team. There is no direct cost to containers as the cost allocation tags are tracked and managed at cluster level.

Dynamic nature of environments: Containerized environments are much more dynamic than non-containerized environments. The pods are created and destroyed; they are moved across nodes across instance types and availability zones. The nodes themselves are created and destroyed. The cost tracking and management needs to be in sync with this dynamic nature of the environment which makes it complex.

Non-Kubernetes resources: Teams using Kubernetes also have non-Kubernetes resources. A strategy needs to be devised that takes into account cost allocation tags for non-Kubernetes resources and labels for Kubernetes resources blended together for a uniform view.

FinOps principles for Kubernetes

The FinOps Foundation created six core principles that guide FinOps practices. In this section, we will look at the principles and how they can be applied for Kubernetes.

1. Collaboration

FinOps uses cost as an efficiency metric for all teams. Teams like development, technology, IT, finance, and business need to work together in near real time. The team needs to understand and collaborate on cost tracking, cost management and optimization considering the cloud billing model.

2. Decisions are driven by business value of cloud

As teams focus on cost efficiency via cost tracking and optimization, they also need to focus on business value derived.

Trend analysis helps to understand how costs are changing. Variance analysis helps to understand how rapidly the costs are changing. Teams should focus on correlation between increased cost and corresponding derived value, growth and performance to put the spends in right perspective.

3. Accountability

FinOps defines cost efficiency as a key metric. Technical teams should consider this metric from start of the project as a continuous activity and not an independent activity. This may require decentralizing the decision making around cost-effective architecture, resource usage, and optimization.

The teams need to be accountable for usage and costs. For this, teams need to take ownership of costs starting from defining a cost-effective architecture and design, implementation, and operations.

To be able to meet this principle, consider –

a. Bringing in appropriate tooling that helps with costs breakdown across teams, applications, and environments.

b. Providing centralized guidance on cost effective architectures and designs while decentralizing application and implementation.

c. Use labels to allocate costs for each of the tenants based on usage. Labels are key-value pairs that can be added to Kubernetes objects like pod and deployments. The cost associated with the resources that are labelled then can be rolled up to aggregate cost at application or tenant level.

d. Combine labels with resource tags to identify and track cost for shared resources or non-containerized resources used by containerized application. This helps you to get a holistic view of the cost.

Teams should also consider recommendations from FinOps org on FinOps platforms that can help with these.

4. Visibility

For FinOps to be effective, it is prudent that cost data is available as soon as possible. The real-time or near real-time visibility into cost data drives better utilization, helps to create feedback loops for optimization. The availability of such data can also drive automation to do continuously improvements in FinOps processes.

To be able to meet this principle, consider –

a. Bringing in appropriate reporting tool that collects, process and makes cost data available as soon as possible. Kubecost, CloudZero, Harness, and Loft are some of the tools that can be evaluated.

b. Bringing in appropriate tooling for budgets and cost notifications when spends exceeds budgets.

c. Performing historical data analysis to identify trends, patterns for planning and forecasting. Evaluate reporting tool capabilities to meet these requirements.

5. Centralization

As we saw, FinOps recommends a decentralized approach for the teams, however a centralized team must own, control, and govern FinOps. The centralized team is responsible for rate negotiations, discounts, and commitments to take advantage of economies of scale. This way the technical teams can stay focused on cost optimization for their own environments.

To be able to meet this principle, consider –

a. Purchasing long term commitments for reserved instances to be used as worker nodes brings down cost of cluster.

b. Negotiating contract terms with cloud provider that includes discounted price options.

c. Use benchmarks to show usage of best practices.

6. Take advantage of the variable cost model of the cloud

The variable cost model of the cloud should be leveraged to gain maximum benefit. This includes just-in-time provisioning, provisioning immutable environments, scaling the infrastructure and resources as demand increase instead of static long-term plans.

To be able to meet this principle, consider –

a. Autoscaling: Kubernetes offer pod autoscaling using Horizontal Pod Autoscaler (HPA) and cluster autoscaling using Cluster Autoscaler. Autoscaling helps to adapt quickly to demands.

b. Pod rightsizing: Allocate resources for optimal performance. For this, examine pod metrics over a period of time to adjust requests and limits.

c. Node rightsizing: Understand the workload requirements and right size the nodes in the cluster. This can also include reducing number of nodes or increasing number of nodes.

Conclusion

More and more organizations are adopting Kubernetes and cloud-native ways to deliver services and run containerized workloads. Just like organizations do a due diligence applying FinOps practices for cloud, they also need to define similar approach for Kubernetes environments. This helps organizations optimize Kubernetes environments without sacrificing agility and innovation.

We looked at six principles of FinOps and how they can be mapped to Kubernetes environments. FinOps is recommended to be driven by central FinOps practice while decentralizing implementation and optimization. It is important to imbibe and adopt FinOps practice from the start of the project as a continuous activity throughout the lifecycle of the project.

--

--