Enable cost insights

更新时间:
复制 MD 格式

Analyze resource usage and allocate costs by namespace, node pool, and application in ACK clusters.

Cost dimensions

You can analyze costs by:

  • Cluster

  • Namespace

  • Node pool

  • Application (Deployment, StatefulSet, DaemonSet, Job, CronJob)

Prerequisites

Make sure that you have:

Billing

Cost insights metrics

Cost insights generates metrics from billing data and resource pricing, then reports them to Prometheus. Changing default settings such as storage retention periods may incur additional costs.

Cost allocation tags

Cost allocation tags filter billing data and correlate it with node pool analytics. Configure them before you enable cost insights:

  1. Go to the Expenses and Costs console.

  2. On the Cost allocation tags page, select tags from the left panel, move them to Selected Tags, and click Enable.

  3. Enable these tags:

    • ack.aliyun.com

    • ack.alibabacloud.com/nodepool-id

Enable cost insights

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

  2. On the Clusters page, click the name of your cluster. In the left navigation pane, click Cost Suite > Cost Insights.

  3. Authorize your cluster to access billing data.

    Authorization differs by cluster type:

    1. Grant billing data access

      • ACK managed clusters

        The system automatically creates the AliyunCSManagedCostRole RAM role. Prometheus assumes this role to access your billing data.

        Or authorize from the RAM Quick Authorization page.

      • ACK dedicated clusters

        Add billing permissions to the worker role policy:

        View the authorization steps

        1. On the Cost Insights page, click KubernetesWorkerRole-***.

        2. On the Permissions tab, click k8sWorkerRole**** in the Policy column.

        3. On the Policy Document tab, click Edit Policy Document.

        4. Add these statements to the Statement array, then click OK.

          {
              "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"
          }
          Note

          Separate each statement with a comma when adding multiple entries.

    2. Install ack-cost-exporter by following the on-screen instructions.

      The page redirects to Cost Insights after installation.

Disable cost insights

To stop cost metric collection, uninstall ack-cost-exporter:

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

  2. On the Clusters page, click the name of your cluster. In the left navigation pane, click Components and Add-ons.

  3. On the Add-ons page, find ack-cost-exporter and click Uninstall. In the confirmation dialog, click OK.

FAQ

What do I do if ack-cost-exporter fails to install or uninstall?

Delete leftover resources manually, then retry:

# Delete the Deployment and Services
kubectl delete deployment ack-cost-exporter -n kube-system
kubectl delete service alibaba-cloud-price-exporter -n kube-system
kubectl delete service alibaba-cloud-billing-exporter -n kube-system
kubectl delete service alibaba-cloud-cost-exporter -n kube-system

# Delete ServiceMonitors
kubectl delete ServiceMonitor alibaba-cloud-price-exporter -n kube-system
kubectl delete ServiceMonitor alibaba-cloud-billing-exporter -n kube-system
kubectl delete ServiceMonitor alibaba-cloud-cost-exporter -n kube-system

# Delete RBAC resources
kubectl delete ClusterRoleBinding ack-cost-exporter-cluster-role-binding
kubectl delete ClusterRoleBinding ack-cost-exporter-cluster-role-binding-v1
kubectl delete ServiceAccount ack-cost-exporter -n kube-system
kubectl delete ClusterRole ack-cost-exporter-cluster-role

If installation failed, reinstall ack-cost-exporter after cleanup. See Manage components.