All Products
Search
Document Center

Container Service for Kubernetes:Enable cost insights

最終更新日:Sep 10, 2024

The cost insights feature of Container Service for Kubernetes (ACK) helps the finance department analyze resource usage and allocate costs from multiple dimensions. This feature also offers suggestions on cost savings. This topic describes how to enable and disable the cost insights feature.

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

  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. Assign the AliyunCSManagedCostRole Resource Access Management (RAM) role to your cluster and install the ack-cost-exporter component.

    1. Authorize your ACK cluster to access your billing data in Billing Management

      • 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.

      • If you use an ACK dedicated cluster, perform the following steps to complete the authorization.

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

        2. On the Permissions tab of the details page of the RAM role, click k8sWorkerRole**** in the Policy column.

        3. On the Policy Document tab of the policy details page, click Modify Policy Document.

        4. In the code editor that appears, add the following content to the Statement field, click Next to edit policy information, and 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

          To specify multiple actions, add a comma (,) to the end of the content of each action before you enter the content of the next action.

    2. Install the ack-cost-exporter component

      Follow the on-screen instructions to install the ack-cost-exporter component. After the component is installed, you are automatically redirected to the Cost Insights page.

Disable cost insights

If you do not need to use the cost insights feature, you can uninstall the ack-cost-exporter component and disable the feature.

  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 navigation pane, choose Operations > Add-ons.

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

FAQ

What do I do if I fail to install or uninstall the ack-cost-exporter component?

  • If you fail to install ack-cost-exporter, run the following commands to delete the resources related to ack-cost-exporter. Then, install ack-cost-exporter again. For more information about how to install ack-cost-exporter, see Manage components.

    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
    
    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
    
    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 you fail to uninstall ack-cost-exporter, run the following commands to delete the resources related to ack-cost-exporter.

    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
    
    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
    
    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