Tất cả tài liệu

Managed – FPT Kubernetes Engine

    Triển khai ứng dụng sử dụng GPU trên Kubernetes
    Triển khai ứng dụng sử dụng GPU trên Kubernetes
    Updated on 12 Apr 2024

    Kubernetes quản lý và sử dụng resources GPU tương tự như sử dụng resources CPU. Tùy vào cấu hình GPU lựa chọn cho Worker Group để khai báo resources GPU cho ứng dụng trên Kubernetes. 

    Chú ý:  

    • Có thể chỉ định GPU limits mà không cần chỉ định requests do Kubernetes sử dụng limits làm giá trị yêu cầu mặc định.
    • Có thể chỉ định cả GPU limits và requests nhưng hai giá trị này phải bằng nhau.
    • Không thể chỉ định GPU requests mà không chỉ định limits.

    – Kiểm tra cấu hình GPU bằng lệnh sau: 

    kubectl get node  -o json | jq ‘.items[].metadata.labels‘ 

     

    Text
Description automatically generated

    Ví dụ: hình trên cho thấy worker sủ dụng card Nvidia A30, cấu hình strategy: all-balanced, trạng thái: success.

    – Kiểm tra cấu hình GPU Instance trên worker chưa bằng lệnh sau: (ssh vào worker, gõ lệnh) 

    A screen shot of a computer
Description automatically generated with low confidence

    Ví dụ triển khai ứng dụng sử dụng GPU:

    • Với strategy: single, tài nguyên GPU được khai báo như sau:
    1. Cú pháp:
    nvidia.com/gpu: [số-lượng-gpu]

     

    1. Ví dụ:
    nvidia.com/gpu: 1
    (Với strategy single, card GPU chia được chia nhỏ thành các instance bằng nhau) 

     

    1. Ví dụ deployment sử dụng gpu single strategy 
    apiVersion: apps/v1 
    kind: Deployment 
    metadata: 
      name: example-gpu-app 
    spec: 
      replicas: 1 
      selector: 
        matchLabels: 
          component: gpu-app 
      template: 
        metadata: 
          labels: 
            component: gpu-app 
        spec: 
          containers: 
            – name: gpu-container 
              securityContext: 
                capabilities: 
                  add: 
                    – SYS\_ADMIN 
              resources: 
                limits: 
                  nvidia.com/gpu: 1 
              image: nvidia/samples:dcgmproftester-2.0.10-cuda11.0-ubuntu18.04 
              command: [“/bin/sh”, “-c”] 
              args: 
                – while true; do /usr/bin/dcgmproftester11 –no-dcgm-validation -t 1004 -d 300; sleep 30; done  

     

    • Với strategy: mixed, tài nguyên GPU được khai báo như sau:
    1. Cú pháp:  
    nvidia.com/[mig-profile]: [số-lượng-gpu]

     

    1. Ví dụ:  
    
    nvidia.com/mig-1g.6gb: 2
    (Với strategy mixed, card GPU chia được chia nhỏ thành 2 loại instance nên khi khai báo resources cần chỉ rõ loại instance sử dụng) 

     

    1. Ví dụ deployment sử dụng gpu mixed strategy 
    apiVersion: apps/v1 
    kind: Deployment 
    metadata: 
      name: example-gpu-app 
    spec: 
      replicas: 1 
      selector: 
        matchLabels: 
          component: gpu-app 
      template: 
        metadata: 
          labels: 
            component: gpu-app 
        spec: 
          containers: 
            – name: gpu-container 
              securityContext: 
                capabilities: 
                  add: 
                    – SYS\_ADMIN 
              resources: 
                limits: 
                  nvidia.com/mig-1g.6gb: 1 
              image: nvidia/samples:dcgmproftester-2.0.10-cuda11.0-ubuntu18.04 
              command: [“/bin/sh”, “-c”] 
              args: 
                – while true; do /usr/bin/dcgmproftester11 –no-dcgm-validation -t 1004 -d 300; sleep 30; done  

     

    • Với none strategy, tài nguyên GPU được khai báo như sau:
    1. Cú pháp: 
    
    nvidia.com/gpu: 1
    (Với none strategy, pod sẽ dùng toàn bộ tài nguyên của một card GPU) 
    1. Ví dụ deployment sử dụng gpu none strategy 
    apiVersion: apps/v1 
    kind: Deployment 
    metadata: 
      name: example-gpu-app 
    spec: 
      replicas: 1 
      selector: 
        matchLabels: 
          component: gpu-app 
      template: 
        metadata: 
          labels: 
            component: gpu-app 
        spec: 
          containers: 
            – name: gpu-container 
              securityContext: 
                capabilities: 
                  add: 
                    – SYS\_ADMIN 
              resources: 
                limits: 
                  nvidia.com/gpu: 1 
              image: nvidia/samples:dcgmproftester-2.0.10-cuda11.0-ubuntu18.04 
              command: [“/bin/sh”, “-c”] 
              args: 
                – while true; do /usr/bin/dcgmproftester11 –no-dcgm-validation -t 1004 -d 300; sleep 30; done