Pods are the smallest deployable units in Container Service for Kubernetes (ACK) clusters. Pod costs are critical factors in the calculation of the cluster cost. Different pods may have different resource specifications, scheduling policies, and lifecycles. Therefore, estimating the cost of a pod is complex. ACK designed a cost data model to define various types of costs and provide calculation methods for these costs. This model provides a method for you to accurately estimate the costs of your ACK clusters and allocate cluster costs to business units by dimensions such as cluster, namespace, and application.
Terms
The following table describes the terms used in the cost data model.
Term | Description |
Total cluster cost | The total cost of a cluster. |
Cluster asset cost | The total payment amounts in the bills of the cloud resources used by a cluster. |
Indirect cluster cost | The additional or indirect cost of the cluster, such as the cluster management fee. |
Allocated resource cost | The cost of allocated resources in the cluster. The cost can be calculated by multiplying the capacity ratio of allocated resources by the asset cost of the cluster. |
Idle resource cost | The cost of idle resources in the cluster. The cost can be calculated by multiplying the capacity ratio of idle resources by the asset cost of the cluster. |
Pod allocated cost | The cost of a pod allocated from the asset cost of the cluster within a specified time period. |
The total cost of a cluster is calculated based on the following formula: Total cluster cost = Asset cost + Indirect cost
.
The asset cost of a cluster is calculated based on the following formula: Asset cost = Allocated resource cost + Idle resource cost
.
The allocated resource cost is calculated based on the following formula: Allocated resource cost = Σ(Allocated costs of pods in the cluster)
The following figure shows the architecture of the cost data model
Cost data model
Cluster Asset Cost
An ACK cluster uses basic cloud resources and optional cloud resources. Basic resources include resources such as Elastic Compute Service (ECS) instances, Server Load Balancer (SLB) instances, and disks. Optional resources include resources such as Prometheus instances and NAT gateways. The asset cost of a cluster is equal to the total payment amounts in the bills of the cloud resources used by the cluster.
The
ack.aliyun.com:<Cluster ID>
label is automatically added to the cloud resources created by the cluster. You can use this unique label to filter the bills of cloud resources.You can manually add the preceding label to the user-created cloud resources used by the cluster. This way, you can use this label to filter the bills of cloud resources.
Pod allocated cost
Formula
In most cases, no pod bill is generated. You can allocate the asset cost of the cluster to a pod by cost ratio. Then, you can aggregate pod costs to obtain your business bills from various dimensions. Therefore, you need to calculate the cost ratio of a pod before you can allocate the asset cost to the pod.
Pod allocated cost = Pod cost ratio × Cluster asset cost
The cost ratio of a pod refers to the ratio of the simulated pod cost to the total cost to be allocated.
Pod cost ratio = Simulated pod cost/Total cost to be allocated
You can simulate the cost of a pod based on a simulated unit price of the pod and the uptime of the pod. When you generate a simulated unit price of a pod, you must take into account the resources (CPU cores, memory, and GPUs) allocated to the pod and the unit prices of the resources.
Simulated pod cost = Simulated pod unit price × Pod uptime
Simulated pod unit price = Σ(Resource unit price × Amount of allocated resources)
The resource unit price is the key factor in the calculation of pod costs. The resource unit price is adjustable in specific scenarios. When you perform internal cost accounting, you can use the list price set by the cloud service provider as the unit price. If the cloud service provider does not set the unit price, you can use a custom unit price based on your business requirements.
Scenario 1: Use the list price as the unit price
After you obtain the list prices of different resources allocated to a pod, you can calculate the pod cost ratio and simulated pod cost based on the following formulas:
Pod cost ratio = Simulated pod cost/Σ(Cost of each node in the cluster)
Simulated pod unit price = (CPU core unit price × Number of allocated CPU cores + Memory unit price × Amount of allocated memory + GPU unit price × Number of allocated GPUs) × Pod uptime
Scenario 2: The unit price is not set by the cloud service provider
If the resource unit price is not set by the cloud service provider, you can use a weighted calculation method to calculate the resource unit price. For example, if you use a node that charges you based on a total node price set by ECS, you can calculate the resource unit price based on the following formulas. Weighted calculation increases the flexibility of the cost data model.
Resource unit price = Resource weight × Resource unit price/Resource capacity on the node
Σ(Weight of each resource) = 1
In this case, the weight of a resource determines the unit price of the resource. By default, the weight of a resource in ACK clusters is determined by the watermark of the resource. You can adjust the resource weight based on your business requirements.
Calculate the cost of a namespace or application
After you obtain the allocated cost of each pod in the cluster, you can calculate the cost of a namespace by aggregating the costs of pods in the namespace, or calculate the cost of an application by aggregating the costs of pods created for the application.
A namespace is a collection of pods that have one or more fields in common.
Namespace cost = Σ(Allocated cost of each pod in the namespace)
A workload consists of pods that have identical labels in the same namespace.
Workload cost = Σ(Allocated cost of each pod with identical labels)
References
You can send HTTP API requests to retrieve cost insights data and use the data for custom development. For more information, see Overview of calling an API to query cost data.