This topic introduces the cost insights feature and describes how to view the results provided by cost insights.
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
Enable cost insights for a cluster within the account
Step 1: Grant RAM permissions to the cost insights component
Use onectl
Install onectl on your on-premises machine. For more information, see Use onectl to manage registered clusters.
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
Create a RAM user. For more information, see Create a RAM user.
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.
Attach the custom policy to the RAM user. For more information, see Create a RAM user and grant permissions to the RAM user.
Create an AccessKey pair for a RAM user. For more information, see Create AccessKey pairs.
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
Log on to the ACK console. In the left-side navigation pane, click Clusters.
On the Clusters page, click the name of the cluster that you want to manage and choose 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.
In the left-side navigation pane of the cluster details page, choose .
On the Add-ons page, click the Logs and Monitoring tab, find the ack-cost-exporter component, and then click Install. Then, click OK.
Enable cost insights for a cluster across accounts
When you use the registered cluster from account A to manage the ACK cluster under account B, you must authorize the cost insights feature in the ACK cluster of account B. This authorization allows the feature to access the billing data of account B.
Step 1: Configure RAM permissions for account B
Log on to the ACK console. In the left-side navigation pane, click Clusters.
On the Clusters page, find the cluster that you want to manage and click its name. In the left-side pane, choose .
Authorize your ACK cluster to access your bills in User Center.
If you use an ACK managed cluster, the system automatically grants the required permissions. After the authorization is complete, the system automatically creates the AliyunCSManagedCostRole role. Managed Service for Prometheus assumes the RAM role to access your billing data in Expenses and Costs.
You can also click the Cloud Resource Access Authorization hyperlink. On the Cloud Resource Access Authorization page, click Agree to Authorization.
NoteThe ACK cluster in account B does not require the ack-arms-prometheus component to be installed. If it is installed, uninstall it first. For more information, see Manage components.
Step 2: Install the components for account A
Install ack-arms-prometheus in account A, where the registered cluster is located. For more information, see Enable Managed Service for Prometheus for a registered cluster.
Configure the ack-cost-exporter component in account A by setting the
AckRegisteredClusterId
parameter to theclusterId
of the ACK cluster in account B.Log on to the ACK console. In the left-side navigation pane, click Clusters.
On the Clusters page, click the name of the cluster that you want to manage and choose 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.
In the left-side navigation pane of the cluster details page, choose .
On the Add-ons page, click the Logs and Monitoring tab, find the ack-cost-exporter component, and click Install in the lower-right corner.
In the Install ack-cost-exporter dialog, set registeredAckClusterId to the
clusterId
of the ACK cluster in account B, and 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
Dimensions
Feature | Number | Description |
Cluster cost analysis options | (1) | The following cluster cost analysis options are available:
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 weighted hybrid resource cost allocation model. These models can help you allocate costs in the following ways:
For more information about how to select a proper cost allocation model, see Cost estimation policies. |
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. |
Cluster cost overview
Feature | Number | Description |
View the cost allocation model | (1) | The displayed data depends on the cost allocation model that you selected. The CPU model is selected by default to estimate the cost of a pod based on the amount of CPU resources requested by the pod. |
The cost of the previous day, the cumulative cost of the week, and the cumulative cost of the month. | (2) | 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.
|
Brief information about the cluster cost and resource waste. | (3) | 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. |
Display the real-time estimated costs of namespaces and allocated cost of each namespace | (4) and (5) | Section (4) displays the real-time estimated cost of each namespace in the cluster. The cost of a namespace is the sum of costs of all pods in the namespace. Section (5) displays the allocated cost of each namespace, which is the cluster cost allocated to each namespace based on the specified cost ratio. Note
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 allocated cost of a namespace, you can multiply the total cluster cost by the cost ratio of the namespace. |
Stability and efficiency analysis
Feature | Number | Description |
Display the total resource usage of the cluster | (1) | Display the number of pods of each quality of service (QoS) class and the total resource usage in the cluster. |
Display the pod resource usage in the cluster | (2) | Display the basic information and resource usage (Usage/Request) of all pods in the cluster. Filtering and sorting are supported. You can use this feature to view the workloads with the highest or lowest resource usage in a cluster. |
Display the resource configurations of burstable pods in a cluster | (3) | Display the resource configurations of the pods whose QoS class is Burstable. Filtering and sorting are supported. This feature allows you to view the requests and limits of resources such as CPU and memory resources for each Burstable pod. This allows you to learn about the cluster resources consumed by pods and identify resource bottlenecks. |
Display the resource usage of BestEffort pods in a cluster | (4) | Display the resource configurations of the pods whose QoS class is BestEffort. This type of pod has a higher stability risk. You can filter and sort the list to check for any unexpected BestEffort pods. This allows you to address the risks at the earliest opportunity. |
For more information about the stability and efficiency analysis feature, see Use cost insights to identify risks for cluster workloads.
Cluster cost analysis
Feature | Number | Description |
Display changes in the cloud resource cost and the cost ratios of different cloud resources | (1) and (2) | Section (3) displays the cost ratios of different cloud resources in the cluster. Section (4) 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 changes in the total cluster cost | (3) | Display daily changes in the total cluster cost. |
Display the costs of node pools | (4) | Display the cost of each node pool in the cluster or the cost of each virtual node. |
Display the trends in real-time estimated costs of namespaces | (5) | 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 allocated cost of a namespace, you can multiply the total cluster cost by the cost ratio of the namespace. |
Display changes in the resource request and resource utilization of the cluster | (6) | Scenarios:
Histogram chart:
Resources that are allocated to applications but are not in use = Green column - Yellow column Allocatable cluster resources = Y-axis - Green column Analysis procedure:
|
Cluster billing details | (7) and (8) | 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.NoteThe 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.NoteThe 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.
Check whether a NAT gateway is configured for the cluster. You cannot use the internal endpoint to query bills in certain regions. Make sure that your cluster has Internet access.
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 is based on the cost allocation tags feature in the Expenses and Costs console. This feature uses a specific identifier in the cloud service tags (key: value = ack.aliyun.com:{{ClusterId}}
) to track and collect cluster cost statistics. If you disable this tag on the Cost allocation tags page of the Expenses and Costs console, the cluster cost information cannot be collected. In this case, you must follow the instructions on the Cost allocation tags page of the Expenses and Costs 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.