All Products
Search
Document Center

Container Service for Kubernetes:Cost estimation policies

最終更新日:May 31, 2024

In Container Service for Kubernetes (ACK) clusters, a pod may use multiple cloud resources and a cloud resource may be used by multiple pods. For enterprises, the key to successful cost allocation by department or application is to calculate the cost of pods. When you estimate the cost of a pod, you need to consider the costs of the resources used by the pod. To better meet the requirements for cost estimation in ACK clusters, the cost management suite of ACK provides cost estimation policies that are implemented based on resource watermarks.

Introduction to cost estimation policies

Policy

Description

Scenario

Single resource cost estimation

Estimate costs by CPU or memory

This policy is suitable for scenarios where the CPU or memory watermark of the cluster is much higher than the other one. This policy is also suitable for scenarios where most applications in the cluster use only one type of resource.

Weighted resource cost estimation

Estimate costs by CPU and memory based on the recommended weights or custom weights.

This policy is suitable for scenarios where the CPU watermark of the cluster is close to the memory watermark. This policy is also suitable for scenarios where applications in the cluster use both types of resources.

Single resource cost estimation

This is the default cost estimation policy. If you want to calculate the cluster cost based on the resource watermark of the cluster, we recommend that you use this policy.

Use scenarios

The resource watermark refers to the ratio of the requested resource to the total resources. In most cases, the resource watermark of a cluster depends on the mostly requested resource type. Therefore, the single resource cost estimation policy is suitable for scenarios where the CPU or memory watermark of the cluster is much higher than the other one. In these scenarios, most applications in the cluster use only one type of resource.

Memory-intensive applications such as Java applications request a large amount of memory resources from the cluster. In this case, the memory cost is much higher than the CPU cost. Memory resource supply determines whether the applications in the cluster can be scheduled. The single resource cost estimation policy is suitable for the preceding scenario. If the memory watermark is 90%, the memory cost accounts for 90% of the cluster cost. This means that the memory watermark completely matches the memory cost ratio.

How it works

This policy calculates the CPU or memory cost of a pod.

Calculate the cost of a pod

This policy uses the following formula to calculate the CPU or memory cost of a pod:

image..png

Calculate the cost of a namespace

A namespace is a group of pods that have one or more fields in common. After you obtain the cost ratio of each pod in the cluster, you can calculate the fees of a namespace by multiplying the sum of the cost ratio of each pod in the namespace by the sum of all payment amounts in the bills of the cluster.

  • The cost of a namespace is calculated based on the following formula:

    image..png

  • The cost ratio of a namespace is calculated based on the following formula:

    图片 1

Weighted resource cost estimation

Use scenarios

If applications in a cluster use both types of resources or the CPU watermark of the cluster is close to the memory watermark, we recommend that you use the weighted resource cost estimation policy. When the CPU cost is close to the memory cost, you can compare the CPU cost and the memory cost by comparing the CPU watermark and the memory watermark.

How it works

The weighted resource cost estimation policy calculates the cost of a pod based on the CPU weight and memory weight of the pod. The CPU weight and the memory weight are determined by the CPU watermark and memory watermark of the cluster.

Calculate the cost of a pod

Unlike the single resource cost estimation policy, the weighted resource cost estimation policy calculates the cost of a pod based on the CPU weight and memory weight of the pod. This policy uses the following formula to calculate the cost of a pod:

image..png

The CPU watermark, memory watermark, CPU weight, and memory weight are calculated based on the following formulas:

  • CPU watermark:

    image..png

  • Memory watermark:

    image..png

  • CPU weight:

    image..png

  • Memory weight:

    image..png

Examples

The following examples show how to choose a suitable cost estimation policy in different scenarios.

Example 1: Most applications in the cluster use only one type of resource

In the following figure, two memory-intensive applications are deployed in the cluster. One application requests 1 vCore and 2 GB of memory, and the other application requests 1 vCore and 4 GB of memory. In this case, the memory watermark of the cluster is 90% and the CPU watermark is 20%. Assume that the daily cost of the cluster is USD 200.

  • Single resource cost estimation:

    • If you calculate the memory cost of the cluster, the pod cost is USD 180 (USD 200 × 90%). The result is close to the total cost of the cluster.

    • If you calculate the CPU cost of the cluster, the pod cost is USD 40 (USD 200 × 20%). A large amount of the cluster cost is unallocated and only 10% of the memory provided by the cluster is available for pod scheduling.

  • Weighted resource cost estimation:

    The memory weight is approximately 80% and the CPU weight is approximately 20%. The pod cost is USD 152 (USD 180 × 80% + USD 40 × 20%). USD 28 is unallocated. The result is less than the result when you calculate the memory cost.

The results indicate that the memory cost accounts for 90% of the cluster cost when the single resource cost estimation policy is used. Therefore, the single resource cost estimation policy is suitable for scenarios where most applications in the cluster use only one type of resource.

image

Example 2: Applications in the cluster use both types of resources

In the following figure, a memory-intensive application and a CPU-intensive application are deployed in the cluster. One application requests 1 vCore and 4 GB of memory, and the other application requests 4 vCores and 1 GB of memory. In this case, the CPU watermark of the cluster is 40% and the memory watermark is 50%. Assume that the daily cost of the cluster is USD 200.

  • Single resource cost estimation:

    • If you calculate the memory cost of the cluster, the pod cost is USD 100 (USD 200 × 50%).

    • If you calculate the CPU cost of the cluster, the pod cost is USD 80 (USD 200 × 40%).

  • Weighted resource cost estimation:

    The memory weight is approximately 56% and the CPU weight is approximately 44%. The pod cost is USD 91.2 (USD 100 × 56% + USD 80 × 44%). USD 8.8 is unallocated. The result is less than the result when you calculate the memory cost.

The results show that the cost allocated by using the single resource (memory) cost estimation policy is higher than that allocated by using the weighted resource cost estimation policy. However, the CPU watermark is close to the memory watermark because the CPU request is close to the memory request. This indicates that the CPU cost of the cluster is close to the memory cost of the cluster. Therefore, the weighted resource cost estimation policy is suitable for scenarios where applications in the cluster use both types of resources.

image

FAQ

How do I reduce the amount of unallocated cost when I use the weighted resource cost estimation policy to allocate the cost of the cluster?

Cause: When you use the weighted resource cost estimation policy to allocate the cost of the cluster, a specific amount of the cost may be unallocated. This is because the watermark of the resource that is intensively used by the cluster is much higher than the watermarks of other resources. If the watermark of the intensively used resource reaches a bottleneck, idle resources of the other type exist. For example, if the CPU watermark of the cluster is much higher than the memory watermark of the cluster, idle memory resources exist. In this case, if you use the single resource cost estimation policy to allocate the cost of the cluster, the cost of idle resources can also be allocated. If you use the weighted resource cost estimation policy to allocate the cost of the cluster, the cost of idle resources cannot be allocated.

Solution: Select proper Elastic Compute Service (ECS) instance types based on the resource requests of your workloads to ensure that the CPU watermark of the cluster is close to the memory watermark. Alternatively, you can use the single resource cost estimation policy to allocate the cost of the cluster.

References