启用计费

本教程介绍如何启用 KubeSphere 的计费功能,以查看集群中不同资源的消费情况。计费功能默认不启用,因此您需要在 ConfigMap 中手动添加价格信息。

请按照以下步骤启用 KubeSphere 的计费功能。

  1. 运行以下命令编辑 ConfigMap kubesphere-config

    1. kubectl edit cm kubesphere-config -n kubesphere-system
  2. 在该 ConfigMap 的 metering 下添加保留期限和价格信息。

    参数描述
    retentionDayretentionDay 决定用户的资源消费统计页面显示的日期范围。该参数的值必须与 Prometheusretention 的值相同。
    currencyUnit资源消费统计页面显示的货币单位。目前可用的单位有 CNY(人民币)和 USD(美元)。若指定其他货币,控制台将默认以美元为单位显示消费情况。
    cpuPerCorePerHour每核/小时的 CPU 单价。
    memPerGigabytesPerHour每 GB/小时的内存单价。
    ingressNetworkTrafficPerMegabytesPerHour每 MB/小时的入站流量单价。
    egressNetworkTrafficPerMegabytesPerHour每 MB/小时的出站流量单价。
    pvcPerGigabytesPerHour每 GB/小时的 PVC 单价。请注意,无论实际使用的存储是多少,KubeSphere 都会根据 PVC 请求的存储容量来计算存储卷的总消费情况。

    以下示例供您参考:

    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. 价格信息设置完成后,重启 ks-apiserver

    1. kubectl rollout restart deploy ks-apiserver -n kubesphere-system
  4. 资源消费统计页面,您可以看到资源的消费信息。

    metering-and-billing