天天看點

基于阿裡雲容器服務監控 Kubernetes叢集GPU名額

簡介

當您在阿裡雲容器服務中使用GPU ECS主機建構Kubernetes叢集進行AI訓練時,經常需要知道每個Pod使用的GPU的使用情況,比如每塊顯存使用情況、GPU使用率,GPU卡溫度等監控資訊,本文介紹如何快速在阿裡雲上建構基于Prometheus + Grafana的GPU監控方案。

Prometheus

Prometheus 是一個開源的服務監控系統和時間序列資料庫。從 2012 年開始編寫代碼,再到 2015 年 github 上開源以來,已經吸引了 20k+ 關注,2016 年 Prometheus 成為繼 k8s 後,第二名 CNCF(

Cloud Native Computing Foundation

) 成員。2018年8月 于CNCF畢業。

作為新一代開源解決方案,很多理念與 Google SRE 運維之道不謀而合。

基于阿裡雲容器服務監控 Kubernetes叢集GPU名額

操作

前提

您已經通過阿裡雲容器服務建立了擁有GPU ECS的Kubernetes叢集,并部署prometheus監控,具體步驟請參考:

部署Prometheus 的GPU 采集器

apiVersion: apps/v1
kind: DaemonSet
metadata:
  namespace: monitoring
  name: ack-prometheus-gpu-exporter
spec:
  selector:
    matchLabels:
      k8s-app: ack-prometheus-gpu-exporter
  template:
    metadata:
      labels:
        k8s-app: ack-prometheus-gpu-exporter
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: aliyun.accelerator/nvidia_name
                operator: Exists
      hostPID: true
      containers:
      - name: node-gpu-exporter
        image: registry.cn-hangzhou.aliyuncs.com/acs/gpu-prometheus-exporter:0.1-5cc5f27
        imagePullPolicy: Always
        ports:
        - name: http-metrics
          containerPort: 9445
        env:
          - name: MY_NODE_NAME
            valueFrom:
              fieldRef:
                apiVersion: v1
                fieldPath: spec.nodeName
        resources:
          requests:
            memory: 50Mi
            cpu: 200m
          limits:
            memory: 100Mi
            cpu: 300m
        volumeMounts:
        - mountPath: /var/run/docker.sock
          name: docker-sock
      volumes:
      - hostPath:
          path: /var/run/docker.sock
          type: File
        name: docker-sock
        
---
apiVersion: v1
kind: Service
metadata:
  name: node-gpu-exporter
  namespace: monitoring
  labels:
    k8s-app: ack-prometheus-gpu-exporter
spec:
  type: ClusterIP
  ports:
  - name: http-metrics
    port: 9445
    protocol: TCP
  selector:
    k8s-app: ack-prometheus-gpu-exporter

---
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: ack-prometheus-gpu-exporter
  labels:
    release: ack-prometheus-operator
    app: ack-prometheus-gpu-exporter
  namespace: monitoring
spec:
  selector:
    matchLabels:
      k8s-app: ack-prometheus-gpu-exporter
  namespaceSelector:
    matchNames:
    - monitoring
  endpoints:
  - port: http-metrics
    interval: 30s
           

配置Grafana

通路Grafana監控面闆

執行以下指令,将叢集中的Grafana映射到本地3000端口。

kubectl -n monitoring port-forward svc/ack-prometheus-operator-grafana 3000:80
           

在浏覽器中通路localhost:3000,即可通路Grafana。 預設賬号密碼為 admin/admin

基于阿裡雲容器服務監控 Kubernetes叢集GPU名額
導入GPU監控配置
  1. 下載下傳檔案并解壓,得到兩個json檔案: GPU 監控 Grafana配置
  2. 進入Grafana頁面,點選Import dashboard:
    基于阿裡雲容器服務監控 Kubernetes叢集GPU名額
  3. 第一步下載下傳的json檔案上傳,選擇資料源為Prometheus
    基于阿裡雲容器服務監控 Kubernetes叢集GPU名額

導入完成後檢視結果确認監控正常。

檢視監控資訊

節點GPU監控
基于阿裡雲容器服務監控 Kubernetes叢集GPU名額
Pod GPU監控
基于阿裡雲容器服務監控 Kubernetes叢集GPU名額

部署應用

如果您已經使用了Arena

Arena - 打開KubeFlow的正确姿勢

) ,可以直接使用arena送出一個訓練任務。

arena submit tf --name=style-transfer              \
              --gpus=1              \
              --workers=1              \
              --workerImage=registry.cn-hangzhou.aliyuncs.com/tensorflow-samples/neural-style:gpu \
              --workingDir=/neural-style \
              --ps=1              \
              --psImage=registry.cn-hangzhou.aliyuncs.com/tensorflow-samples/style-transfer:ps   \
              "python neural_style.py --styles /neural-style/examples/1-style.jpg --iterations 1000000"

NAME:   style-transfer
LAST DEPLOYED: Thu Sep 20 14:34:55 2018
NAMESPACE: default
STATUS: DEPLOYED

RESOURCES:
==> v1alpha2/TFJob
NAME                  AGE
style-transfer-tfjob  0s           

送出任務成功後在監控頁面裡可以看到Pod的GPU相關名額, 能夠看到我們通過Arena部署的Pod,以及pod裡GPU 的資源消耗

基于阿裡雲容器服務監控 Kubernetes叢集GPU名額

節點次元也可以看到對應的GPU卡和節點的負載, 在GPU節點監控頁面可以選擇對應的節點和GPU卡

基于阿裡雲容器服務監控 Kubernetes叢集GPU名額