k8s配置GPU感知:k8s-device-plugin的使用(已踩完坑)

news/2025/2/19 17:39:53/

1,定义

Kubernetes 的 NVIDIA 设备插件是一个 Daemonset,它允许自动:

  • 暴露集群中每个节点上的 GPU 数量
  • 跟踪 GPU 的运行状况
  • 在 Kubernetes 集群中运行支持 GPU 的容器

2,需要满足的前置条件

  • NVIDIA drivers ~= 384.81
  • nvidia-docker >= 2.0 || nvidia-container-toolkit >= 1.7.0 (>= 1.11.0 to use integrated GPUs on Tegra-based systems)
  • nvidia-container-runtime configured as the default low-level runtime
  • Kubernetes version >= 1.10

3,安装

kubect apply -f nvidia-device-plugin.yml

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:labels:name: nvidia-device-plugin-dsspec:tolerations:- 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: 10.5.5.25:8080/nvidia/k8s-device-plugin:v0.17.0-ubi9name: nvidia-device-plugin-ctrenv:- name: FAIL_ON_INIT_ERRORvalue: "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,测试

4.1 配置yaml文件,跑一个job

apiVersion: v1
kind: Pod
metadata:name: gpu-pod
spec:restartPolicy: Nevercontainers:- name: cuda-containerimage: nvcr.io/nvidia/k8s/cuda-sample:vectoradd-cuda12.5.0resources:limits:nvidia.com/gpu: 1 # requesting 1 GPUtolerations:- key: nvidia.com/gpuoperator: Existseffect: NoSchedule

4.2 查看gpu-pod的log

请添加图片描述

5 遇到的问题

安装结束后,并没有发现GPU信息,通过查看/etc/docker/daemon,发现container toolkit也已经装好,但是运行docker info发现runtime还是runc,猜想可能就是这个原因,因此设置了default-runtime,如下:

{"data-root":"/data/docker_data","insecure-registries":["192.168.237.50:8080",//私有仓库"127.0.0.0/8"],"registry-mirrors":["192.168.237.50:8080",//私有仓库"https://docker.m.daocloud.io","https://docker.unsee.tech","https://docker.1panel.live","http://mirrors.ustc.edu.cn","https://docker.chenby.cn","http://mirror.azure.cn","https://dockerpull.org","https://dockerhub.icu","https://hub.rat.dev","https://proxy.1panel.live","https://docker.1panel.top","https://docker.m.daocloud.io","https://docker.1ms.run","https://docker.ketches.cn","https://mirror,aliyuncs.com"],"runtimes":{"nvidia":{"args":[],"path":"nvidia-container-runtime"}},"default-runtime":"nvidia"
}

最终实现了k8s调用GPU


http://www.ppmy.cn/news/1572457.html

相关文章

嵌入式硬件篇---原码、补码、反码

文章目录 前言简介八进制原码、反码、补码1. 原码规则示例问题 2. 反码规则示例问题 3. 补码规则示例优点 4. 补码的运算5. 总结 十六进制原码、反码、补码1. 十六进制的基本概念2. 十六进制的原码规则示例 3. 十六进制的反码规则示例 4. 十六进制的补码规则示例 5. 十六进制补…

ORB-SLAM3的源码学习: Settings.cc:settings构造函数

前言 配置文件的相关的构造函数 1.函数声明 settings的构造函数 Settings::Settings(const std::string &configFile, const int &sensor) : bNeedToUndistort_(false), bNeedToRectify_(false), bNeedToResize1_(false), bNeedToResize2_(false) 这个构造函数接…

spring 中 AspectJ 基于 XML 的实现分析

前面的文章介绍了 spring 引入 AspectJ 之后,基于注解实现 AOP 的过程分析,今天我们来看下AspectJ 基于 XML 的 AOP 实现逻辑。 XML 的实现示例可以参考 AspectJ 对于 AOP 的实现。 aop:config 标签解析 先去 spring-aop 模块下,META-INF/…

哈希:LeetCode49. 字母异位词分组 128.最长连续序列

49. 字母异位词分组 给你一个字符串数组,请你将 字母异位词 组合在一起。可以按任意顺序返回结果列表。 字母异位词 是由重新排列源单词的所有字母得到的一个新单词。 示例 1: 输入: strs ["eat", "tea", "tan", "ate",…

网页五子棋——用户模块

目录 用户注册 注册时序图 约定前后端交互接口 后端实现 controller 层接口设计 service 层接口设计 dao 层接口设计 全局异常处理 接口测试 前端实现 register.html css common.css register.css js 注册模块测试 用户登录 登录时序图 约定前后端交互接口 …

Python Pandas(11):Pandas 数据可视化

数据可视化是数据分析中的重要环节,它帮助我们更好地理解和解释数据的模式、趋势和关系。通过图形、图表等形式,数据可视化将复杂的数字和统计信息转化为易于理解的图像,从而便于做出决策。Pandas 提供了与 Matplotlib 和 Seaborn 等可视化库…

Pytest自动化测试框架总结

🍅 点击文末小卡片,免费获取软件测试全套资料,资料在手,涨薪更快 1、pytest简介 pytest是Python的一种单元测试框架,与python自带的unittest测试框架类似,但是比unittest框架使用起来更简洁,效…

什么是FCC认证

联邦通信委员会(FCC)认证是美国一种强制性的认证,确保电子设备在上市前符合特定标准。 联邦通讯委员会(FCC)----管理进口和使用无线电频率装置,包括电脑、传真机、电子装置、无线电接收和传输设备、无线电…