All Collections
Cost Centers & Integrations
Kubernetes
Kubernetes - How Finout Calculates K8s Costs
Kubernetes - How Finout Calculates K8s Costs
Updated over a week ago

The cost of a Kubernetes (K8s) pod can vary depending on various factors, such as the size of the pod, the resources allocated to it, the duration of its usage, and the cloud provider or infrastructure used to run the pod. To accurately calculate the cost of a K8s pod, it is essential to consider the resources consumed by the pod, including CPU, memory, storage, and network bandwidth. The cost of these resources may differ depending on the cloud provider or infrastructure used.

Step 1: Query the Metrics

Finout provides multiple ways to integrate your K8s clusters with MegaBill, including Datadog or with a cronjob that queries your Prometheus. Metrics are gathered from the source frequently, including CPU usage, memory usage, CPU request, memory request, and network usage.

Step 2: Parse the Usage Metrics Per Pod

Once the data is received, it is processed to determine how much of the allocated resources the pod has used per hour. The usage metrics are processed as follows:

  • Memory and CPU: This is done by identifying the maximum value of either the usage or request during the hour. For example, if the maximum request during the hour is 3 CPU units and the maximum usage is 1 CPU unit, the cost is based on 3 CPU units. If during the hour, the usage was 4 CPU units, the cost is based on 4 CPU units This is calculated for both CPU and memory for each hour and each pod.

  • Network usage: Finout calculates the total number of bytes per pod (both received and transmitted) per hour.

Step 3: Get the Hourly Rate Per Cloud VM (Node)

One of the unique features of Finout is that your cost data is fetched from all major cloud vendors. Finout can consume, for example, the AWS Cost and Usage Report (CUR) and determine the exact cost of a single node, accounting for special pricing and discounts, such as Saving Plans, Reserved Instances (RIs), Spot Instances and if needed your EDP. This allows Finout to calculate the hourly node cost accurately.

Step 4: Calculate the Pod Costs

To calculate the cost of a pod, Finout uses the hourly CPU, memory, and network allocations (step 2), along with the hourly node cost (step 3), to determine the pod's CPU and memory cost, respectively.

CPU & memory

The hourly node cost is reported as a total cost and represents the cost for CPU and memory resources. The problem is that the cloud provider does not provide a CPU/memory breakdown. To apportion the costs to CPU and memory costs correctly, Finout specifies a configurable CPU/memory ratio for each resource, cluster or namespace.

The default ratio is 50:50 for balanced and average workloads. This can be modified depending on whether the CPU or memory is more dominant, for example, for a memory-intensive resource a ratio of 25:75 may be more appropriate.

Network cost

For each node, Finout can calculate the data transfer hourly cost, based on the information supplied by the cloud provider. To calculate the network cost for each pod, Finout uses the network received and network transmitted metrics per pod and divides the cost of the node up into the pods based on these network metrics.

Step 5: Calculate the Node-Level Waste (Unallocated)

The unallocated cost at the node level is also calculated, which is the difference between the hourly node cost and the sum of hourly pod costs running on that node. This helps identify any unallocated costs associated with idle or underutilized nodes.

With Finout's comprehensive cost calculation and reporting capabilities, you can gain better visibility into the cost of running K8s pods and optimize your cloud costs effectively. Our CostGuard dashboards provide valuable insights to help you make informed decisions and implement cost optimization efforts for your K8s workloads.

Still need help? Please feel free to reach out to our team at [email protected].

Did this answer your question?