GPU 워커 노드에서 수평 포드 자동 확장 설정하기

다음 단계를 검토하여 GPU 워커 노드에서 수평 포드 자동 확장을 사용하도록 설정하세요.

왜 수평적 포드 자동 확장인가?
워크로드가 특정 양의 GPU를 더 많이 또는 더 적게 소비할 때 파드 수를 확장하도록 수평적 파드 자동 확장을 구성할 수 있습니다. GPU는 고가의 리소스이므로 워크로드를 장시간 최대 용량으로 실행하는 것은 바람직하지 않을 수 있습니다. 대신 클러스터에서 실행 중인 워크로드에 따라 파드를 확장하거나 축소할 수 있습니다.

전제조건

HPA를 구성하려면 클러스터에 다음 구성 요소를 설치해야 합니다.

  • NVIDIA 데이터 센터 GPU 관리자(DCGM) 익스포터를 사용하여 Kubernetes 에서 GPU 메트릭을 수집합니다. DCGM 익스포터는 Grafana 을 사용하여 시각화할 수 있는 Prometheus 에 대한 GPU 메트릭을 노출합니다.
  • Prometheus 및 Prometheus 어댑터를 사용하여 사용자 지정 지표를 생성할 수 있습니다.
  1. NVIDIA GPU 연산자 설치

  2. 설치 Prometheus.

    helm install prom-stack prometheus-community/kube-prometheus-stack -f ~/ca-prom-val.yaml
    
    cat ~/ca-prom-val.yaml
    
    prometheus:
        prometheusSpec:
            additionalScrapeConfigs:
            - job_name: gpu-metrics
                scrape_interval: 1s
                metrics_path: /metrics
                scheme: http
                kubernetes_sd_configs:
                - role: endpoints
                    namespaces:
                        names:
                        - nvidia-gpu-operator
                relabel_configs:
                - source_labels: [__meta_kubernetes_endpoints_name]
                    action: drop
                    regex: .*-node-feature-discovery-master
                - source_labels: [__meta_kubernetes_pod_node_name]
                    action: replace
                    target_label: kubernetes_node
    
  3. Prometheus 서비스 세부 정보를 확인하세요.

    oc get svc
    
  4. Prometheus 어댑터를 설치하십시오.

    helm upgrade --install prometheus-adapter prometheus-community/prometheus-adapter --set prometheus.url="http://prom-stack-kube-prometheus-prometheus.default.svc.cluster.local"
    

HPA 설정

HPA를 사용하는 배포를 만들려면 다음 단계를 완료하세요.

  1. 배치를 작성하십시오.

    apiVersion: apps/v1
    kind: Deployment
    metadata:
        name: cuda-test
        labels:
            app: cuda-test
    spec:
        selector:
            matchLabels:
                app: cuda-test
        template:
            metadata:
                labels:
                    app: cuda-test
            spec:
                containers:
                - name: cuda-test-main
                    image: "registry.k8s.io/cuda-vector-add:v0.1"
                    command: ["bash", "-c", "for (( c=1; c<=5000; c++ )); do ./vectorAdd; done"]
                    resources:
                        limits:
                            nvidia.com/gpu: 1
    
  2. HorizontalPodAutoscaler 리소스를 생성합니다.

    kind: HorizontalPodAutoscaler
    apiVersion: autoscaling/v2
    metadata:
        name: cuda-hpa
        namespace: default
    spec:
        scaleTargetRef:
            apiVersion: apps/v1
            kind: Deployment
            name: cuda-test
        minReplicas: 1
        maxReplicas: 3
        metrics:
            - type: Pods
                pods:
                    metric:
                        name: DCGM_FI_DEV_GPU_UTIL     #the metric you want to use for autoscaling
                    target:
                        type: AverageValue
                        averageValue: '5'
    
  3. 결과를 확인하려면 다음 명령어를 실행하십시오.

    oc get pods | grep cuda
    
    cuda-test-d987464bf-brd48                                1/1     Running   0          4m19s
    cuda-test-d987464bf-gsx82                                0/1     Pending   0          4m19s
    cuda-test-d987464bf-zstzs                                1/1     Running   0          7m35s
    

    워크로드 리소스가 증가함에 따라 복제본 1개가 3개로 확장되었습니다.

    Min replicas:       1
    Max replicas:       3
    Deployment pods:    3 current / 3 desired
    Events:
    Type    Reason             Age   From                       Message
    ----    ------             ----  ----                       -------
    Normal  SuccessfulRescale  50s   horizontal-pod-autoscaler  New size: 3; reason: pods metric DCGM_FI_DEV_GPU_UTIL above target