如何定义 pGPU 成本模型

前提条件

在 GPU 集群中:

  • 已安装 Alauda Build of NVIDIA GPU Device Plugin
  • 已安装 Cost Management 智能体

关于 Alauda Build of NVIDIA GPU Device Plugin

适用于 Kubernetes 的 NVIDIA device plugin 是一个 DaemonSet,可让你自动执行以下操作:

  • 暴露集群中每个节点上的 GPU 数量
  • 跟踪 GPU 的健康状态
  • 在 Kubernetes 集群中运行启用了 GPU 的容器
Note
因为 Alauda Build of NVIDIA GPU Device Plugin 的发版周期与灵雀云容器平台不同,所以 Alauda Build of NVIDIA GPU Device Plugin 的文档现在作为独立的文档站点托管在 Alauda Build of NVIDIA GPU Device Plugin

操作步骤

创建 PrometheusRule 以生成所需指标

在 GPU 集群中创建一个 PrometheusRule。

apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
  labels:
    prometheus: kube-prometheus
  name: pgpu-labels
  namespace: kube-system
spec:
  groups:
  - name: gpu.rules
    interval: 30s
    rules:
    - record: gpu_count
      expr: |
        count by (UUID, label_modelName, namespace) (
          label_replace(
            DCGM_FI_DEV_GPU_UTIL{namespace!="kube-system"},
            "label_modelName",
            "$0",
            "modelName",
            ".*"
          )
        )

添加采集配置(Cost Management Agent)

在运行 Cost Management 智能体的 GPU 集群中创建一个 ConfigMap,用于声明要采集的内容。

apiVersion: v1
data:
  config: >
    - kind: pGPU
      category: pGPUCount
      item: vGPUCountQuota
      period: Hourly
      labels:
        query: "gpu_count"
        mappers:
          name: UUID
          namespace: namespace
          cluster: ""
          project: ""
      usage:
        query: gpu_count
        step: 5m
        mappers:
          name: UUID
          namespace: namespace
          cluster: ""
          project: ""
kind: ConfigMap
metadata:
  labels:
    cpaas.io/slark.collection.config: "true"
  name: slark-agent-pgpu-namespace-config
  namespace: cpaas-system
---
apiVersion: v1
data:
  config: >
    - kind: Project
      category: pGPUCount
      item: vGPUCountsProjectQuota
      period: Hourly
      usage:
        query: avg by (project, cluster) (avg_over_time(cpaas_project_resourcequota{resource="requests.nvidia.com/gpu", type="project-hard"}[5m]))
        step: 5m
        mappers:
          name: project
          namespace: ""
          cluster: cluster
          project: project
kind: ConfigMap
metadata:
  labels:
    cpaas.io/slark.collection.config: "true"
  name: slark-agent-project-config-vgpu
  namespace: cpaas-system

添加 yaml 后,需要重启 Agent Pod 以重新加载配置。

kubectl delete pods -n cpaas-system -l service_name=slark-agent

添加展示/存储配置(Cost Management Server)

在运行 Cost Management Server 的集群中创建一个 ConfigMap,用于声明计费项、计费方式、单位和显示名称。这会告诉服务器要计什么费以及如何计费。

apiVersion: v1
data:
  config: |
    - name: pGPUCount
      displayname:
        zh: "pGPU"
        en: "pGPU"
      methods:
        - name: Request
          displayname:
            zh: "请求量"
            en: "Request Usage"
          item: vGPUCountQuota
          divisor: 1
          unit:
            zh: "count-hours"
            en: "count-hours"
        - name: ProjectQuota
          displayname:
            zh: "项目配额"
            en: "Project Quota"
          item: vGPUCountsProjectQuota
          unit:
            zh: "count-hours"
            en: "count-hours"
          divisor: 1
kind: ConfigMap
metadata:
  labels:
    cpaas.io/slark.display.config: "true"
  name: slark-display-config-for-pgpu
  namespace: kube-public

添加 yaml 后,需要重启 Server Pod 以重新加载配置。

kubectl delete pods -n cpaas-system -l service_name=slark-server

为 pGPU 成本模型添加价格

计费方式说明

计费项计费方式计费规则说明
pGPURequest (Count-hours)按小时基于 POD 在过去一小时内的 Request 进行计算,并乘以 POD 的实际持续时间(如果少于 5 分钟,则按 5 分钟计)。基于 pGPU 资源请求
pGPUProject Quota (Count-hours)按小时基于项目分配的 CPU 配额上限进行计算,并乘以持续时间。配额变更时按分段方式计算。基于项目级资源配额

如果 GPU 集群没有 Cost model,则需要创建一个新的 cost model。
然后可以为 GPU 集群的 cost model 添加价格:

  1. Billing Items 中选择 pGPU
  2. Method 中选择 Request Usage (count-hours)Project Quota (count-hours)
  3. 设置 Default Price
  4. 配置 Price By Label(可选)。
    示例:
    key: modelName
    value: "Tesla P100-PCIE-16GB" 或 "Tesla T4" 或 "NVIDIA A30"(可通过运行 nvidia-smi 获取)

成本明细和成本统计

最后,在等待 1 个或多个小时后,你可以在 Cost Details 中看到按 namespace 和 card uuid 维度展示的成本明细。
同时,你还可以在 Cost Statistics 中看到基于 cluster、project 和 namespace 的总成本。