All Products
Search
Document Center

Container Service for Kubernetes:Cluster cost insights

Last Updated:Aug 14, 2023

This topic introduces the cost insights feature and describes how to view the results provided by cost insights.

Table of contents

Prerequisites

  • The Kubernetes version of your cluster is 1.18.8 or later. If the Kubernetes version of your cluster is earlier than 1.18.8, update the Kubernetes version. For more information, see Update an ACK cluster.

  • Managed Service for Prometheus is enabled. For more information, see Enable Managed Service for Prometheus.

Enable cost insights

Step 1: Grant RAM permissions to the cost insights component

Use onectl

  1. Install onectl on your on-premises machine. For more information, see Use onectl to manage registered clusters.

  2. Run the following command to grant Resource Access Management (RAM) permissions to the cost insights component:

    onectl ram-user grant --addon ack-cost-exporter

    Expected output:

    Ram policy ack-one-registered-cluster-policy-ack-cost-exporter granted to ram user ack-one-user-ce313528c3 successfully.

Use the console

  1. Create a RAM user. For more information, see Create a RAM user.

  2. Create a custom policy For more information, see Create a custom policy. The following content shows the RAM policy on which ack-cost-exporter relies when accessing cloud services.

    Show sample code

    {
        "Version": "1",
        "Statement": [
            {
                "Action": [
                    "bssapi:QueryInstanceBill",
                    "bssapi:DescribeInstanceBill"
                ],
                "Resource": "*",
                "Effect": "Allow"
            },
            {
                "Action": [
                    "ecs:DescribeDisks",
                    "ecs:DescribeSpotPriceHistory",
                    "ecs:DescribeInstances",
                    "ecs:DescribePrice"
                ],
                "Resource": "*",
                "Effect": "Allow"
            },
            {
                "Action": "eci: DescribeContainerGroupPrice",
                "Resource": "*",
                "Effect": "Allow"
            }
        ]
    }
  3. Attach the custom policy to the RAM user. For more information, see Create a RAM user and grant permissions to the RAM user.

  4. Create an AccessKey pair for a RAM user. For more information, see Create AccessKey pairs.

  5. Use the AccessKey pair to create a Secret named alibaba-addon-secret in the registered cluster. Run the following command to create the alibaba-addon-secret Secret for ack-cost-exporter:

    kubectl -n kube-system create secret generic alibaba-addon-secret --from-literal='access-key-id=<your AccessKey ID>' --from-literal='access-key-secret=<your AccessKey Secret>'

Step 2: Install ack-cost-exporter

Use onectl

Run the following command to install ack-cost-exporter:

onectl addon install ack-cost-exporter

Expected output:

Addon ack-cost-exporter, version **** installed.

Use the console

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

  2. On the Clusters page, click the name of the cluster that you want to manage and choose Applications > Helm in the left-side navigation pane.

    If the ack-cost-exporter release is displayed on the Helm page, delete the release and then perform the following steps to install ack-cost-exporter again.

  3. In the left-side navigation pane of the cluster details page, choose Operations > Add-ons.

  4. On the Add-ons page, click the Logs and Monitoring tab, find the ack-cost-exporter component, and then click Install. Then, click OK.

Usage notes

  • After the cost insights feature is enabled, billing data is displayed at 08:00:00 (UTC+8) on the next day.

  • You can click the drop-down list in the upper-right corner of a dashboard to change the time range of cost insights.

Cluster cost analysis

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

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

  3. On the Cost Insights page, click the Cluster Dimension tab to view the cluster dashboard.

    image..png

    Feature

    Number

    Description

    Cluster cost analysis options

    (1)

    The following cluster cost analysis options are available:

    • Actual Billing cost with discount: This option is selected by default. To view the payment amount of the cloud resources in the cluster, select this option.

    • Original Billing cost without discount: To view the bill amount of the cloud resources calculated based on the list prices of these resources on the Alibaba Cloud International site, select this option.

    For more information about the payment amount and list prices, see Bill details.

    Note

    The costs of applications in the cluster can be analyzed by namespace or pod. The application cost is calculated based on the bill amount of the resources.

    Cost allocation models

    (2)

    Cost allocation models include the single resource cost allocation model and the weighted hybrid resource cost allocation model. These models can help you allocate costs in the following ways:

    • CPU model: Estimate the cost of a pod based on the amount of CPU resources requested by the pod. This option is selected by default.

    • Memory Model: Estimate the cost of a pod based on the amount of memory resources requested by the pod.

    • CPU-Memory Hybrid Model (recommended weights): Estimate the cost of a pod based on the recommended CPU weight and memory weight of the pod.

    • CPU-Memory Hybrid Model (Custom Weights): Estimate the cost of a pod based on the custom CPU weight and memory weight of the pod. After you select CPU-Memory Hybrid Model (Custom Weights), you need to specify the CPU weight.

    For more information about how to select a proper cost allocation model, see Cost allocation model overview.

    Time range

    (3)

    The time range of the data displayed in the dashboard. The default time range is the last 7 days. You can specify a time range to view the changes in costs and resources within the specified time period.

    The cost of the previous day, the cumulative cost of the week, and the cumulative cost of the month.

    (4)

    The cost of the previous day, the day-on-day ratio, the cumulative cost of the week, and the cumulative cost of the month are all calculated based on the bill amount of the cloud resources in the cluster.

    The weekly cumulative cost is calculated based on the bill amount of every calendar week and the monthly cumulative cost is calculated based on the bill amount of every calendar month. Bills are generated one day after the transaction date. Therefore, the cumulative cost of the week is zero on Monday of each week and the cumulative cost of the month is zero on the first day of each month.

    The day-on-day ratio is the ratio of the cost of the previous day to the cost of the day before the previous day.

    • If the day-on-day growth rate is in green, it indicates that the cost of the previous day is reduced compared with the cost of the day before the previous day.

    • If the day-on-day growth rate is in red, it indicates that the cost of the previous day is increased compared with the cost of the day before the previous day.

    Brief information about the cluster cost and resource waste.

    (5)

    The charts display changes in the cluster cost and cluster capacity. The yellow curve indicates the cluster cost and the blue curve indicates the actual cluster capacity. In most cases, the two curves are correlated with each other.

    If the two curves represent different trends, it indicates changes in the average cost of individual CPU cores. In this case, you can check whether resources of higher prices are consumed.

    成本分摊

    Feature

    Number

    Description

    Display the costs of different namespaces.

    (6) and (10)

    Section 6 displays the costs of resources requested by different namespaces in the cluster in a pie chart. The Idle slice displays the cost ratio of idle resources in the cluster. Section 10 displays the costs of resources requested by different namespaces in the cluster in a histogram chart.

    Note
    • The costs of namespaces are calculated based on the bill amount.

    • If no resource (CPU) request is configured for the pods in a namespace, no cluster resource is requested by the namespace. In this case, the namespace is not taken into account during namespace cost calculation.

    A cluster may contain nodes of different specifications and billing methods. When you allocate the cost based on namespaces, you must consider the price differences of nodes that host pods in different namespaces, not only the resource consumption of different namespaces.

    The cost insights feature converts the real-time cost of each node. The cost insights feature provides the following formula to calculate the cost of a namespace:

    Σ (Pod resource request/Node capacity) × Node unit price

    The formula can help you precisely calculate the cost of a namespace. However, due to the deferred billing policy applied when discounts, vouchers, or the subscription billing method is used, the cost calculated based on this formula may differ from the bill amount. To calculate the actual cost of a namespace, you can multiply the amount on the cluster bill by the cost ratio of the namespace.

    Display changes in the total cluster cost

    (8)

    Display daily changes in the total cluster cost.

    Display changes in the cloud resource cost and the cost ratios of different cloud resources

    (7) and (9)

    Section 7 displays the cost ratios of different cloud resources in the cluster. Section 9 displays changes in the cloud resource cost.

    A cluster may use multiple cloud resources. The costs of cloud resources vary based on billing rules and how the cloud resources are used by the cluster. The cost insights feature displays the changes in the cloud resource cost and the cost ratios of different cloud resources to help you reduce the cost of the cluster.

    Display the costs of node pools

    (11)

    Display the cost of each node pool in the cluster or the cost of each virtual node (virsual-kubernetes).

    image..png

    Feature

    Number

    Description

    Display changes in the resource request and resource utilization of the cluster

    (12)

    Scenarios:

    • Help you analyze the resource watermarks and resource capacity of the cluster to identify resource waste.

    • When scaling activities are triggered, the resource watermarks of the cluster periodically fluctuate. You can determine the resource capacity of the cluster based on the changes in the histogram chart.

    Histogram chart:

    • Y-axis: 100% indicates the total resource capacity of the cluster, which is the total amount of resources that can be allocated to applications in the cluster.

    • Green column: indicates the requested resources within the current hour.

    • Yellow column: indicates the actual resource usage of the processes in the pods within the current hour.

    Resources that are allocated to applications but are not in use = Green column - Yellow column

    Allocatable cluster resources = Y-axis - Green column

    Analysis procedure:

    1. Avoid wasting unallocated resources: You can utilize unallocated resources in the cluster by modifying the resource request of pods or downgrading the instances that host the pods. We recommend that you keep about 20% of the cluster resources unallocated.

    2. Avoid wasting allocated but unused resources: You can identify applications that are allocated an excessive amount of resources based on the statistics about allocated but unused resources and the applications or pods that waste the most resources in the namespace dashboard. Then, you can modify the resource request accordingly.

    3. Scale resources: When your businesses periodically fluctuate, you can reference the changes of resource watermarks in the histogram chart to resize resources in the cluster and configure an appropriate scaling policy.

    List of daily bills

    (13)

    A list of daily bills displayed by cloud resource or instance.

Use cost insights to analyze the costs of on-premises servers and applications that run on the servers

You can use cost insights to analyze the costs of on-premises servers in registered clusters and applications that run on these servers. By default, the cost insights feature calculates the costs of on-premises servers in registered clusters and applications that run on the servers at a CPU unit price of CNY 0.2/vCore hour. The following section describes how to set a custom unit price.

  • Set a CPU unit price for all on-premises servers

    Add the DefaultIDCPricePerCPUCoreHour environment variable to the ack-cost-exporter Deployment in the kube-system namespace to specify a CPU unit price for all on-premises servers.

    Note

    The unit of the price is CNY/vCore hour.

    env:
    # Set the CPU unit price to CNY 0.3/vCore hour. 
    - name: DefaultIDCPricePerCPUCoreHour
      value: "0.3"
  • Set a unit price for a node

    Add the "node.kubernetes.io/price-per-day" label to a node to specify a unit price for the node.

    Note

    The unit of the price is CNY/day.

    Run the following command to set the unit price of the node to CNY 100/day.

    kubectl label nodes <node-name> node.kubernetes.io/price-per-day="100"

FAQ

Why is no data displayed after I enable cost analysis?

Check whether you have completed RAM role authorization. For more information, see Step 3 in the Enable cost insights topic. Cost analysis is based on monitoring data and cost data. The collection of monitoring data starts within 3 minutes after you enable the cost insights feature. Cost data is displayed at 08:00:00 (UTC+8) on the next day. The data of the Day-on-day Ratio and Estimated Cost of Next Day metrics is displayed after the cost insights feature collects statistics for two consecutive days.

Why does the cost of a namespace differ from the actual bill amount?

The cost of a namespace is calculated based on cost estimation and is not directly related to the actual bill amount. Therefore, the cost estimation is based on the list prices. However, the actual cost of a cluster can be reduced by vouchers, discounts, and cost savings plans. As a result, the estimated cost of a namespace may not equal the bill amount. To obtain the actual cost of a namespace, you can multiply the actual cost of the cluster by the cost ratio of the namespace.

Why do I fail to obtain the cost data of pods on some nodes?

Check whether the RAM role is granted the required permissions. Make sure that the ecs:DescribeDisks permission is included in the permission policy. For more information, see Step 3 in the Enable cost insights topic.

Why does the bill not display all cloud services used by my cluster?

Cost analysis only collects information about cloud services that are exclusive to your cluster. Information about cloud services that are shared by multiple clusters is not collected. The cost insights feature uses the tag whose key is ack.aliyun.com and whose value is {{ClusterId}} in Billing Management to collect information about cloud services. ClusterId indicates the ID of the cluster whose information you want to collect. If you disable this tag on the Cost allocation tags page of the Billing Management console, the cluster cost information cannot be collected. In this case, you must follow the instructions on the Cost allocation tags page of the Billing Management console to enable the tag whose key is ack.aliyun.com and the tag whose key is ack.alibabacloud.com/nodepool-id.

Why is the monthly or weekly spending lower than the actual amount?

The cost data of a cluster before you enable the cost insights feature is not analyzed when the cost insights feature calculates the cluster cost.