技术博客

昇腾 NPU 接入 Kubernetes 运维全流程

从 ascend-device-plugin 安装、CANN 软件栈配置、NPU 健康检查到集群故障隔离,完整覆盖华为昇腾 910B/950 系列 NPU 在 Kubernetes 生产集群中的运维实践。

昇腾NPUKubernetesCANN国产GPU华为

随着国产 AI 算力的政策驱动与生态成熟,华为昇腾 NPU 在国内数据中心的部署规模快速扩大。2026 年 Q1,昇腾 950 系列已发布 950PR 版本,互联带宽提升至 2TB/s,FP8/FP4 精度支持进一步增强。与此同时,腾讯、字节跳动等大厂已开始大规模导入国产算力,运维团队需要掌握昇腾 NPU 在 Kubernetes 中的完整运维路径。

昇腾生态软件栈架构

应用层(PyTorch / MindSpore / MindIE 推理服务)

MindCluster 集群调度 / Kubernetes 调度层

ascend-device-plugin(NPU 资源注册与分配)

CANN(Compute Architecture for Neural Networks)

NPU 硬件驱动(Ascend Driver)

昇腾 910B / 950 系列 NPU 硬件

硬件与系统要求

项目 要求
NPU 型号 昇腾 910B、910C、950PR
操作系统 openEuler 22.03 LTS / Ubuntu 22.04
驱动版本 Ascend HDK ≥ 24.1.RC3
CANN 版本 ≥ 8.0.0
Kubernetes ≥ 1.27
Container Runtime containerd ≥ 1.7 或 Docker ≥ 25

宿主机环境配置

安装昇腾驱动

# 以 910B 为例,下载对应 HDK 包后安装
chmod +x Ascend-hdk-910b-npu-driver_24.1.RC3_linux-aarch64.run
./Ascend-hdk-910b-npu-driver_24.1.RC3_linux-aarch64.run --full

# 安装完成后检查驱动
npu-smi info
# 期望输出类似 nvidia-smi 的设备信息表格

# 查看 NPU 设备文件
ls /dev/davinci*
# /dev/davinci0  /dev/davinci1  ...  /dev/davinci_manager  /dev/devmm_svm

安装 CANN 软件栈

# 安装 CANN 工具包(Toolkit)
./Ascend-cann-toolkit_8.0.0_linux-aarch64.run --install

# 配置环境变量(写入 /etc/profile.d/cann.sh)
cat > /etc/profile.d/cann.sh << 'EOF'
export ASCEND_HOME=/usr/local/Ascend
export ASCEND_TOOLKIT_HOME=${ASCEND_HOME}/ascend-toolkit/latest
export PATH=${ASCEND_TOOLKIT_HOME}/bin:${PATH}
export LD_LIBRARY_PATH=${ASCEND_TOOLKIT_HOME}/lib64:${LD_LIBRARY_PATH}
export ASCEND_OPP_PATH=${ASCEND_TOOLKIT_HOME}/opp
EOF
source /etc/profile.d/cann.sh

# 验证 CANN 安装
ascend_cann_check.sh

配置 Container Runtime

containerd 需要配置 device mapping 才能将 NPU 设备传入容器:

# 安装 Ascend Container Runtime(华为官方)
./Ascend-cann-nnrt_8.0.0_linux-aarch64.run --install

# 修改 containerd 配置,使用 ascend-docker-runtime
cat > /etc/containerd/config.toml << 'EOF'
version = 2

[plugins."io.containerd.grpc.v1.cri".containerd.runtimes]
  [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc]
    runtime_type = "io.containerd.runc.v2"
  [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.ascend]
    runtime_type = "io.containerd.runc.v2"
    [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.ascend.options]
      BinaryName = "/usr/local/Ascend/ascend-toolkit/latest/tools/docker_daemon_tools/ascend-docker-runtime"
EOF

systemctl restart containerd

部署 ascend-device-plugin

ascend-device-plugin 以 DaemonSet 形式运行在每个 NPU 节点,将 /dev/davinci* 设备注册为 Kubernetes 可调度资源。

方式一:官方 Helm Chart

helm repo add ascend https://ascend.github.io/ascend-device-plugin
helm repo update

helm upgrade --install ascend-device-plugin ascend/ascend-device-plugin \
  --namespace kube-system \
  --set image.tag=v5.0.0 \
  --set npu.enabled=true

方式二:直接应用 YAML

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: ascend-device-plugin
  namespace: kube-system
spec:
  selector:
    matchLabels:
      app: ascend-device-plugin
  template:
    metadata:
      labels:
        app: ascend-device-plugin
    spec:
      tolerations:
      - key: "npu.huawei.com"
        operator: Exists
        effect: NoSchedule
      containers:
      - name: device-plugin
        image: ascendhub.huawei.com/public-ascendhub/ascend-k8sdeviceplugin:v5.0.0
        resources:
          limits:
            memory: 300Mi
            cpu: 100m
        volumeMounts:
        - name: device-plugin
          mountPath: /var/lib/kubelet/device-plugins
        - name: ascend-driver
          mountPath: /usr/local/Ascend
        - name: dev
          mountPath: /dev
        securityContext:
          privileged: true
      volumes:
      - name: device-plugin
        hostPath:
          path: /var/lib/kubelet/device-plugins
      - name: ascend-driver
        hostPath:
          path: /usr/local/Ascend
      - name: dev
        hostPath:
          path: /dev
      nodeSelector:
        npu: "true"

给 NPU 节点打标签并加污点:

kubectl label node <npu-node> npu=true
kubectl taint node <npu-node> npu.huawei.com/npu=:NoSchedule

验证资源注册

kubectl describe node <npu-node> | grep -A5 "huawei.com"
# Capacity:
#   huawei.com/Ascend910B:   8
# Allocatable:
#   huawei.com/Ascend910B:   8

部署推理服务示例

以 MindIE 推理服务部署 Qwen3-32B 为例:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mindie-qwen3-32b
  namespace: ai-inference
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mindie-qwen3
  template:
    metadata:
      labels:
        app: mindie-qwen3
    spec:
      tolerations:
      - key: npu.huawei.com/npu
        operator: Exists
        effect: NoSchedule
      containers:
      - name: mindie
        image: ascendhub.huawei.com/public-ascendhub/mindie:2.0.0-cann8.0
        resources:
          limits:
            huawei.com/Ascend910B: "4"
        env:
        - name: ASCEND_VISIBLE_DEVICES
          value: "0,1,2,3"
        - name: MS_ASCEND_CHECK_OVERFLOW_MODE
          value: "SATURATE_MODE"
        command:
        - mindie-server
        - --model-path=/models/qwen3-32b
        - --npu-count=4
        - --port=8080
        volumeMounts:
        - name: models
          mountPath: /models
        - name: npu-log
          mountPath: /var/log/npu
      volumes:
      - name: models
        nfs:
          server: 192.168.1.100
          path: /data/models
      - name: npu-log
        hostPath:
          path: /var/log/npu

NPU 健康检查与故障诊断

oam-tools 集群巡检

CANN 官方提供 oam-tools 工具集用于 NPU 集群运维:

# 批量健康检查(集群中所有节点)
kubectl create job npu-health-check --image=ascendhub.huawei.com/public-ascendhub/oam-tools:latest \
  -- oam-cli check --all-nodes

# 查看检查结果
kubectl logs job/npu-health-check

# 单节点详细检查
ssh <npu-node> "oam-cli check --detail"

npu-smi 常用诊断命令

# 查看所有 NPU 状态
npu-smi info

# 查看 NPU 温度和功耗
npu-smi info -t usages -i 0

# 查看 NPU 显存使用
npu-smi info -t memory -i 0

# 查看错误日志
npu-smi info -t errors -i 0

# 查看 NPU 拓扑(HCCS 互联)
npu-smi info -t topo

常见故障与处理

故障 1:Pod 无法分配 NPU,一直 Pending

# 检查 device-plugin 日志
kubectl logs -n kube-system -l app=ascend-device-plugin --tail=100

# 检查设备文件是否存在
ls -la /dev/davinci* /dev/davinci_manager

# 重启 device-plugin
kubectl rollout restart daemonset/ascend-device-plugin -n kube-system

故障 2:容器内看不到 NPU

# 进入容器检查
kubectl exec -it <pod-name> -- bash
ls /dev/davinci*

# 若无设备文件,检查 runtime 配置
containerd config dump | grep -A5 ascend

# 确认 Pod 使用了正确的 runtimeClassName(如有配置)
kubectl get pod <pod-name> -o jsonpath='{.spec.runtimeClassName}'

故障 3:CANN 算子运行报错

# 查看 CANN 日志
cat /var/log/npu/slog/host-0/

# 开启 CANN 详细日志
export ASCEND_SLOG_PRINT_TO_STDOUT=1
export ASCEND_GLOBAL_LOG_LEVEL=0   # 0=DEBUG, 1=INFO, 2=WARNING, 3=ERROR

节点故障隔离流程

当某个 NPU 节点出现不可恢复错误时,执行以下隔离操作:

# 1. 标记节点不可调度(新 Pod 不再调度到此节点)
kubectl cordon <npu-node>

# 2. 驱逐节点上现有 Pod(保留 DaemonSet)
kubectl drain <npu-node> \
  --ignore-daemonsets \
  --delete-emptydir-data \
  --grace-period=120

# 3. 给节点打故障标签,便于后续追踪
kubectl label node <npu-node> npu.health=unhealthy

# 4. 通知硬件维护团队处理
# 5. 维修完成后解除隔离
kubectl uncordon <npu-node>
kubectl label node <npu-node> npu.health=healthy --overwrite

Prometheus 监控

昇腾提供 ascend-exporter 组件(部分场景需自行集成 npu-smi 指标):

# 参考 ServiceMonitor 配置
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: ascend-npu-monitor
  namespace: monitoring
spec:
  selector:
    matchLabels:
      app: ascend-exporter
  endpoints:
  - port: metrics
    interval: 30s
    path: /metrics

核心告警规则:

groups:
- name: ascend-npu
  rules:
  - alert: NpuTemperatureHigh
    expr: ascend_npu_temperature_celsius > 85
    for: 5m
    labels:
      severity: warning
    annotations:
      summary: "NPU {{ $labels.device }} 温度过高:{{ $value }}°C"

  - alert: NpuMemoryNearFull
    expr: ascend_npu_memory_used_bytes / ascend_npu_memory_total_bytes > 0.90
    for: 2m
    labels:
      severity: warning
    annotations:
      summary: "NPU {{ $labels.device }} 显存使用率超 90%"

小结

昇腾 NPU 接入 Kubernetes 的核心路径:宿主机装驱动+CANN → 配置 Container Runtime → 部署 ascend-device-plugin → 业务 Pod 申请 huawei.com/Ascend* 资源。日常运维重点在于通过 npu-smioam-tools 做健康巡检,结合 Prometheus 告警做主动监控,配合节点 cordon/drain 做故障隔离。随着 DeepSeek-V4 等大模型在昇腾上的首日适配,CANN 生态的成熟度已大幅提升,是信创合规场景下的主要选择。