ACK cost insights supports custom cost accounting policies as an alternative to default cost allocation policies. If your internal pricing differs—for example, because your operations team resells bulk-purchased compute to business units at negotiated rates, or because you need to eliminate cost variations caused by scheduling—you can define custom pricing templates. Each template assigns unit prices for CPU and memory and is matched to Pods by label, namespace, and resource specification.
Pod costs from custom pricing templates are available only through an API. After you configure custom pricing, retrieve the data from the customCost field in the API response. For more information, see Overview of retrieving cost data by API.
When to use custom pricing
Custom pricing templates are useful in the following scenarios:
-
An internal operations team purchases compute resources in bulk and resells them to business units at different rates.
-
Pods with identical specifications land on nodes of different specifications due to scheduling. You want to standardize costs at the business level and eliminate the resulting cost variation.
-
Business units deploy Pods with the same resource request but different overcommit ratios on the same node, and you need differentiated cost accounting based on the resource limit.
Prerequisites
Before you begin, make sure you have:
Step 1: Enable custom pricing in cost-exporter
-
Log on to the ACK console. In the left navigation pane, click Clusters.
-
On the Clusters page, click the name of your cluster. In the left navigation pane, click Workloads > Deployments.
-
At the top of the page, select kube-system from the Namespace drop-down list. Find the ack-cost-exporter Deployment. In the Actions column, choose More > View in YAML. In the
commandsection, add'--enable-custom-price=true'. Click Update.
Step 2: Configure a pricing template
-
Create a file named
price-template.yamlwith the following content.ImportantAll fields under
specare optional. A Pod matches a template when all configuredspecfields match the Pod's metadata. A template with an emptyspecmatches all Pods. If aspecfield is omitted, that condition is not applied and the template matches Pods regardless of that attribute.Templates are evaluated in order. When a Pod matches multiple templates, the system uses the first matching template from top to bottom.
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.02This template defines two pricing rules:
-
template-nginx applies to Pods that meet all of the following conditions: the Pod has the
app: nginxlabel, runs in thedefaultorkube-systemnamespace, has a CPU resource request of 500m (limit: 1 Core), and has a memory resource request of 512 MiB (limit: 1 GiB). -
template-default applies to all other Pods in the cluster.
The following table describes the template parameters.
Parameter Description nameName of the pricing template. spec.labelSelectorSelector for matching Pod labels. Omit to match Pods with any label. spec.namespaceSelectorList of namespaces to match. Omit to match Pods in any namespace. spec.resource.cpuCPU resource request of the Pod. Omit to match Pods with any CPU request. spec.resource.memoryMemory resource request of the Pod. Omit to match Pods with any memory request. spec.resource.cpu-overcommit-ratioCPU overcommit ratio of the Pod, calculated as CPU resource limit / CPU resource request. Omit to match Pods with any CPU overcommit ratio. spec.resource.memory-overcommit-ratioMemory overcommit ratio of the Pod, calculated as memory resource limit / memory resource request. Omit to match Pods with any memory overcommit ratio. price.cpuUnit price of the Pod's CPU. Unit: Core-Hour. price.memoryUnit price of the Pod's memory. Unit: GiB-Hour. -
-
Apply the ConfigMap to your cluster.
kubectl apply -f price-template.yaml -n kube-system
What's next
-
Estimate Pod costs based on cluster scheduling watermarks using single-resource (CPU or memory) or weighted-mix estimation. See Introduction to cost estimation policies.
-
Query cost insights data through the HTTP API for custom development. See Overview of calling an API to query cost data.