Skip to main content

On-Premises Pricing

On-premises cluster pricing is supported in OpenCost by providing default prices for node data via the default.json.

{
"provider": "custom",
"description": "Default prices based on GCP us-central1",
"CPU": "0.031611",
"spotCPU": "0.006655",
"RAM": "0.004237",
"spotRAM": "0.000892",
"GPU": "0.95",
"storage": "0.00005479452",
"zoneNetworkEgress": "0.01",
"regionNetworkEgress": "0.01",
"internetNetworkEgress": "0.12"
}

This file is loaded when the OpenCost starts up, providing default prices. You may verify these values by querying Prometheus:

kubectl port-forward -n prometheus service/my-prometheus-server 9003:80
curl -s 'http://localhost:9003/api/v1/query?query=node_cpu_hourly_cost' | jq '.data.result[0]'
{
"metric": {
"__name__": "node_cpu_hourly_cost",
"instance": "mom.bottlebru.sh",
"instance_type": "k3s",
"job": "opencost",
"node": "mom.bottlebru.sh",
"provider_id": "k3s://mom.bottlebru.sh"
},
"value": [
1675411231.44,
"0.031611"
]
}

Similarly you can query node_ram_hourly_cost, node_total_hourly_cost, and pv_hourly_cost.

Modified Default.json Example

You can update the prices in the default.json file and rebuild your container with the modified source (make sure permissions are 644 on the default.json).

{
"provider": "custom",
"description": "Modified prices based on arbitrary whims",
"CPU": "1.25",
"spotCPU": "0.006655",
"RAM": "0.50",
"spotRAM": "0.000892",
"GPU": "0.95",
"storage": "0.25",
"zoneNetworkEgress": "0.01",
"regionNetworkEgress": "0.01",
"internetNetworkEgress": "0.12"
}

produces output similar to

kubectl port-forward -n prometheus service/my-prometheus-server 9003:80
curl -s 'http://localhost:9003/api/v1/query?query=node_cpu_hourly_cost' | jq '.data.result[0]'
{
"metric": {
"__name__": "node_cpu_hourly_cost",
"instance": "mom.bottlebru.sh",
"instance_type": "k3s",
"job": "opencost",
"node": "ndnd.bottlebru.sh",
"provider_id": "k3s://mom.bottlebru.sh"
},
"value": [
1675416174.822,
"1.25"
]
}

This is reflected in the OpenCost UI with substantially higher CPU, RAM and PV costs than before the update.

Custom pricing using the OpenCost Helm Chart

Create a configmap with custom pricing

apiVersion: v1
kind: ConfigMap
metadata:
name: opencost-conf
data:
default.json: |
{
"provider": "custom",
"description": "Modified prices based on arbitrary whims",
"CPU": "1.25",
"spotCPU": "0.006655",
"RAM": "0.50",
"spotRAM": "0.000892",
"GPU": "0.95",
"storage": "0.25",
"zoneNetworkEgress": "0.01",
"regionNetworkEgress": "0.01",
"internetNetworkEgress": "0.12"
}

Attach and reference the configmap by providing helm overrides during install.

opencost:
exporter:
extraEnv:
# The default config path is read only, for customizing we have to swap spots.
CONFIG_PATH: "/tmp/custom-config"
extraVolumeMounts:
- mountPath: /tmp/custom-config
name: custom-configs
extraVolumes:
- name: custom-configs
configMap:
name: opencost-conf
Documentation Distributed under CC BY 4.0.  The Linux Foundation® (TLF) has registered trademarks and uses trademarks. For a list of TLF trademarks, see: Trademark Usage.