有奖捉虫:行业应用 & 管理与支持文档专题 HOT

组件介绍

TKE 开发了 elastic-gpu-exporter 组件用于获取 GPU 相关监控指标,主要包含:
GPU 卡利用率
Pod / 容器 GPU 资源利用率

部署方式

elastic-gpu-exporter 通过 DaemonSet 的方式部署到集群里。
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: elastic-gpu-exporter
namespace: kube-system
labels:
app: elastic-gpu-exporter
spec:
updateStrategy:
type: RollingUpdate
selector:
matchLabels:
name: gpu-manager-ds
app: nano-gpu-exporter
template:
metadata:
name: elastic-gpu-exporter
labels:
name: gpu-manager-ds
app: nano-gpu-exporter
spec:
nodeSelector:
qgpu-device-enable: enable
serviceAccount: elastic-gpu-exporter
hostNetwork: true
hostPID: true
hostIPC: true
containers:
- image: ccr.ccs.tencentyun.com/tkeimages/elastic-gpu-exporter:v1.0.8
imagePullPolicy: Always
args:
- --node=$(NODE_NAME)
env:
- name: "PORT"
value: "5678"
- name: "NODE_NAME"
valueFrom:
fieldRef:
fieldPath: spec.nodeName
name: elastic-gpu-exporter
securityContext:
capabilities:
add: ["SYS_ADMIN"]
volumeMounts:
- name: cgroup
readOnly: true
mountPath: "/host/sys"
volumes:
- name: cgroup
hostPath:
type: Directory
path: "/sys"
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: elastic-gpu-exporter
rules:
- apiGroups:
- ""
resources:
- nodes
verbs:
- get
- list
- watch
- apiGroups:
- ""
resources:
- events
verbs:
- create
- patch
- apiGroups:
- ""
resources:
- pods
verbs:
- update
- patch
- get
- list
- watch
- apiGroups:
- ""
resources:
- bindings
- pods/binding
verbs:
- create
- apiGroups:
- ""
resources:
- configmaps
verbs:
- get
- list
- watch
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: elastic-gpu-exporter
namespace: kube-system
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: elastic-gpu-exporter
namespace: kube-system
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: elastic-gpu-exporter
subjects:
- kind: ServiceAccount
name: elastic-gpu-exporter
namespace: kube-system
---
apiVersion: v1
kind: Service
metadata:
name: elastic-gpu-exporter
namespace: kube-system
annotations:
prometheus.io/scrape: "true"
labels:
kubernetes.io/cluster-service: "true"
spec:
clusterIP: None
ports:
- name: elastic-gpu-exporter
port: 5678
protocol: TCP
targetPort: 5678
selector:
app: nano-gpu-exporter


查看运行状态

部署后,集群中生成一个 elastic-gpu-exporter 的 DaemonSet:
NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE
elastic-gpu-exporter 1 1 1 1 1 <none> 3m36s
符合条件的节点上会有一个运行的 elastic-gpu-exporter 的 Pod:
NAME READY STATUS RESTARTS AGE
elastic-gpu-exporter-dblqm 1/1 Running 0 6s

获取监控指标

elastic-gpu-exporter 的服务运行所在节点会输出到 /metrics 路径下,因此也可以通过如下命令获取监控指标:
$ curl NodeIP:5678/metrics

GPU 卡相关指标

gpu_xxx
GPU 指标
gpu_core_usage
GPU 实际使用的算力
gpu_mem_usage
GPU 实际使用的显存
gpu_core_utilization_percentage
GPU 算力使用率
gpu_mem_utilization_percentage
GPU 显存使用率
GPU 卡的指标形式为: 
gpu_core_usage{card="0",node="10.0.66.4"} 0
说明:
“card” 表示 GPU 的序号,“node” 表示所在节点。

Pod 相关指标

pod_xxx
pod 指标
pod_core_usage
pod 实际使用的算力
pod_mem_usage
pod 实际使用的显存
pod_core_utilization_percentage
pod 实际使用的算力占申请算力的百分比
pod_mem_utilization_percentage
pod 实际使用的显存占申请显存的百分比
pod_core_occupy_node_percentage
pod 实际使用的算力占节点总算力百分比
pod_mem_occupy_node_percentage
pod 实际使用的显存占节点总显存百分比
pod_core_request
pod 申请的算力
pod_mem_request
pod 申请的显存
Pod 的指标形式为: 
pod_core_usage{namespace="default",node="10.0.66.4",pod="7a2fa737-eef1-4801-8937-493d7efb16b7"} 0
说明:
“namespace” 表示 Pod 所在的 namespace,“node” 表示 Pod 所在节点,“pod” 表示 Pod 的名称。

容器相关指标

container_xxx
容器指标
container_gpu_utilization
容器实际使用的算力
container_gpu_memory_total
容器实际使用的显存
container_core_utilization_percentage
容器实际使用的算力占申请算力的百分比
container_mem_utilization_percentage
容器实际使用的显存占申请显存的百分比
container_request_gpu_memory
容器申请的显存
container_request_gpu_utilization
容器申请的算力
容器的指标形式为: 
container_gpu_utilization{container="cuda",namespace="default",node="10.0.66.4",pod="cuda"} 0
说明:
“container” 表示容器名称,“namespace” 表示容器所在的 namespace,“node” 表示容器所在节点,“pod” 表示容器所在的 Pod 的名称。