All Products
Search
Document Center

Container Service for Kubernetes:Use the cost insights feature provided by ACK to manage and optimize costs

Last Updated:Jul 10, 2024

This topic describes how to use the cost insights feature to accurately calculate the IT spending in a cloud-native architecture based on the actual business status of an enterprise. The cost insights feature enables enterprises to benefit from the flexibility and high performance of cloud-native technologies and efficiently manage and control costs.

Prerequisites

Background information

In traditional IT governance scenarios, an application usually has exclusive access to a set of cloud resources, such as nodes, Server Load Balancer (SLB) instances, and storage resources. Cost tracking is more straightforward and simple because these cloud resources are billed separately.

In the cloud-native era, resources are consumed in a different mode. A node may simultaneously run containers for different applications, and the network and storage resources of the nodes may be shared by these applications. The resource-sharing mode increases the complexity of cost allocation, which means that costs cannot be explicitly allocated to each business unit. As a result, cost insights and management become complicated.

ACK provides a general-purpose cost data model to help you accurately calculate business costs. The following content shows how the cost insights feature works.

  1. First, analyze the resources used by each pod to estimate the cost of each pod. The resources include CPU, memory, and storage resources.

  2. Then, proportionally allocate the total cost of the cluster, including the costs of all resources, to each pod based on the estimated cost. You can obtain the cluster cost per pod by proportionally allocating the total cost of the cluster.

  3. Finally, you can obtain the cost of a business unit by summing up the costs of all pods associated with the business unit within a cost governance cycle.

Scenarios

The following figure shows that an enterprise deploys its applications in an ACK cluster. The enterprise has four departments: Department A is responsible for Application A, Department B and Department C are responsible for Application B, and Department D is responsible for Application C and Application D.

image

Application A and Application B are scheduled to subscription Elastic Compute Service (ECS) instances because these applications provide web services to handle stable traffic loads. Application C and Application D are scheduled to pay-as-you-go ECS instances because these applications require elastic resources to process and analyze business data.

Use the cost insights feature to manage and optimize costs

The following content shows how to use the cost insights dashboard to view the costs of departments and applications.

Note

You can also call the HTTP API to query the costs of departments and applications. For more information, see Call the Allocation API to query cost insights data.

Step 1: Determine the cost governance cycle

  • Determine the cluster cost governance cycle:

    ECS instances support two billing cycles. Subscription instances are billed on a monthly or weekly basis. Pay-as-you-go instances are billed on an hourly basis. In this topic, the cluster contains subscription ECS instances and pay-as-you-go ECS instances. To view the total cost of the cluster, you need to set the cost governance cycle to monthly. To better compare and analyze billing data, the ECS billing dates are used as the start and end dates of cost governance.

  • Determine the department or application cost governance cycle:

    • Departments A, B, and C run their services on subscription ECS instances. To view the costs of these departments, you need to set the cost governance cycle to monthly.

    • Department D runs services on pay-as-you-go ECS instances. To view the cost of the department, you need to set the cost governance cycle to daily.

    • To view the application cost, you can determine the cost governance cycle based on the department to which an application belongs.

Step 2: Determine the cost allocation policy based on the business type

When you calculate business costs, you need to estimate the costs of the pods associated with the business. ACK provides two cost estimation policies: single resource cost estimation and weighted resource cost estimation.

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.

By default, the single resource cost estimation policy is suitable for scenarios where most applications in the cluster use only one type of resource. If the applications in your cluster use only CPU resources, you can select the single resource cost estimation policy.

For more information about how to select cost estimation policies in different scenarios, see Cost estimation policies.

Step 3: View the cluster cost

  1. Log on to the ACK console. In the left-side navigation pane, click Clusters.

  2. On the Clusters page, find the cluster that you want to manage and click its name. In the left-side pane, choose Cost Suite > Cost Insights.

  3. On the Cluster Dimension tab of Cost Insights page, set the following filter conditions to view the cluster cost.

    1. Actual/original bill: Select a method to calculate the cluster cost. In this example, Actual Billing cost with discount is selected.

    2. Time range: In this example, set the time range to 2024-05-01 00:00:00 to 2024-05-31 23:59:59.

    In the Cumulative Expenses for the Month - Actual Billing cost with discount section, view the total cost of the cluster in May 2024.查看

Step 4: View the department cost

  1. On the Cost Insights page, click the Namespace Dimension tab and configure the following filter conditions to view the namespace cost.

    • Namespace (Namespace): Select the namespace used by your apartment. In this example, the default namespace is selected.

    • Actual/original bill: Select a method to calculate the cost of the namespace. In this example, Actual Billing cost with discount is selected.

    • Time range: In this example, set the time range to 2024-05-31 00:00:00 to 2024-05-31 23:59:59.

      Department D in this example has a fluctuating resource demand. You can also specify a day, such as 2024-05-31, to view the daily cost of Department D.

    In the Namespace Charges - Actual Billing cost with discount section, you can view the cost of the department.

    image.png

Step 5: View the application cost

  1. On the Cost Insights page, click the Application Dimension tab and set the following filter conditions to view the application cost.

    • Namespace (Namespace): Select the namespace of your application. In this example, the default namespace is selected.

    • Label Pair Filter (LabelSelector): Specify an application label.

    • Time range: In this example, set the time range to 2024-05-31 10:00 to 2024-05-31 16:59.

      The daily costs of Applications C and D in this example fluctuate due to business requirements. Therefore, you need to specify a time period on a day, such as 10:00 to 16:59 on May 31, 2024, to view the costs within the specified time period.

    In the Application Cost section, you can view the application cost.

    image.png

FAQ

Why am I unable to find the cost data of the previous month or week after I enable the cost insights feature?

The cost insights feature records data after you enable the feature. If the feature is not enabled within the specified time range, no data is displayed.

Why is the displayed historical cost lower than the actual cost?

By default, Managed Service for Prometheus stores data for 15 days. Make sure that the specified time range falls within the retention period of Managed Service for Prometheus. Otherwise, the historical cost may be lower than the actual cost. If you want to store data for more than 15 days, see How do I change the storage duration of the data samples for a metric?

References

  • In addition to the cost insights dashboard, you can also use the HTTP API to view the costs of departments and applications. You can call the Allocation API to aggregate cost insights data by namespace, controller, label, or pod. For more information, see Call the Allocation API to query cost insights data.

  • For more information about the cost insights metrics, see Cluster cost analysis, Namespace cost analysis, Node pool cost analysis, and Application cost analysis.

  • If you want to simplify the configuration of resource requests and limits for containers, you can use resource profiling to obtain resource configuration suggestions for individual containers. This helps you adjust the application resource configuration. For more information, see Resource profiling.

  • In multi-cloud and hybrid cloud scenarios, resources from different cloud vendors or even in on-premises environments are used. Resource monitoring and cost management through a unified view in these scenarios become challenging. For more information about how to use Distributed Cloud Container Platform for Kubernetes (ACK One) to manage hybrid cloud costs, see Cluster cost insights.