Use the Cost API to query estimated real-time cost and resource usage data for pods or namespaces in an ACK cluster.
Prerequisites
Before you begin, ensure that you have:
-
Completed all prerequisites in Overview of calling an API to query cost data, including deploying the
ack-metrics-adaptercomponent and connecting to your cluster -
kubectlinstalled and configured with access to your cluster
Supported query dimensions
The Cost API supports the following query dimensions:
-
Pod — query by individual pod, multiple pods, or pods filtered by label
-
Namespace — query by individual namespace or all namespaces
Use DimensionType and Dimension together to target a specific scope. Add LabelSelector to filter by label across either dimension. LabelSelector and DimensionType are combined with AND logic.
Parameters
All examples use kubectl get --raw against the following endpoint:
/api/v1/namespaces/kube-system/services/ack-metrics-adapter-api-service:8080/proxy/cost
Append query parameters to this endpoint to filter results.
| Parameter | Description | Default | Valid values |
|---|---|---|---|
DimensionType |
The dimension for querying cost data | Pod (all pods) |
Namespace, Pod |
Dimension |
Filters results to a specific namespace or pod. Omit to return all. To query multiple pods, use comma-separated values: pod=<name1>,pod=<name2> |
All | A namespace name or pod name |
LabelSelector |
Filters pods by app label |
— | app=<label-value> |
TimeUnit |
The time range of cost data to return | hour |
hour, day, week, month |
Summary |
When set to true, returns aggregated cost data for all matching pods instead of per-pod data |
false |
true, false |
Cost data metrics
Each response entry includes the following cost metrics:
| Field | Unit | Description |
|---|---|---|
cpu |
vCores | CPU usage |
gpu |
Count | GPU count |
memory |
KB | Memory usage |
perCorePricing |
$ (International site) | Unit price of vCores on the node hosting the pod or application |
costRatio |
— | Ratio of this pod or application's cost to the total cluster cost. For example, 0.2 means 20% of total cluster cost |
cost |
$ (International site) | Total cost of the pod or application within the queried time range |
customCost |
— | Custom cost of the pod or application within the queried time range |
Each entry also includes request, usage, and limit sub-fields for cpu, memory, gpu, and gpuMem:
| Sub-field | Description |
|---|---|
request |
The resource amount requested by the pod |
usage |
The actual resource consumption of the pod |
limit |
The resource limit configured for the pod |
Examples
Example 1: Query all pods in the cluster for the previous hour
kubectl get --raw "/api/v1/namespaces/kube-system/services/ack-metrics-adapter-api-service:8080/proxy/cost"
Example 2: Query all pods in a namespace for the previous hour
Replace default with the target namespace name.
kubectl get --raw "/api/v1/namespaces/kube-system/services/ack-metrics-adapter-api-service:8080/proxy/cost?DimensionType=Namespace&Dimension=default" | jq .
Example 3: Query a specific pod for the previous hour
Replace the pod name with the actual value.
kubectl get --raw "/api/v1/namespaces/kube-system/services/ack-metrics-adapter-api-service:8080/proxy/cost?DimensionType=Pod&Dimension=pod=nginx-deployment-basic-75d6678cbb-lg8v5" | jq .
Example 4: Query pods by label
The following command queries all pods with the app=nginx label for the previous hour. Replace the label value with the actual value.
LabelSelectorandDimensionTypeare combined with AND logic. OmittingDimensionTypequeries across all pods that match the label.
kubectl get --raw "/api/v1/namespaces/kube-system/services/ack-metrics-adapter-api-service:8080/proxy/cost?LabelSelector=app=nginx" | jq .
Example 5: Query a pod's cost for the previous day
Replace the pod name with the actual value.
kubectl get --raw "/api/v1/namespaces/kube-system/services/ack-metrics-adapter-api-service:8080/proxy/cost?DimensionType=Pod&Dimension=pod=nginx-deployment-basic-75d6678cbb-lg8v5&TimeUnit=day" | jq .
Example 6: Query aggregated cost for a namespace
Set Summary=true to get a single aggregated entry for all pods in the namespace instead of per-pod results. Replace default with the target namespace name.
kubectl get --raw "/api/v1/namespaces/kube-system/services/ack-metrics-adapter-api-service:8080/proxy/cost?DimensionType=Namespace&Dimension=default&Summary=true" | jq .
What's next
-
For more flexible time range queries and additional dimensions (controller, controller kind), see Call the Cost V2 API to query cost data.
-
To allocate business costs based on billing data for accounting purposes, see Call the Allocation API to query cost insights data.