As the middle layer of IaaS and PaaS, the billing of Kubernetes currently relies on the resource billing of IaaS. A Kubernetes cluster is billed by the purchased node CVMs. However, users use the Pods. In actual scenarios, users are often faced with questions such as how does a Pod bear the cost, how to evaluate the cost of the cluster, how to make cost predictions and optimization suggestions. For the above problems, we recommend users to use Kubecost.
Kubecost is a cost analysis tool that can provide insights, analysis, recommendations and suggestions on cluster costs. As your financial analyst for optimizing cluster costs, Kubecost can provide you with a comprehensive cost analysis report. This document describes the Kubecost use cases, optimization suggestions, detailed features, and how to install and use it.
The cost expenditure is the cost of calculating Pod resource request (Request) or usage (Usage). The cost of Pod is calculated based on the IaaS billing method of the node where the Pod is located.
Currently, the node billing modes of cloud vendors are generally monthly subscription (Month), pay-as-you-go (Hour) and spot instance. When you use Kubecost to calculate the cost of Pod, even containers with the same requests have different costs on different types of nodes.
In the above three billing modes, user purchases an entire instance. The billing is based on the instance, not for a single resource. By using Kubecost, you can refer to the model to analyze the apportioned cost of each resource type and each resource.
For example, a cloud vendor provides a node (virtual machine or physical machine) with 1 CPU core (C), 1 GB memory (Mem), and a price of 20 CNY/month.
By using Kubecost, you need to add the basic price of each resource specified by the cloud vendor, such as the CPU and Mem prices, or configure the corresponding ratio based on the business needs, for example, the price ratio of 1 Core:1 GB is 3:1, CPU/Mem=3:1. You can know the billing allocated to each resource (CPU/GPU/Mem/PV/Network).
The calculation formula is as follows:
sum (normalized_resource_price[i] × resource_quantity[i]) = node_price
Therefore, the price of the entire node is 20 CNY/month, and the apportioned cost is 15 CNY/month for CPU and 5 CNY/month for Mem.
You can evaluate the cost efficiency via cost weighted average. Because the cost weight of each resource is different (cost weight means that different types of resources are sold at different prices. For example, the price of computing resources such as CPU and GPU is relatively high, while the price of Mem is relatively low, and the price of disk is even lower), the contribution of different resources to the cost is also different for the same resource utilization efficiency.
For example, if the disk utilization is 100%, since the disk is relatively cheap, the contribution to the final cost control is low. However, for the CPU resources, even if the resource utilization rate is 30%, since the price of CPU resources is relatively expensive, it may play a key role in the cost. Therefore, it is necessary to use weighted average to evaluate the cost efficiency, for example:
When judging which services need to be optimized and how to optimize the cost structure, you can first look for the TOP 10 resource wastes. For example, the Usage of resources is very different from the Request. You can obtain the recommended Request based on the application monitoring profile, and finally calculate each resource costs that can be saved.
For the node auto scaling, you can measure the final cost if the CPU and Mem of each node in the cluster increase by 1 core and 1 GB, and whether there will be a scale effect (the scale effect means that when the number of resources increases, the cost does not explode, but the bin packing problem is solved).
If you have the above requirements and problems, you can use Kubecost to analyze your cluster cost trends.
The corresponding description for each part is as follows:
The corresponding description for each part is as follows:
The Kubecost Assets view shows the fine-grained cost allocation of a Kubernetes cluster based on a single resource in the cluster (for example, the cost allocated by nodes, disks, and other resources).
It shows the monthly estimated savings and the number of optimization suggestions for cost savings, namely the first entry in the “Overview” page.
Here takes Request Sizing Recommendations as an example, as shown in the second figure below. The following three levels of recommendation values are provided, and the recommended values are also related to the given time window:
The score of the cluster infrastructure status. If there are suggested repairs, it will be marked with a red exclamation point ❗, as shown in the figure below:
Reports are mainly used to save the observation data. The observation granularity is the same as that in Cost Allocation. It supports data storage with one-click after data aggregation/observation in a certain way, as shown below:
Log in to a node and run the following command to install Helm.
curl https:``//raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash
Run the following command to download the Kubecost Helm:
wget https:``//qitian-1251707795.cos.ap-beijing.myqcloud.com/cost-analyzer-1.81.0.tgz
Run the following command to install Kubecost:
kubectl create ns kubecost``helm install cost-analyzer cost-analyzer-``1.81``.``0``.tgz -n kubecost
Run the following command to check whether the Pods are running properly, as shown below:
kubectl get pods -n kubecost -o wide
The execution result is as shown below:
Run the following command to uninstall Kubecost:
helm uninstall cost-analyzer -n kubecost
Was this page helpful?