The cost insights feature of Container Service for Kubernetes (ACK) tracks cluster resource usage and cost distribution across multiple dimensions. Cost data is reported to and stored in Managed Service for Prometheus. Call HTTP APIs to query this data for cost optimization analysis or to integrate it into your own tooling.
ACK provides three APIs for querying cost data:
-
Cost API (old version) — queries the real-time estimated cost and resource usage of a pod.
-
Cost V2 API — compatible with the Cost API, and supports time range filtering and workload filtering by pod name, namespace, label, controller, or controller type. Use this to analyze real-time cost trends.
-
Allocation API — allocates the payment amounts in cluster bills to individual workloads. The response has the same data structure as the Cost V2 API. Use this for cost allocation and chargeback reporting.
Prerequisites
Before you begin, ensure that you have:
-
Enabled the cost insights feature
-
Enabled Managed Service for Prometheus
-
Installed and configured alibaba-cloud-metrics-adapter
-
Connected to your cluster using one of the following methods:
-
Downloaded a JSON processing tool. The examples in this topic use jq.
Authorization for non-owner users
If you are not the cluster owner but are authorized by the owner to manage the cluster, ack-metrics-adapter-api-service may not have the required permissions. Grant role-based access control (RBAC) permissions to the user or user group in the credentials used in requests to the API server.
To grant RBAC permissions:
-
Log on to the ACK console. In the left-side navigation pane, click Clusters.
-
On the Clusters page, find the cluster and click its name. In the left-side pane, choose Security > Role.
-
On the Role tab, click Edit YAML in the Actions column of arms-pilot-prom-spec-ns-k8s.
-
In the View in YAML panel, modify the rules parameter based on the following content and click OK.
- apiGroups: - '' resources: - services verbs: - get
Available APIs
| API | Use case | Description |
|---|---|---|
| Cost API | Existing integrations | Queries the real-time estimated cost and resource usage of a pod. Old version — use Cost V2 API for new integrations. |
| Cost V2 API | Real-time cost monitoring and trend analysis | Queries real-time estimated cost. Supports time range filtering and workload filtering by pod name, namespace, label, controller, or controller type. Compatible with the Cost API. |
| Allocation API | Cost allocation and chargeback | Allocates payment amounts from cluster bills to individual workloads. Returns the same data structure as the Cost V2 API. |
What's next
-
Analyze cluster resource efficiency using the resource profiling and idle resource optimization features. See Cost optimization.
-
After implementing cost optimization strategies, use the cost control feature to manage the cost governance lifecycle. See Cost control.