All Products
Search
Document Center

Container Service for Kubernetes:Obtain cost data by using the Cost API

Last Updated:Mar 26, 2026

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-adapter component and connecting to your cluster

  • kubectl installed 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"

Expand to view the expected output

[
  {
    "metadata": {
      "timestamp": "2023-02-14T03:27:18Z",
      "timeUnit": "hour",
      "DimensionType": "",
      "Dimension": "",
      "PodName": "arms-springboot-demo-subcomponent-7f94c7f597-5l8tc"
    },
    "request": {
      "cpu": 0.5,
      "memory": 0,
      "gpu": 0,
      "gpuMem": 0
    },
    "usage": {
      "cpu": 0.022,
      "memory": 1538784,
      "gpu": 0,
      "gpuMem": 0
    },
    "limit": {
      "cpu": 0,
      "memory": 0.5,
      "gpu": 0,
      "gpuMem": 0
    },
    "perCorePricing": 0.2,
    "costRatio": 0.010671219720414044,
    "cost": 0.1
  },
  {
    "metadata": {
      "timestamp": "2023-02-14T03:27:18Z",
      "timeUnit": "hour",
      "DimensionType": "",
      "Dimension": "",
      "PodName": "thanos-query-74cfcd459f-pf54n"
    },
    "request": {
      "cpu": 0.1,
      "memory": 131072,
      "gpu": 0,
      "gpuMem": 0
    },
    "usage": {
      "cpu": 0.001,
      "memory": 90780,
      "gpu": 0,
      "gpuMem": 0
    },
    ...
  }
]

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 .

Expand to view the expected output

[
  {
    "metadata": {
      "timestamp": "2023-02-14T04:08:15Z",
      "timeUnit": "hour",
      "DimensionType": "Namespace",
      "Dimension": "default",
      "PodName": "test60-test-chart-v2-5cd85b946c-ntcct"
    },
    "request": {
      "cpu": 0,
      "memory": 0,
      "gpu": 0,
      "gpuMem": 0
    },
    "usage": {
      "cpu": 0,
      "memory": 18336,
      "gpu": 0,
      "gpuMem": 0
    },
    "limit": {
      "cpu": 0,
      "memory": 0,
      "gpu": 0,
      "gpuMem": 0
    },
    "perCorePricing": 0,
    "costRatio": 0,
    "cost": 0
  },
  {
    "metadata": {
      "timestamp": "2023-02-14T04:08:15Z",
      "timeUnit": "hour",
      "DimensionType": "Namespace",
      "Dimension": "default",
      "PodName": "nginx"
    },
    "request": {
      "cpu": 0,
      "memory": 0,
      "gpu": 0,
      "gpuMem": 0
    },
    ...
  }
]

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 .

Expand to view the expected output

[
  {
    "metadata": {
      "timestamp": "2023-02-14T04:09:50Z",
      "timeUnit": "hour",
      "DimensionType": "Pod",
      "Dimension": "pod=nginx-deployment-basic-75d6678cbb-lg8v5",
      "PodName": "nginx-deployment-basic-75d6678cbb-lg8v5"
    },
    "request": {
      "cpu": 0.5,
      "memory": 0,
      "gpu": 0,
      "gpuMem": 0
    },
    "usage": {
      "cpu": 0.002,
      "memory": 50148,
      "gpu": 0,
      "gpuMem": 0
    },
    "limit": {
      "cpu": 0,
      "memory": 0.5,
      "gpu": 0,
      "gpuMem": 0
    },
    "perCorePricing": 0.2,
    "costRatio": 0.010671219720414044,
    "cost": 0.1
  }
]

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.

LabelSelector and DimensionType are combined with AND logic. Omitting DimensionType queries 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 .

Expand to view the expected output

[
  {
    "metadata": {
      "timestamp": "2023-02-14T04:10:24Z",
      "timeUnit": "hour",
      "DimensionType": "",
      "Dimension": "",
      "PodName": "nginx-deployment-basic-75d6678cbb-lg8v5"
    },
    "request": {
      "cpu": 0.5,
      "memory": 0,
      "gpu": 0,
      "gpuMem": 0
    },
    "usage": {
      "cpu": 0.002,
      "memory": 50148,
      "gpu": 0,
      "gpuMem": 0
    },
    "limit": {
      "cpu": 0,
      "memory": 0.5,
      "gpu": 0,
      "gpuMem": 0
    },
    "perCorePricing": 0.2,
    "costRatio": 0.010671219720414044,
    "cost": 0.1
  },
  {
    "metadata": {
      "timestamp": "2023-02-14T04:10:24Z",
      "timeUnit": "hour",
      "DimensionType": "",
      "Dimension": "",
      "PodName": "nginx-675b8d6f54-vqxvd"
    },
    "request": {
      "cpu": 0.25,
      "memory": 524288,
      "gpu": 0,
      "gpuMem": 0
    },
    "usage": {
      "cpu": 0,
      "memory": 13548,
      "gpu": 0,
      "gpuMem": 0
    },
    "limit": {
      "cpu": 0,
      "memory": 0,
      "gpu": 0,
      "gpuMem": 0
    },
    "perCorePricing": 0.2,
    "costRatio": 0.005335609860207022,
    "cost": 0.05
  },
  {
    "metadata": {
      "timestamp": "2023-02-14T04:10:25Z",
      "timeUnit": "hour",
      "DimensionType": "",
      "Dimension": "",
      "PodName": "nginx-deployment-basic-7456bcd48d-r87rz"
    },
    "request": {
      "cpu": 0,
      "memory": 0,
      "gpu": 0,
      "gpuMem": 0
    },
    "usage": {
      "cpu": 0,
      "memory": 223492,
      "gpu": 0,
      "gpuMem": 0
    },
    "limit": {
      "cpu": 0,
      "memory": 0,
      "gpu": 0,
      "gpuMem": 0
    },
    "perCorePricing": 0,
    "costRatio": 0,
    "cost": 0
  }
]

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 .

Expand to view the expected output

[
  {
    "metadata": {
      "timestamp": "2023-02-14T04:11:04Z",
      "timeUnit": "day",
      "DimensionType": "Pod",
      "Dimension": "pod=nginx-deployment-basic-75d6678cbb-lg8v5",
      "PodName": "nginx-deployment-basic-75d6678cbb-lg8v5"
    },
    "request": {
      "cpu": 0.5,
      "memory": 0,
      "gpu": 0,
      "gpuMem": 0
    },
    "usage": {
      "cpu": 0.001,
      "memory": 50196,
      "gpu": 0,
      "gpuMem": 0
    },
    "limit": {
      "cpu": 0,
      "memory": 0.5,
      "gpu": 0,
      "gpuMem": 0
    },
    "perCorePricing": 0.2,
    "costRatio": 0.010571112959515542,
    "cost": 2.402
  }
]

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 .

Click to view the expected output

[
  {
    "metadata": {
      "timestamp": "2023-02-14T04:12:48Z",
      "timeUnit": "hour",
      "DimensionType": "Namespace",
      "Dimension": "default",
      "PodName": ""
    },
    "request": {
      "cpu": 12,
      "memory": 7045120,
      "gpu": 0,
      "gpuMem": 0
    },
    "usage": {
      "cpu": 0.053,
      "memory": 4901208,
      "gpu": 0,
      "gpuMem": 0
    },
    "limit": {
      "cpu": 0,
      "memory": 6553600,
      "gpu": 0,
      "gpuMem": 0
    },
    "perCorePricing": 4.061,
    "costRatio": 0.01609432143753053,
    "cost": 3.657
  }
]

What's next

References