作业17:GPU/K8s 排障 · 模型路由配置发布 · 发布检查清单 PR(跟学 + Cursor)
作业目标:弄清本环境(或实验 K8s)GPU 型号、驱动、Operator;学会用 kubectl 看 Pod 事件里 NVIDIA 相关失败;把 模型路由配置当配置发布(改备模、回滚、审计);Cursor 根据现有 Deployment 生成 发布检查清单 PR 模板。
验收标准:
1. 能填写 GPU 盘点表(116 H20 + 207 无卡 + lab K8s Operator 判定)
2. 列出 ≥5 种 NVIDIA/GPU 相关 Event 及处理方向
3. 完成一次 LiteLLM 路由变更演练(改备模 / 回滚 / 审计记录)
4. 生成 PR 模板 MD,含发布前/后检查项
环境:现网 116.62.10.183 H20 + Docker vLLM;K8s/GPU Operator 在实验集群跟学(勿动生产推理)。
HTML:
docs/html_cursor/作业17_GPU与K8s模型路由发布_cursor.html
脚本:
scripts_cursor/作业17_GPU与K8s模型路由发布/参考 Deployment:
patches_cursor/作业17_K8s与模型路由/vllm-qwen-deployment.yaml路由配置样例:
patches_cursor/作业17_K8s与模型路由/litellm-routing-primary-backup.yamlRunbook:
作业17_模型路由配置发布Runbook_cursor.md结果:
data/homework17/
目录
- 做完长什么样
- 学习路线
- Part A · GPU / 驱动 / Operator 盘点
- Part B · kubectl 与 NVIDIA Pod 事件
- Part C · 模型路由 = 配置发布
- Part D · Cursor:发布检查清单 PR
- 完整程序
- 验收清单
做完长什么样
| 项 | 值 |
|---|---|
| 现网 GPU | 116 NVIDIA H20,Docker vllm-qwen3.6-27b,无 Operator |
| 网关路由 | LiteLLM :4000 → patches_cursor/LiteLLM部署/config.yaml |
| 主备样例 | litellm-routing-primary-backup.yaml + 作业13 fallbacks |
| K8s 参考 | vllm-qwen-deployment.yaml(nvidia.com/gpu: 1) |
| PR 产物 | data/homework17/pr_release_checklist_*.md |
| 盘点产物 | data/homework17/gpu_inventory_*.md |
学习路线
A 填 GPU 盘点:116 nvidia-smi + 实验集群 Operator 命令
B 跟读 kubectl describe / get events,背 5 类 NVIDIA 失败
C 把 LiteLLM config 当发布:改备模 → 验收 → 回滚 → 审计行
D 跑 hw17_01 从 Deployment 生成 PR 检查清单Part A · GPU / 驱动 / Operator 盘点
A1. 本环境(已落地,跟读填表)
| 问题 | 本环境答案 |
|---|---|
| GPU 型号 | NVIDIA H20(~96GB,与 mxh_env/mxh_live 共享) |
| GPU 在哪 | 116.62.10.183(hostname prod102) |
| 207 有 GPU 吗 | 无;Xinference CPU,Dify/LiteLLM 在 207 |
| 推理怎么跑 | Docker 容器 vllm-qwen3.6-27b,--gpus / runtime nvidia |
| K8s Operator | 现网未用;116 不是 K8s 调度 |
| 驱动怎么查 | 116 上 nvidia-smi(作业5/6 已用) |
116 实录命令:
ssh 116.62.10.183 "nvidia-smi --query-gpu=name,driver_version,memory.total --format=csv"
ssh 116.62.10.183 "docker ps --filter name=vllm --format '{{.Names}}\t{{.Status}}'"A2. 实验 K8s 集群(跟学 Operator)
| 组件 | 作用 | 怎么判断「已装且正常」 |
|---|---|---|
| NVIDIA GPU Operator | 驱动、device plugin、DCGM 等 CR 管理 | kubectl get pods -n gpu-operator 核心 Pod Running |
| Device Plugin | 把 GPU 报成 nvidia.com/gpu 资源 | Node status.allocatable.nvidia.com/gpu > 0 |
| Container Toolkit | 容器内可见 GPU | 无则 Event:nvidia-container-cli 错误 |
kubectl get nodes -o custom-columns=NAME:.metadata.name,GPU:.status.allocatable.nvidia\\.com/gpu
kubectl get pods -n gpu-operatorA3. 脚本盘点
python scripts_cursor/作业17_GPU与K8s模型路由发布/hw17_02_GPU与Operator盘点.py
python scripts_cursor/作业17_GPU与K8s模型路由发布/hw17_02_GPU与Operator盘点.py --ssh-host 116.62.10.183Part B · kubectl 与 NVIDIA Pod 事件
B1. 必会三条命令
NS=ai-inference
APP=vllm-qwen
# ① Pod 详情(Events 在末尾)
kubectl describe pod -n $NS -l app=$APP
# ② 命名空间事件,过滤 NVIDIA 关键词
kubectl get events -n $NS --sort-by='.lastTimestamp' \
| grep -iE 'nvidia|gpu|cuda|device-plugin|Insufficient|FailedMount|FailedScheduling'
# ③ 发布滚动状态
kubectl rollout status deployment/vllm-qwen3-6-27b -n $NSB2. 常见 NVIDIA 相关失败(背下来)
| Event / Message 关键词 | 含义 | 优先动作 |
|---|---|---|
Insufficient nvidia.com/gpu | 集群无足够 GPU 可分配 | 查节点 allocatable;释放其它 GPU Pod |
FailedScheduling + gpu | 调度失败(资源/selector/taint) | describe pod 看 Predicates;核对 nodeSelector |
UnexpectedAdmissionError | 准入失败,常伴 device plugin | 查 nvidia-device-plugin 日志;重启 DS |
CUDA driver version is insufficient | 驱动与镜像 CUDA 不匹配 | 升节点驱动或降 vLLM 镜像 |
nvidia-container-cli: initialization error | container runtime 未配 NVIDIA | 查 containerd/docker nvidia runtime |
FailedMount + driver | 驱动容器/挂载异常 | GPU Operator 驱动 Pod 是否 Ready |
Back-off restarting failed container | 容器起不来(OOM/模型路径) | kubectl logs;非 GPU 时也需区分 |
B3. 与现网 Docker 对照
| K8s 现象 | Docker 等价 |
|---|---|
| Insufficient gpu | docker run --gpus all 失败 / 显存已被占满 |
| device plugin 挂 | nvidia-smi 在宿主机正常但容器内没有 GPU |
| 调度失败 | 单机多容器抢 H20(mxh_env + vLLM)→ OOM 或极慢 |
Part C · 模型路由 = 配置发布
模型路由在本环境 = LiteLLM config.yaml(虚拟模型名 → upstream api_base + fallbacks)。 与作业13 一致:对外 primary,失败切 backup;生产 :4000 变更必须当发布。
C1. 发布流程(配置即代码)
flowchart LR A[Git 分支改 config] --> B[PR + 检查清单] B --> C[Review / diff] C --> D[备份现网 config 带时间戳] D --> E[合并 + 重启 litellm] E --> F[curl 验收 primary/backup] F --> G[写审计记录] F -->|失败| H[回滚 config + restart]
C2. 改备模(示例)
文件:patches_cursor/作业17_K8s与模型路由/litellm-routing-primary-backup.yaml
qwen3.6-27b→ primary116:8000qwen3.6-27b-backup→ backup116:8001(或降级模型)fallbacks: qwen3.6-27b → [qwen3.6-27b-backup]
测试环境先改 :4010 + 作业13 模拟上游,再上生产。
C3. 回滚
# 207 示例
cp /opt/litellm/config.yaml /opt/litellm/config.yaml.bak.$(date +%Y%m%d_%H%M%S)
# 恢复上一版
cp /opt/litellm/config.yaml.bak.YYYYMMDD_HHMMSS /opt/litellm/config.yaml
docker compose -f /opt/litellm/docker-compose.yml restart litellm
curl -sS http://127.0.0.1:4000/health/livelinessK8s Deployment 回滚:kubectl rollout undo deployment/vllm-qwen3-6-27b -n ai-inference
C4. 审计(每次发布一行)
| 时间 | 操作人 | Ticket | 变更摘要 | 回滚点 |
|---|---|---|---|---|
| 2026-08-27 10:00 | oncall | OPS-1234 | primary→8001, 增 backup fallback | config.bak / deploy rev#2 |
完整步骤:作业17_模型路由配置发布Runbook_cursor.md
Part D · Cursor:发布检查清单 PR
D1. 提示词
阅读 patches_cursor/作业17_K8s与模型路由/vllm-qwen-deployment.yaml,
生成 Python 脚本 hw17_01_发布检查清单PR模板.py:
解析 name/namespace/image/gpu limits/annotations,
输出 Markdown PR body:GPU/Operator 检查、发布前后验收、回滚命令、kubectl NVIDIA 事件命令。D2. 运行
python scripts_cursor/作业17_GPU与K8s模型路由发布/hw17_01_发布检查清单PR模板.py \
--author 完颜振江 --ticket OPS-20260827-001产物可直接贴进 GitHub/GitLab PR 描述。
D3. 参考 Deployment 要点
| 字段 | 值 | 发布时核对 |
|---|---|---|
resources.limits.nvidia.com/gpu | 1 | 与节点 allocatable 一致 |
--max-num-seqs | 8 | 与容量规划一致(汇总文档) |
--gpu-memory-utilization | 0.75 | 与 116 现网 docker 对齐 |
annotations config/release-id | 版本号 | 审计关联 |
完整程序
| 文件 | 作用 |
|---|---|
hw17_01_发布检查清单PR模板.py | 从 Deployment 生成 PR 检查清单 |
hw17_02_GPU与Operator盘点.py | GPU/Operator 对照 + SSH nvidia-smi |
vllm-qwen-deployment.yaml | 实验 K8s Deployment 样例 |
litellm-routing-primary-backup.yaml | 路由发布样例 |
验收清单
- [ ] 能说出 116 GPU 型号 H20、207 无 GPU、现网 无 Operator
- [ ] 实验集群(或文档模拟)跑过
kubectl describe pod+ events 过滤 NVIDIA - [ ] 写出 ≥5 种 GPU 相关 Event 及处理方向
- [ ] 完成 LiteLLM 路由发布演练:备份 → 改备模/fallback → 验收 → 回滚 → 审计一行
- [ ] 生成
pr_release_checklist_*.md且含发布前/后/回滚勾选项 - [ ] 未在未授权窗口改生产
:4000且无备份
相关文档
- 作业13 主备与 429:
作业13_虚拟模型主备与压测Runbook_cursor.md - LiteLLM 部署:
LiteLLM部署_cursor.md - vLLM 健康 Agent:
作业5_vLLM健康检查Agent_cursor.md - AI Infra 路线(K8s + Operator):
AI_Infra架构师成长路线图_cursor.md