If you want to obtain information about resource usage and cost distribution in your clusters from multiple dimensions, you can enable the cost insights feature of Container Service for Kubernetes (ACK). After you enable this feature, cost data is reported to and stored in Managed Service for Prometheus. You can call HTTP APIs to query the cost data. ACK can provide suggestions on cost optimization based on the data. The data can also be used in further development.
Prerequisites
Components and features:
The alibaba-cloud-metrics-adapter component is installed with the
AlibabaCloudMetricsAdapter.prometheus.url
parameter is set to the endpoint of Managed Service for Prometheus. For more information, see Modify the configuration of alibaba-cloud-metrics-adapter.
One of the following methods is used to connect to your cluster:
curl is used to call HTTP APIs to query the cost data of ACK. For more information, see Use the Kubernetes API.
A data processing tool for JSON is downloaded. In this example, jq is downloaded and used to query structured cost data. For more information about how to download jq, see jq Download.
Usage notes
If you are not the owner of the cluster but you are authorized to manage the cluster by the owner, ack-metrics-adapter-api-service may not have the required permissions. When you call the Kubernetes API or HTTP API exposed by your Service to query cost insights data of ACK, you need to grant role-based access control (RBAC) permissions to the user or user group in the credentials of the request that is sent to the API server.
Methods to query cost data
Method | API | Description |
Cost API (old version): queries the estimated cost in real time. | You can call the Cost API to query the real-time estimated cost and resource usage of a pod. | |
Cost V2 API: queries the estimated cost in real time. | The Cost V2 API is compatible with the Cost API and allows you to specify a time range and filter workloads by pod name, namespace, label, controller, or controller type. You can analyze the real-time cost trend based on the returned cost data. | |
Allocation API: queries cost allocation data. | The Allocation API allocates the payment amounts in the bills of the cluster to workloads in the cluster. The data structure in the response of the Allocation API is the same as the data structure in the response of the Cost V2 API. You can use the cost allocation data for accounting. |
What to do next
ACK provides the resource profiling and idle resource optimization features. For more information, see Resource profiling and Idle resource optimization.
After you extract insights from cost data and implement cost optimization strategies, you can use the cost control feature to control the cost governance lifecycle. For more information, see Cost control.