You can call the Allocation API to query the cost allocation data of a cluster, which you can use for accounting during the financial governance cycle.
Prerequisites
The prerequisites described in the Overview of calling an API to query cost data topic are met.
Request and response parameters
Request syntax
GET /v2/allocation
Request parameters
Parameter | Type | Required | Description |
window | string | Yes | The time range to be queried. The output of cost insights data must be used with the billing data of cloud services. The minimum time range to be queried is 24 hours. The following formats are accepted:
|
filter | string | No | The filter options for workloads. The following types of filter options are supported:
You can specify multiple filter options of the same type. Separate filter options with commas (,). Example: You can also specify multiple types of filter options. Separate different types of filter options with plus signs ( |
step | string | No | The interval that is used to split the time range. The step parameter specifies the interval of a cost set. Example: 1d or 1w. The default value is the value of the Note A cost set includes the cost data of a Kubernetes object, such as a pod, within the interval. |
aggregate | string | No | The aggregate options for the returned results from different dimensions. The following types of aggregate options are supported:
|
format | string | No | The format of the queried costs. The following types of format options are supported:
|
Response parameters
Parameter | Type | Description |
properties | object | The properties of the associated Kubernetes object. |
pod | string | The name of the pod. |
namespace | string | The namespace. |
controllerKind | string | The type of the controller. |
controller | string | The name of the controller. |
start | string | The start time of the cost set. |
end | string | The end time of the cost set. |
cpuCoreRequestAverage | float | The average number of vCPUs requested. |
cpuCoreUsageAverage | float | The average number of vCPUs in use. |
ramByteRequestAverage | float | The average amount of memory requested. |
ramByteUsageAverage | float | The average amount of memory in use. |
cost | float | The cost allocated to the service from the total cluster cost. |
costRatio | float | The ratio of the allocated cost to the total cluster cost. |
customCost | float | The custom cost. |
Query cost insights data
In this section, curl is used to access the Kubernetes API. For more information, see Use the Kubernetes API.
Example: Query the cost allocated to a DaemonSet from the total cluster cost of the previous day
Command
curl -G -k --cert ./client-cert.pem --key ./client-key.pem \
-d 'window=yesterday' \
-d 'filter=namespace:"kube-system"+controllerKind:"DaemonSet"+label[app]:"terway-eniip"' \
"$APISERVER/api/v1/namespaces/kube-system/services/ack-metrics-adapter-api-service:8080/proxy/v2/allocation" | jq .