All Products
Search
Document Center

Container Service for Kubernetes:Cost allocation model overview

Last Updated:May 31, 2023

The cost insights feature of Container Service for Kubernetes (ACK) allows enterprises to allocate costs from various dimensions. For example, enterprises can allocate costs by department or application. The key to successful cost allocation is to calculate the cost of pods. The cost insights feature supports the following cost allocation models: single resource cost allocation and weighted hybrid resource cost allocation. This topic describes how the two cost allocation models work and the use scenarios of the models. It also provides examples on how to use these models.

Table of contents

Comparison between the resource allocation models

Model

Description

Single resource cost allocation model

You can use this model to allocate costs by CPU or memory.

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

Weighted hybrid resource cost allocation model

You can use this model to allocate costs by recommended weights or custom weights.

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

Single resource cost allocation model

The single resource cost allocation model is the default cost allocation model of ACK. This model best suits resource watermarks.

How it works

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

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

    image..png
  • A namespace is an aggregation of pods that have the same attributes. After you obtain the cost ratio of each pod in the cluster, you can calculate the fees of a namespace by using the following formula: Fees of a namespace = Sum of the cost ratio of each pod in the namespace × Total amount of all payments 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:

      image..png

Use scenarios

The resource watermark refers to the ratio of the amount of the requested resource to the total amount of resources. In most cases, the resource watermark of a cluster depends on the most requested resource type. Therefore, the single resource cost allocation model is suitable for scenarios where the CPU or memory watermark of the cluster is 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 availability determines whether the applications in the cluster can be scheduled. The single resource cost allocation model is suitable for this case. 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.

Weighted hybrid resource cost allocation model

How it works

The weighted hybrid resource cost allocation model calculates the CPU and memory costs of a pod. The CPU weight and the memory weight are determined by the CPU watermark and the memory watermark of the cluster.

  • Unlike the single resource cost allocation model, the weighted hybrid resource cost allocation model calculates the cost of a pod based on the CPU weight and the memory weight of the pod. This model 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

Use scenarios

The weighted hybrid resource cost allocation model is suitable for scenarios where applications in the cluster use both types of resource. This model is also suitable for scenarios where the CPU watermark of the cluster is close to the memory watermark. 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.

Examples

The following examples show how to choose suitable cost allocation models for 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 of the cluster is 20%. Assume that the daily cost of the cluster is CNY 200.

  • Single resource cost allocation model:

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

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

  • Weighted hybrid resource cost allocation model:

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

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

image..png

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

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 of the cluster is 50%. Assume that the daily cost of the cluster is CNY 200.

  • Single resource cost allocation model:

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

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

  • Weighted hybrid resource cost allocation model:

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

The results show that the cost allocated by using the single resource (memory) cost allocation model is higher than that allocated by using the weighted hybrid resource cost allocation model. 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. The weighted hybrid resource cost allocation model is suitable for scenarios where applications in the cluster use both types of resource.

image..png

How do I reduce the amount of unallocated cost when I use the weighted hybrid resource cost allocation model to allocate the cost of the cluster?

Cause: When you use the weighted hybrid resource cost allocation model 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 watermark of other resource. 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 allocation model to allocate the cost of the cluster, the cost of idle resources can also be allocated. However, the cost of idle resources cannot be allocated if you use the weighted hybrid resource cost allocation model to allocate the cost of the cluster.

Solution:: Select suitable 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. To resolve this issue, you can also use the single resource cost allocation model to allocate the cost of the cluster.