Tracking the efficiency of resource requests on Kubernetes
Tags: kubernetes, usageanalytics, costoptimization, capacityplanning
Published: 2022-02-10 08:49:39

## Problem Context
Best practices on Kubernetes recommend setting resource requests (and also limits?) on workloads. It's even possible to set cluster-level policies to reject manifests without resource requests. However, one of the problems that this raises is the ability to suitably assess and set resource requests in a way that avoids wasting resources due to unused requested (i.e. reserved) capacities.

> So, how to measure the efficiency of resource requests set on your Kubernetes workloads to avoid wasting resources due to oversized requested (i.e. reserved) capacities?

## Our Original Contribution
Thanks to [kube-opex-analytics](https://github.com/rchakode/kube-opex-analytics), an open source Kubernetes usage analytics and accounting tool (read more about it at the end of this story), we address the problem of assessing the efficiency of resource requests set on Kubernetes workloads.
The release [v22.02.0](https://github.com/rchakode/kube-opex-analytics/releases/tag/v22.02.0) introduces a new indicator called 𝐔𝐬𝐚𝐠𝐞/𝐑𝐞𝐪𝐮𝐞𝐬𝐭 𝐄𝐟𝐟𝐢𝐜𝐢𝐞𝐧𝐜𝐲. Conceptually, this indicator is defined as the ratio between the actual usage and the resource requests. The indicator is provided by namespace and, as all other kube-opex-analytics indicators, it's computed based on hourly-consolidated Kubernetes metrics.

> By tracking and visualizing the usage/request efficiency indicator over time, Kubernetes administrators do have an additional tool to take appropriate cost-optimization decisions.

![kube-opex-analytics :: Usage/Request Efficiency chart](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zp9cfq3zg2aij5nj6zw9.png)_kube-opex-analytics - A chart showing the usage/request efficiency for CPU (1) and memory (2) resources for a selectable period of time (4). At specific date time, a tooltip (3) provides details for each namespace. It's possible to export (5) the chart as PNG image or as CSV and JSON data file_.

The next section discusses possible values of this indicator.

## Understanding Usage/Request Efficiency
At a given namespace and a given time, the value of this indicator can be in one of the following ranges:

- A **value equal to 1** means an effective match between the actual usage and requests; this is also the default value if no resource requests are set in the namespace.

- A **value between 0 (excluded) and 1** does mean that the actual usage is lower than resource requests. A value close to zero typically means that requests are oversized, and that they need to be reviewed to avoid wasting resources.

- A **value greater than 1** means that the actual usage is greater than the requests. It's likely an ideal situation to avoid wasting resources. However, in this case it's likely necessary to have resource limits or namespace quotas set to be sure that the resource consumption will be under control.

## About kube-opex-analytics
kube-opex-analytics (literally Kubernetes Opex Analytics) is an open source Kubernetes usage analytics tool to help organizations track the resources being consumed by their Kubernetes clusters over time (hourly, daily, monthly). Doing so, kube-opex-analytics aims to prevent overpaying by enabling each organization to understand how their Kubernetes resources are consumed over time, and hence be able to make appropriate cost optimization decisions.

Some of its key features include:

- Usage accounting and trends per namespace.
- Accounting of non-allocatable capacities(nodes and cluster levels).
- Cluster usage accounting and capacity planning.
- Usage/requests efficiency.
- Cost allocation and chargeback analytics.
- Insightful and extensible visualization.

You can get additional information on kube-opex-analytics via [its GitHub page](https://github.com/rchakode/kube-opex-analytics).

## Conclusion
In this story we have presented an original indicator to track the efficiency of resource requests set on Kubernetes workloads. The aim of this indicator is to provide Kubernetes administrators a tool to make appropriate cost-optimization decisions.

Don't hesitate to share your feedback.