k8s pod使用gpu前提

  1. k8s节点有gpu显卡
  2. k8s节点安装gpu显卡驱动
  3. k8s节点docker或containerd运行时使用nvidia-container-runtime
  4. k8s部署gpu device plugin daemonset

1.安装gpu显卡驱动

查看节点显卡类型

nvidia-smi  -L
GPU 0: Tesla V100-SXM2-32GB (UUID: GPU-f2b15a66-0630-5f77-1f17-28abb3854f1c)# 忘记没安装驱动,用不了上面命令,使用
lspci | grep -i nvidia
00:03.0 3D controller: NVIDIA Corporation Device 1eb8 (rev a1)
00:04.0 3D controller: NVIDIA Corporation Device 1eb8 (rev a1)

根据 1eb8到这个网站查
http://pci-ids.ucw.cz/mods/PC/10de?action=help?help=pci

根据型号到这个网站查找驱动安装程序
https://www.nvidia.com/Download/Find.aspx#

# 下载
wget https://us.download.nvidia.com/tesla/515.65.01/NVIDIA-Linux-x86_64-515.65.01.runchmod +x NVIDIA-Linux-x86_64-515.65.01.run# 上述安装程序依赖这些包,安装
apt install gcc linux-kernel-headers dkms
sh NVIDIA-Linux-x86_64-515.65.01.run --ui=none --disable-nouveau --no-install-libglvnd --dkms -s# 使用下面命令验证是否安装成功。
nvidia-smi
Thu Nov  3 19:17:50 2022
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 515.65.01    Driver Version: 515.65.01    CUDA Version: 11.7     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  Tesla V100-SXM2...  On   | 00000000:00:08.0 Off |                    0 |
| N/A   36C    P0    37W / 300W |      4MiB / 32768MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------++-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|    0   N/A  N/A      1499      G   /usr/lib/xorg/Xorg                  4MiB |
+-----------------------------------------------------------------------------+

2. 安装nvidia-container-runtime

curl -s -L https://nvidia.github.io/nvidia-container-runtime/gpgkey | sudo apt-key add -curl -s -L https://nvidia.github.io/nvidia-container-runtime/$(. /etc/os-release;echo $ID$VERSION_ID)/nvidia-container-runtime.list | sudo tee /etc/apt/sources.list.d/nvidia-container-runtime.listapt updateapt install nvidia-container-runtime -y

2.1修改默认运行时

2.2 cri为docker

修改/etc/docker/daemon.json,增加default-runtime,runtimes配置.

{"default-runtime": "nvidia","runtimes": {"nvidia": {"path": "/usr/bin/nvidia-container-runtime","runtimeArgs": []}},"registry-mirrors": ["https://docker.mirrors.ustc.edu.cn/","https://hub-mirror.c.163.com/"],"max-concurrent-downloads": 10,"log-driver": "json-file","log-level": "warn","log-opts": {"max-size": "10m","max-file": "3"},"insecure-registries":["127.0.0.1","192.168.12.12:8888"],"data-root":"/data/docker","features":{"buildkit": true}
}

重启
systemctl restart docker

2.2 cri为containerd

修改/etc/containerd/config.toml,如果文件不存在
生成默认配置文件

mkdir /etc/containerd
containerd config default > /etc/containerd/config.toml
vi /etc/containerd/config.toml
...[plugins."io.containerd.grpc.v1.cri".containerd]snapshotter = "overlayfs"default_runtime_name = "runc"no_pivot = false
...[plugins."io.containerd.grpc.v1.cri".containerd.runtimes][plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc]runtime_type = "io.containerd.runtime.v1.linux" # 将此处 runtime_type 的值改成 io.containerd.runtime.v1.linux
...[plugins."io.containerd.runtime.v1.linux"]shim = "containerd-shim"runtime = "nvidia-container-runtime" # 将此处 runtime 的值改成 nvidia-container-runtime
...

重启
systemctl restart containerd

3. 部署nivdia-device-plugin

kubectl apply -f nvidia-device-plugin.yaml

# Copyright (c) 2019, NVIDIA CORPORATION.  All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.apiVersion: apps/v1
kind: DaemonSet
metadata:name: nvidia-device-plugin-daemonsetnamespace: kube-system
spec:selector:matchLabels:name: nvidia-device-plugin-dsupdateStrategy:type: RollingUpdatetemplate:metadata:# This annotation is deprecated. Kept here for backward compatibility# See https://kubernetes.io/docs/tasks/administer-cluster/guaranteed-scheduling-critical-addon-pods/annotations:scheduler.alpha.kubernetes.io/critical-pod: ""labels:name: nvidia-device-plugin-dsspec:tolerations:# This toleration is deprecated. Kept here for backward compatibility# See https://kubernetes.io/docs/tasks/administer-cluster/guaranteed-scheduling-critical-addon-pods/- key: CriticalAddonsOnlyoperator: Exists- key: nvidia.com/gpuoperator: Existseffect: NoSchedule# Mark this pod as a critical add-on; when enabled, the critical add-on# scheduler reserves resources for critical add-on pods so that they can# be rescheduled after a failure.# See https://kubernetes.io/docs/tasks/administer-cluster/guaranteed-scheduling-critical-addon-pods/priorityClassName: "system-node-critical"containers:- image: nvidia/k8s-device-plugin:v0.7.1name: nvidia-device-plugin-ctrargs: ["--fail-on-init-error=false"]securityContext:allowPrivilegeEscalation: falsecapabilities:drop: ["ALL"]volumeMounts:- name: device-pluginmountPath: /var/lib/kubelet/device-pluginsvolumes:- name: device-pluginhostPath:path: /var/lib/kubelet/device-plugins

4. 查看kubelet是否识别gpu

查看pod是否正常启动
kubectl get pod -n kube-system -o wide

describe node查看是否识别gpu
kubectl describe node vm-1-5-ubuntu

测试gpu pod启动
kubectl apply -f gpu-pod.yaml


apiVersion: v1
kind: Pod
metadata:name: gpu-pod
spec:containers:- name: cuda-containerimage: nvidia/cuda:9.0-develresources:limits:nvidia.com/gpu: 1- name: digits-containerimage: nvidia/digits:6.0resources:limits:nvidia.com/gpu: 1

5. gpu共享

以上方式为独占gpu,GPU资源在节点上是以个数暴露给kubernetes集群来进行调度的,也就是说如果有两个后端应用pod需要使用到GPU资源,但集群节点上只有一张GPU物理卡的情况下,会导致两个后端应用容器中仅有一个可以正常运行,另一个pod则会处于pending状态。

gpu共享的配置阿里云和ucloud等都有对应文档配置,非云集群网上也有开源解决方案。

k8spod使用gpu相关推荐

  1. K8S调用GPU资源配置指南

    06-09 K8S调用GPU资源配置指南 时间 版本号 修改描述 修改人 2022年6月9日15:33:12 V0.1 新建K8S调用GPU资源配置指南, 编写了Nvidia驱动安装过程 2022年6 ...

  2. docker 配置使用宿主机的GPU(ubuntu16.04+cuda10.0+cudnn7)

    1. 安装 Docker 卸载旧版本 Docker sudo apt-get remove docker docker-engine docker.io containerd runc 安装新版本 s ...

  3. python 虚拟环境 tensorflow GPU

    拿到一个新的容器之后,怎么创建一个独立的GPU训练环境呢?之前弄的时候总是零零散散的,现在把它总结在这里,供自己以及有需要的朋友查阅. conda创建 1.1 下载anaconda wget -c h ...

  4. CUDA之nvidia-smi命令详解---gpu

    nvidia-smi是用来查看GPU使用情况的.我常用这个命令判断哪几块GPU空闲,但是最近的GPU使用状态让我很困惑,于是把nvidia-smi命令显示的GPU使用表中各个内容的具体含义解释一下. ...

  5. pytorch利用多个GPU并行计算多gpu

    版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/Answer3664/article/d ...

  6. pytorch 多GPU训练总结(DataParallel的使用)

    版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/weixin_40087578/arti ...

  7. Pytorch - GPU ID 指定 pytorch gpu 指定

    PyTorch 关于多 GPUs 时的指定使用特定 GPU. PyTorch 中的 Tensor,Variable 和 nn.Module(如 loss,layer和容器 Sequential) 等可 ...

  8. pytorch中查看gpu信息

    其他:windows使用nvidia-smi查看gpu信息 为什么将数据转移至GPU的方法叫做.cuda而不是.gpu,就像将数据转移至CPU调用的方法是.cpu?这是因为GPU的编程接口采用CUDA ...

  9. Google Colab 免费GPU服务器使用教程 挂载云端硬盘

    一.前言 二.Google Colab特征 三.开始使用 3.1在谷歌云盘上创建文件夹 3.2创建Colaboratory 3.3创建完成 四.设置GPU运行 五.运行.py文件 5.1安装必要库 5 ...

最新文章

  1. asp.net 防注入
  2. Android BaseAdapter 例子
  3. 安卓setclicklistener函数没有_金主脚本按键精灵安卓按键初体验—乱斗西游2自动签到...
  4. DL之Perceptron:Perceptron感知器(感知机/多层感知机/人工神经元)的简介、原理、案例应用(相关配图)之详细攻略
  5. 【PAT笔记】数学问题——素数和质因数
  6. DB2快速入门的捷径pdf
  7. 最长连续序列Python解法
  8. pca 主成分分析_六分钟的主成分分析(PCA)的直观说明。
  9. VMWare tools的安装过程及文件共享设置
  10. Tomcat异常:The Tomcat server configuration at\Servers\Tomcat v9.0 Server at localhost-c
  11. windows安装使用SQLlite并在C#调用SQLlite开发
  12. [翻译] ASP.NET MVC Framework控制器操作安全性
  13. 一道经典面试题的不同解法
  14. JS 表单submit() 提交无效的问题
  15. 干货 | Spark Streaming 和 Flink 详细对比
  16. C02014010宋明妤信息论作业
  17. 百家企业短信网关(背景及核心代码)-1-同时对接多家短信公司的开源免费代码
  18. 跟着团子学SAP PS:项目模版搭建 CJ91/CJ92/CJ93/CN01/CN02/CN03/CN11/CN12/CN13
  19. 2020年Andorid很详细的基础面试题
  20. css中按钮变色,CSS控制按钮变色(有图有真相)

热门文章

  1. 异步AsyncTask,怎样停止AsyncTask和Thread
  2. 昨天我请教了几位大佬,他们告诉我要这样学习编程!
  3. OSI七层模型与TCP/IP四层模型详解
  4. [易飞]录入信息传递设置信息
  5. 今日头条2018.8.12笔试题总结
  6. 深度学习数学基础之激活函数与导数
  7. 对于学it的来说,软考的高级证书难考吗,难度大吗?
  8. css 层叠样式表详解
  9. 《第一行代码》总结之简介、Activity(一)
  10. 北航操作系统课程-第一次作业-操作系统引论1