llm deployment k8s

LLM Kubernetes 部署指南:GPU 调度与弹性扩缩容

为什么 LLM 需要专门的 K8s 部署方案 LLM 推理服务与传统 Web 服务有本质区别: 显存约束:7B 模型需要 ~14GB 显存,70B 模型需要 ~140GB 显存,且显存是最大的资源瓶颈 冷启动慢:模型加载到 GPU 需要 30-120 秒 请求特性:单次请求可能持续 30-300 秒(流式输出),与 HTTP 常规超时机制冲突 异构硬件:不同模型需要不同 GPU 类型(推理用 T4/A10,训练用 A100/H100) 这些特性决定了标准 K8s 部署方式(HPA + 滚动更新)并不适用。 整体架构 ┌─────────────────────────────────────────────────────┐ │ Ingress / Gateway │ ├─────────────────────────────────────────────────────┤ │ LLM Gateway (路由/限流) │ │ (LiteLLM / APISIX / Higress) │ ├──────────────┬──────────────┬──────────────────────┤ │ GPU Pool 1 │ GPU Pool 2 │ CPU Pool (兜底) │ │ (7B Models) │ (70B Models) │ (小模型/重写) │ │ T4/A10×N │ A100×N │ gpt-4o-mini proxy │ ├──────────────┴──────────────┴──────────────────────┤ │ GPU Operator + NVIDIA Device Plugin │ ├─────────────────────────────────────────────────────┤ │ K8s Control Plane │ └─────────────────────────────────────────────────────┘ GPU 节点池配置 节点池规划 池名称 GPU 型号 显存 用途 节点数 单节点副本数 gpu-small T4 (16GB) 16GB 7B 以下模型 3 2 gpu-medium A10 (24GB) 24GB 7B-14B 模型 2 1 gpu-large A100 (80GB) 80GB 70B 模型 2 1 cpu-fallback 无 - 预处理/重写 5 10 GPU 节点 Label 与 Taint 配置 # GPU 节点打标签 apiVersion: v1 kind: Node metadata: name: gpu-node-1 labels: accelerator: nvidia-t4 gpu.memory: "16Gi" node.kubernetes.io/instance-type: "g4dn.xlarge" pool: gpu-small spec: {} --- # 专用 GPU 节点设置 Taint(防止非 GPU Pod 调度上去) apiVersion: v1 kind: Node metadata: name: gpu-node-1 spec: taints: - key: nvidia.com/gpu value: "true" effect: NoSchedule - key: pool value: gpu-small effect: NoSchedule NVIDIA GPU Operator 部署 # 安装 NVIDIA GPU Operator helm repo add nvidia https://helm.ngc.nvidia.com/nvidia helm repo update helm install gpu-operator nvidia/gpu-operator \ --namespace gpu-operator --create-namespace \ --set driver.enabled=true \ --set toolkit.enabled=true \ --set devicePlugin.enabled=true \ --set dcgmExporter.enabled=true \ --set nodeStatusExporter.enabled=true # 验证 GPU 可用 kubectl get nodes -o wide kubectl describe node gpu-node-1 | grep nvidia.com/gpu 模型服务部署 vLLM 推理服务部署 vLLM 是目前性能最好的开源 LLM 推理框架,支持 PagedAttention、连续批处理和 Tensor Parallel。 ...

2026-06-25 · 7 min · 1418 words · 硅基 AGI 探索者
鲁ICP备2026018361号