All Products
Search
Document Center

Container Service for Kubernetes:Custom cost allocation policies

Last Updated:Jun 20, 2026

In addition to default cost allocation strategies, the cost management suite allows you to create custom cost accounting policies. To define your own chargeback logic for cloud resource costs, create a configuration file that sets custom resource prices. This helps align cost data more closely with your business logic.

Use cases

Custom pricing provides fine-grained control over your IT costs. Common use cases include:

  • An internal operations team purchases underlying computing resources in bulk and resells them to different business teams.

  • Normalize costs at the business level by eliminating price variations that result from scheduling identical pods on nodes with different specifications.

  • To implement differentiated pricing, you must include the resource limit when calculating the pod's unit price.

To address these scenarios, the cost management suite provides a custom pricing template feature. You can edit a template to configure the unit price for each of a pod's resources, which are then aggregated to determine the pod's custom cost.

Note

Currently, a pod's custom cost is available only through the API. After you enable and configure custom pricing, you can retrieve the cost from the customCost field in the API response. For details on using the API, see Retrieve cost data by API.

Prerequisites

Step 1: Enable custom pricing for cost-exporter

  1. Log on to the ACK console. In the left navigation pane, click Clusters.

  2. On the Clusters page, click the name of your cluster. In the left navigation pane, click Workloads > Deployments.

  3. At the top of the page, switch the namespace to kube-system. In the Actions column of the Deployment list, click More > View in YAML for ack-cost-exporter. In the command section, add '--enable-custom-price=true' to enable the custom price feature. Then, click Update.

    spec:
            containers:
            - command:
                - /root/alibaba-cloud-price-exporter
                - '--listen-address=:9091'
                - '--ali-user-id=1251182063904492'
                - '--cluster-id=c66b9e33984194a219813f6a7d402cdba'
                - '--region-id=cn-hangzhou'
                - '--cluster-type=ManagedKubernetes'
                - '--cluster-profile=Default'
                - '--enable-custom-price=true'
              env:
                - name: DefaultIDCPricePerCPUCoreHour
                  value: '0.2'

Step 2: Configure the pricing template

Procedure

  1. Create a file named price-template.yaml with the following example content.

    Important
    • The fields under the spec field in a template are optional. If all configured fields under spec match the Pod's metadata, the Pod is considered a match for the template. A template with an empty spec can match all Pods.

    • Templates are matched in order. If a pod matches multiple templates in the YAML file, the system uses the first matching template to calculate the pod's cost.

    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: price-template
      namespace: kube-system
    data:
      template.yaml: |
        - name: template-nginx
          spec:
            labelSelector:
              app: nginx
            namespaceSelector:
              - default
              - kube-system
            resource:
              cpu: 500m
              memory: 512Mi
              cpu-overcommit-ratio: 2
              memory-overcommit-ratio: 2
          price:
            cpu: 0.2
            memory: 0.03
        - name: template-default
          price:
            cpu: 0.1
            memory: 0.02

    This pricing template specifies the following rules:

    • The template-nginx template applies to pods that meet all of the following conditions:

      • The label contains app:nginx

      • The pod is in the default or kube-system namespace.

      • The CPU request is 500m, and the limit is 1 Core.

      • The memory request is 512 MiB, and the limit is 1 GiB.

    • All other pods in the cluster use the template-default template.

    The following table describes the parameters.

    Parameter

    Description

    name

    The name of the pricing template.

    spec.labelSelector

    A map of key-value pairs. A pod is considered a match if it has all the labels specified in this selector.

    spec.namespaceSelector

    A list of namespaces. The pod's namespace must be in this list to match.

    spec.resource.cpu

    The pod's CPU request.

    spec.resource.memory

    The pod's memory request.

    spec.resource.cpu-overcommit-ratio

    The pod's CPU overcommitment ratio, calculated as CPU limit / CPU request.

    spec.resource.memory-overcommit-ratio

    The pod's memory overcommitment ratio, calculated as memory limit / memory request.

    price.cpu

    The unit price for CPU, measured in cost per core-hour.

    price.memory

    The unit price for memory, measured in cost per GiB-hour.

  2. Run the following command to create the price-template ConfigMap in the kube-system namespace and apply your custom pricing configuration.

    kubectl apply -f price-template.yaml -n kube-system

Related documents

  • You can estimate pod costs based on cluster resource utilization by using single-resource (CPU or memory) or weighted (CPU and memory) models. For more information, see Cost estimation policies.

  • Send HTTP API requests to retrieve cost insights data for custom development. For more information, see Overview of calling an API to query cost data.