All Products
Search
Document Center

:Custom cost accounting policies

更新時間:Jul 24, 2024

In addition to default cost allocation policies, the cost management suite supports custom cost accounting policies. If you have higher requirements on cost allocation of cloud resources or if you need to customize cost allocation, you can configure custom resource prices.

Note

This feature is in canary release. To use this feature, submit a ticket.

Use scenarios

You can implement fine-grained IT spending governance based on custom cost accounting policies. Custom cost accounting policies are suitable for the following scenarios:

  • The enterprise O&M team resells underlying computing resources to different business departments of the enterprise.

  • Enterprises want to eliminate differences in business costs caused by dynamic resource prices. For example, when pods with the same configurations are scheduled to nodes with different specifications, the fees incurred by the nodes are different.

  • Different departments of an enterprise deploy pods with the same resource requests on the same node based on different overcommit ratios. In this case, if you want to implement differentiated cost accounting among departments, you must consider the resource limit when you calculate the pod unit price.

To meet the preceding requirements for data customization, the cost management suite provides templates that you can use to configure custom resource unit prices. You can calculate the pod unit price by aggregating the unit prices of the resources used by the pod.

Note

After you configure custom resource unit prices, you can obtain the pod unit price only by calling an API operation. The customCost parameter in the response indicates the pod unit price. For more information about how to call the API operations, see Overview of calling an API to query cost data.

Prerequisites

Step 1: Enable the custom resource pricing feature of cost-exporter

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

  2. On the Clusters page, find the cluster that you want to manage and click its name. In the left-side pane, choose Workloads > Deployments.

  3. In the upper part of the page, select kube-system from the Namespace drop-down list. Find ack-cost-exporter and choose More > View in YAML in the Actions column. Add '--enable-custom-price=true' to the command parameter. Then, click Update.image

Step 2: Configure a pricing template

Procedure

  1. Create a file named price-template.yaml and copy the following content to the file.

    Important
    • All fields in the spec parameter are optional. If all fields in the spec parameter match the metadata of a pod, the template applies to the pod. If no field exists in the spec parameter, the template applies to all pods.

    • If multiple templates match the metadata of a pod, the system selects the template on the top of the list.

    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

    The preceding template specifies the following details:

    • Pods that meet all the following conditions use the template-nginx template for resource pricing:

      • The pod has the app:nginx label.

      • The pod belongs to the default or kube-system namespace.

      • The CPU request is 500 millicores and the CPU limit is 1 CPU core.

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

    • Other pods use the template-default template for resource pricing.

    The following table describes the parameters in the preceding pricing template.

    Parameter

    Description

    name

    The name of the pricing template.

    spec.labelSelector

    The label selectors. If a pod has one of the labels, the pod meets this condition.

    spec.namespaceSelector

    The namespace selectors.

    spec.resource.cpu

    The CPU request of the pod.

    spec.resource.memory

    The memory request of the pod.

    spec.resource.cpu-overcommit-ratio

    The CPU overcommitment ratio, which equals the result of dividing the CPU limit by the CPU request.

    spec.resource.memory-overcommit-ratio

    The memory overcommitment ratio, which equals the result of dividing the memory limit by the memory request.

    spec.price.cpu

    The CPU unit price of the pod. Unit: USD/core-hour.

    spec.price.memory

    The memory unit price of the pod. Unit: USD/GiB-hour.

  2. Run the following command to create the price-template ConfigMap in the kube-system namespace.

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

References

  • You can estimate the pod cost based on the resource watermark of the cluster. You can use single resource cost estimation (based on CPUs or memory) or weighted resource cost estimation (based on CPUs and memory). For more information, see Cost estimation policies.

  • You can send HTTP API requests to retrieve cost insights data and use the data for custom development. For more information, see Overview of calling an API to query cost data.