npu-operator:基于 Kubernetes Operator Framework 的昇腾NPU管理项目

为openFuyao实现NPU资源管理、工作负载的优化调度、训推任务的容器化支持,使能AI作业以容器形式部署并运行在NPU设备上

分支17Tags3
文件最后提交记录最后更新时间
3 个月前
2 个月前
9 个月前
3 个月前
3 个月前
6 个月前
1 年前
18 天前
1 年前
1 年前
1 年前
1 年前
11 个月前
7 个月前
1 年前
1 个月前
18 天前
10 个月前
10 个月前

NPU Operator

特性介绍

Kubernetes通过设备插件提供对特殊硬件资源(如昇腾NPU)的访问。但是配置和管理具有这些硬件资源的节点需要配置多个软件组件(如驱动程序、容器运行时或其他库),这些组件安装复杂困难且容易出错。NPU Operator使用Kubernetes中的Operator Framework来自动管理配置昇腾设备所需的所有软件组件。这些组件包括昇腾驱动程序和固件,使能构建集群全流程运行,支持集群作业调度、运维监控、故障恢复等功能的MindCluster设备插件。通过安装相应的组件,可以实现NPU资源管理、工作负载的优化调度、训推任务的容器化支持,使能AI作业以容器形式部署并运行在NPU设备上。

安装部署

在线安装

前提条件

  • 当前计算机上有kubectl和Helm CLI,或集群中有可配置的应用商店或仓库。

  • 请确认环境中含有bash工具,否则可能导致驱动固件安装脚本解析失败。

  • Kubernetes集群中运行NPU工作负载的所有工作节点或节点组运行的操作系统版本都需满足openEuler 22.03 LTS或者Ubuntu 22.04(ARM架构)。

  • 对于仅运行CPU工作负载的工作节点或节点组,节点可以运行任何操作系统,因为NPU Operator不会对非NPU工作负载的节点执行任何配置或管理。

  • 当前NPU Operator所安装的组件需要运行环境满足的NPU芯片型号为910B和310P。具体OS和硬件配套关系请参考MindCluster文档

二进制安装

1.拉取项目安装包。

helm pull oci://cr.openfuyao.cn/charts/npu-operator xxx

其中xxx需替换为具体项目安装包版本,如0.0.0-latest。拉取到的安装包为压缩包形式。

2.安装部署。

以命名空间default、release名称npu-operator为例,在安装包所在的目录下,可直接通过以下命令进行安装。

helm install npu-operator npu-operator-xxx.tgz -n default

源码安装

1.从仓库拉取项目。

git clone -b xxx https://gitcode.com/openfuyao/npu-operator.git

其中xxx指的是代码的分支。

2.安装部署。

以命名空间default、release名称npu-operator为例,在npu-operator同级目录下执行如下命令。

cd npu-operator/charts/npu-operator
helm install -n default npu-operator .

参数配置

详细的参数配置说明请参考npu-operator用户手册的常见定制选项章节。

离线安装

前提条件

  • 当前计算机上有kubectl和Helm CLI,或集群中有可配置的应用商店或仓库。

  • 请确认环境中含有bash工具,否则可能导致驱动固件安装脚本解析失败。

  • Kubernetes集群中运行NPU工作负载的所有工作节点或节点组运行的操作系统版本都需满足openEuler 22.03 LTS或者Ubuntu 22.04(ARM架构)。

  • 对于仅运行CPU工作负载的工作节点或节点组,节点可以运行任何操作系统,因为NPU Operator不会对非NPU工作负载的节点执行任何配置或管理。

  • 当前NPU Operator所安装的组件需要运行环境满足的NPU芯片型号为910B和310P。具体OS和硬件配套关系请参考MindCluster文档

  • 下载离线镜像,将需要安装的组件所用到的全部镜像下载到本地。详情可见表1。

  • 准备驱动固件zip包和MindIO组件的zip包:

    • 下载驱动固件zip包:可前往npu-driver-installer的代码仓,找到对应驱动固件版本号的config.json文件,按照对应节点的NPU型号、OS架构单击相应链接来下载对应的驱动固件压缩包;910C型号NPU支持离线驱动固件安装,需要从昇腾社区-固件与驱动下载自行下载,其余型号的驱动固件zip包也可前往上述链接进行下载。
    • 下载MindIO组件zip包:可前往npu-node-provision的代码仓,找到组件对应版本号的config.json文件,按照对应节点的NPU型号、OS架构,单击相应链接来下载对应的SDK压缩包。
  • 将驱动固件包的zip文件放到需要进行离线安装的节点路径下:/tmp/driver_pkg/,该路径可在values.yaml的driver.env字段中自定义修改。

  • 将MindIO组件的zip包放到需要进行离线安装的节点路径下:/opt/openFuyao/mindio/

  • 检查待安装节点中是否含有以下工具:

    • 如果使用的包管理工具为yum,则需要安装的pkg为:"jq wget unzip which initscripts coreutils findutils gawk e2fsprogs util-linux net-tools pciutils gcc make automake autoconf libtool git patch kernel-devel-(uname−r)kernel−headers−(uname -r) kernel-headers-(uname -r) dkms"
      可使用如下命令进行检测。

      pkgs=(jq wget unzip which initscripts coreutils findutils gawk e2fsprogs util-linux net-tools pciutils gcc make automake autoconf libtool git patch kernel-devel-$(uname -r) kernel-headers-$(uname -r) dkms); rpm -q "${pkgs[@]}" >/dev/null || rpm -q "${pkgs[@]}" | grep "is not installed"
      
    • 如果使用的包管理工具为apt-get,需要安装的pkg为:"jq wget unzip debianutils coreutils findutils gawk e2fsprogs util-linux net-tools pciutils gcc make automake autoconf libtool git patch dkms linux-headers-$(uname -r)"
      可使用如下命令进行检测。

      pkgs=(jq wget unzip debianutils coreutils findutils gawk e2fsprogs util-linux net-tools pciutils gcc make automake autoconf libtool git patch dkms linux-headers-$(uname -r)); dpkg-query -W -f='${Package}\t${Status}\n' "${pkgs[@]}" 2>&1 | grep -Ev "install ok installed"
      
    • 如果使用的包管理工具为dnf,则需要安装的pkg为:"jq wget unzip which initscripts coreutils findutils gawk e2fsprogs util-linux net-tools pciutils gcc make automake autoconf libtool git patch kernel-devel-(uname−r)kernel−headers−(uname -r) kernel-headers-(uname -r) dkms"
      可使用如下命令进行检测。

      pkgs=(jq wget unzip which initscripts coreutils findutils gawk e2fsprogs util-linux net-tools pciutils gcc make automake autoconf libtool git patch kernel-devel-$(uname -r) kernel-headers-$(uname -r) dkms); rpm -q "${pkgs[@]}" >/dev/null || rpm -q "${pkgs[@]}" | grep "is not installed"
      

表1 组件涉及到的镜像列表

组件 镜像
昇腾驱动和固件 cr.openfuyao.cn/openfuyao/npu-driver-installer:latest
ascend-docker-runtime cr.openfuyao.cn/openfuyao/ascend-docker-runtime:v7.3.0
cr.openfuyao.cn/openfuyao/npu-container-toolkit:latest
clusterd hub.oepkgs.net/openfuyao/ascendhub/clusterd:v7.3.0
device-plugin hub.oepkgs.net/openfuyao/ascendhub/ascend-k8sdeviceplugin:v7.3.0
hub.oepkgs.net/openfuyao/busybox:1.36.1
mindio cr.openfuyao.cn/openfuyao/npu-node-provision:latest
noded hub.oepkgs.net/openfuyao/ascendhub/noded:v7.3.0
npu-exporter hub.oepkgs.net/openfuyao/ascendhub/npu-exporter:v7.3.0
resilience-controller hub.oepkgs.net/openfuyao/ascendhub/resilience-controller:v7.1.RC1
ascend-operator hub.oepkgs.net/openfuyao/ascendhub/ascend-operator:v7.3.0
hub.oepkgs.net/openfuyao/busybox:1.36.1
volcano hub.oepkgs.net/openfuyao/ascendhub/vc-controller-manager:v1.9.0-v7.3.0
hub.oepkgs.net/openfuyao/ascendhub/vc-scheduler:v1.9.0-v7.3.0
hub.oepkgs.net/openfuyao/busybox:1.36.1
npu-operator cr.openfuyao.cn/openfuyao/npu-operator:latest
node-feature-discovery hub.oepkgs.net/openfuyao/nfd/node-feature-discovery:v0.16.4
npu-feature-discovery cr.openfuyao.cn/openfuyao/npu-feature-discovery:latest

其中镜像tag可根据组件不同版本自定义修改。

二进制安装

1.拉取项目安装包。

helm pull oci://cr.openfuyao.cn/charts/npu-operator xxx

其中xxx需替换为具体项目安装包版本,如0.0.0-latest。拉取到的安装包为压缩包形式。

2.安装部署。

以命名空间default、release名称npu-operator为例,在安装包所在的目录下,可直接通过以下命令进行安装。

helm install npu-operator npu-operator-xxx.tgz -n default

源码安装

1.从仓库拉取项目。

git clone -b xxx https://gitcode.com/openfuyao/npu-operator.git

其中xxx指的是gitcode仓库源代码的分支。

2.安装部署。

以命名空间default、release名称npu-operator为例,在npu-operator同级目录下执行如下命令。

cd npu-operator/charts/npu-operator
helm install -n default npu-operator .

根据集群中提前准备的离线镜像对应的tag,同步在npu-operator/charts/npu-operator/values.yaml中,对组件镜像进行修改,以确保组件的镜像与已导入集群的离线镜像相同。

本地构建

镜像构建

构建参数

  • GOPRIVATE:配置Go语言私有仓库,相当于GOPRIVATE环境变量。
  • COMMIT:当前git commit的哈希值。
  • VERSION:组件版本。
  • SOURCE_DATE_EPOCH:镜像rootfs的时间戳。

构建命令

  • 构建并推送到指定OCI仓库。

    使用docker
    docker buildx build . -f <path/to/dockerfile> \
        -o type=image,name=<oci/repository>:<tag>,oci-mediatypes=true,rewrite-timestamp=true,push=true \
        --platform=linux/amd64,linux/arm64 \
        --provenance=false \
        --build-arg=GOPRIVATE=gopkg.openfuyao.cn \
        --build-arg=COMMIT=$(git rev-parse HEAD) \
        --build-arg=VERSION=0.0.0-latest \
        --build-arg=SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct)
    
    使用nerdctl
    nerdctl build . -f <path/to/dockerfile> \
        -o type=image,name=<oci/repository>:<tag>,oci-mediatypes=true,rewrite-timestamp=true,push=true \
        --platform=linux/amd64,linux/arm64 \
        --provenance=false \
        --build-arg=GOPRIVATE=gopkg.openfuyao.cn \
        --build-arg=COMMIT=$(git rev-parse HEAD) \
        --build-arg=VERSION=0.0.0-latest \
        --build-arg=SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct)
    

    其中,<path/to/dockerfile>为Dockerfile路径,<oci/repository>为镜像地址,<tag>为镜像tag。

  • 构建并导出OCI Layout到本地tarball。

    使用docker
    docker buildx build . -f <path/to/dockerfile> \
        -o type=oci,name=<oci/repository>:<tag>,dest=<path/to/oci-layout.tar>,rewrite-timestamp=true \
        --platform=linux/amd64,linux/arm64 \
        --provenance=false \
        --build-arg=GOPRIVATE=gopkg.openfuyao.cn \
        --build-arg=COMMIT=$(git rev-parse HEAD) \
        --build-arg=VERSION=0.0.0-latest \
        --build-arg=SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct)
    
    使用nerdctl
    nerdctl build . -f <path/to/dockerfile> \
        -o type=oci,name=<oci/repository>:<tag>,dest=<path/to/oci-layout.tar>,rewrite-timestamp=true \
        --platform=linux/amd64,linux/arm64 \
        --provenance=false \
        --build-arg=GOPRIVATE=gopkg.openfuyao.cn \
        --build-arg=COMMIT=$(git rev-parse HEAD) \
        --build-arg=VERSION=0.0.0-latest \
        --build-arg=SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct)
    

    其中,<path/to/dockerfile>为Dockerfile路径,<oci/repository>为镜像地址,<tag>为镜像tag,path/to/oci-layout.tar为tar包路径。

  • 构建并导出镜像rootfs到本地目录。

    使用docker
    docker buildx build . -f <path/to/dockerfile> \
        -o type=local,dest=<path/to/output>,platform-split=true \
        --platform=linux/amd64,linux/arm64 \
        --provenance=false \
        --build-arg=GOPRIVATE=gopkg.openfuyao.cn \
        --build-arg=COMMIT=$(git rev-parse HEAD) \
        --build-arg=VERSION=0.0.0-latest
    
    使用nerdctl
    nerdctl build . -f <path/to/dockerfile> \
        -o type=local,dest=<path/to/output>,platform-split=true \
        --platform=linux/amd64,linux/arm64 \
        --provenance=false \
        --build-arg=GOPRIVATE=gopkg.openfuyao.cn \
        --build-arg=COMMIT=$(git rev-parse HEAD) \
        --build-arg=VERSION=0.0.0-latest
    

    其中,<path/to/dockerfile>为Dockerfile路径,path/to/output为本地目录路径。

Helm Chart构建

  • 打包Helm Chart。

    helm package <path/to/chart> -u \
        --version=0.0.0-latest \
        --app-version=openFuyao-v25.09
    

    其中,<path/to/chart>为Chart文件夹路径。

  • 推送Chart包到指定OCI仓库。

    helm push <path/to/chart.tgz> oci://<oci/repository>:<tag>
    

    其中,<path/to/chart.tgz>为Chart包路径,<oci/repository>为Chart包推送地址,<tag>为Chart包tag。

项目介绍

为openFuyao实现NPU资源管理、工作负载的优化调度、训推任务的容器化支持,使能AI作业以容器形式部署并运行在NPU设备上

定制我的领域