Enable Billing

This tutorial demonstrates how to enable KubeSphere Billing to view the cost of different resources in your cluster. By default, the Billing function is disabled so you need to manually add the price information in a ConfigMap.

Perform the steps below to enable KubeSphere Billing.

  1. Edit the ConfigMap kubesphere-config by running the following command:

    1. kubectl edit cm kubesphere-config -n kubesphere-system
  2. Add the retention day and price information under metering in the ConfigMap.

    ParameterDescription
    retentionDayretentionDay determines the date range displayed on the Metering and Billing page for users. The value of this parameter must be the same as the value of retention in Prometheus.
    currencyUnitThe currency that displays on the Metering and Billing page. Currently allowed values are CNY (Renminbi) and USD (US dollars). If you specify other currencies, the console will display cost in USD by default.
    cpuPerCorePerHourThe unit price of CPU per core/hour.
    memPerGigabytesPerHourThe unit price of memory per GB/hour.
    ingressNetworkTrafficPerMegabytesPerHourThe unit price of ingress traffic per MB/hour.
    egressNetworkTrafficPerMegabytesPerHourThe unit price of egress traffic per MB/hour.
    pvcPerGigabytesPerHourThe unit price of PVC per GB/hour. Note that KubeSphere calculates the total cost of volumes based on the storage capacity PVCs request regardless of the actual storage in use.

    The following is an example for your reference:

    1. $ kubectl get cm kubesphere-config -n kubesphere-system -oyaml
    2. ...
    3. alerting:
    4. prometheusEndpoint: http://prometheus-operated.kubesphere-monitoring-system.svc:9090
    5. thanosRulerEndpoint: http://thanos-ruler-operated.kubesphere-monitoring-system.svc:10902
    6. thanosRuleResourceLabels: thanosruler=thanos-ruler,role=thanos-alerting-rules
    7. ...
    8. metering:
    9. retentionDay: 7d
    10. billing:
    11. priceInfo:
    12. currencyUnit: "USD"
    13. cpuPerCorePerHour: 1.5
    14. memPerGigabytesPerHour: 5
    15. ingressNetworkTrafficPerMegabytesPerHour: 1
    16. egressNetworkTrafficPerMegabytesPerHour: 1
    17. pvcPerGigabytesPerHour: 2.1
    18. kind: ConfigMap
    19. ...
  3. After you set the price information, restart ks-apiserver.

    1. kubectl rollout restart deploy ks-apiserver -n kubesphere-system
  4. On the Metering and Billing page, you can see the cost information of resources.

    billing-dashboard