新闻详情

新闻详情

首页 / 资讯中心 / 详情

在 Kubernetes 上使用 Ray Serve LLM 部署 DeepSeek R1:从 GKE GPU 集群搭建到首个推理请求

发布时间:2026/9/21 2:34:07来源:尧图网络
在 Kubernetes 上使用 Ray Serve LLM 部署 DeepSeek R1:从 GKE GPU 集群搭建到首个推理请求
在 Kubernetes 上使用 Ray Serve LLM 部署 DeepSeek R1从 GKE GPU 集群搭建到首个推理请求【免费下载链接】rayRay is an AI compute engine. Ray consists of a core distributed runtime and a set of AI Libraries for accelerating ML workloads.项目地址: https://gitcode.com/gh_mirrors/ra/ray本指南基于 KubeRay、Ray Serve 与 vLLM 技术栈完整演示如何在 Kubernetes 集群上以 OpenAI 兼容 API 方式规模化部署deepseek-ai/DeepSeek-R1模型。你将掌握从 GKE GPU 集群创建、KubeRay Operator 安装、RayService 自定义资源部署到通过 Ray Dashboard 观测与发送首个推理请求的完整闭环并深入理解serveConfigV2中 tensor/pipeline 并行等关键性能参数的作用。本指南对应的示例文档位于 doc/source/cluster/kubernetes/examples/rayserve-deepseek-example.md关于 Ray Serve LLM 的整体能力可参考 Serving LLMs即serving-llms锚点对应章节。前置条件DeepSeek-R1 模型体量庞大需要2 个节点、每节点 8 张 H100 80GB GPU的硬件规模。能够满足该资源要求的 Kubernetes 集群均可部署本示例。本指南以 GKE 为例推荐使用 A3 High 或 A3 Mega 机型。在创建集群前请先确认你的云项目对所需加速器拥有足够的 quota 配额否则 GPU 节点池创建会失败。Step 1在 GKE 上创建 Kubernetes 集群在本地机器或 Google Cloud Shell 上执行本步及后续所有命令。若在本地执行需先安装 Google Cloud SDK。以下命令创建名为kuberay-gpu-cluster的集群位于us-east5-a区域包含 1 个默认 CPU 节点。示例采用e2-standard-16机型16 vCPU / 64 GB 内存该节点主要承载控制面组件与 KubeRay Operator。gcloud container clusters create kuberay-gpu-cluster \ --locationus-east5-a \ --machine-typee2-standard-16 \ --num-nodes1 \ --enable-image-streaming接着创建按需计费的 GPU 节点池用于运行 Ray GPU workergcloud beta container node-pools create gpu-node-pool \ --cluster kuberay-gpu-cluster \ --machine-type a3-highgpu-8g \ --num-nodes 2 \ --accelerator typenvidia-h100-80gb,count8 \ --zone us-east5-a \ --node-locations us-east5-a \ --host-maintenance-intervalPERIODIC其中--accelerator标志指定节点池中每个节点挂载的 GPU 类型与数量。示例采用 A3 High GPU机型a3-highgpu-8g具备 8 张 GPU、640 GB GPU 显存、208 vCPU 与 1872 GB 内存。Note若要创建使用预留资源reservation的节点池可追加以下参数--reservation-affinityspecific--reservationRESERVATION_NAME--placement-policyPLACEMENT_POLICY_NAME可选最后配置kubectl使其连接该集群gcloud container clusters get-credentials kuberay-gpu-cluster --zone us-east5-aStep 2安装 KubeRay Operator按照 Deploy a KubeRay operator 文档从 Helm 仓库安装最新的稳定版 KubeRay Operator。示例配置中的 KubernetesNoSchedule污点taint可防止 KubeRay Operator Pod 被调度到 GPU 节点上确保控制面组件与 GPU 工作负载隔离。Step 3部署 RayService通过以下命令将 DeepSeek-R1 作为 RayService 自定义资源部署kubectl apply -f https://raw.githubusercontent.com/ray-project/kuberay/master/ray-operator/config/samples/ray-service.deepseek.yaml该步骤在 2 个 worker 节点上搭建了一个自定义 Ray Serve 应用用于服务deepseek-ai/DeepSeek-R1模型。你可以检查并修改 YAML 中的serveConfigV2部分来了解 Serve 应用的配置结构serveConfigV2: | applications: - args: llm_configs: - model_loading_config: model_id: deepseek model_source: deepseek-ai/DeepSeek-R1 accelerator_type: H100 deployment_config: autoscaling_config: min_replicas: 1 max_replicas: 1 runtime_env: env_vars: VLLM_USE_V1: 1 engine_kwargs: tensor_parallel_size: 8 pipeline_parallel_size: 2 gpu_memory_utilization: 0.92 dtype: auto max_num_seqs: 40 max_model_len: 16384 enable_chunked_prefill: true enable_prefix_caching: true import_path: ray.serve.llm:build_openai_app name: llm_app route_prefix: /配置逐项拆解从 import_path 到 engine_kwargsimport_path: ray.serve.llm:build_openai_app是本应用的核心入口。它在 Ray Serve LLM 中公开定义于 python/ray/serve/llm/init.py#L149签名与职责为PublicAPI(stabilitystable) def build_openai_app(llm_serving_args: dict) - Application: Helper to build an OpenAI compatible app with the llm deployment setup from the given llm serving args. This is the main entry point for users to create a Serve application serving LLMs.从实现看python/ray/serve/llm/init.py#L246-L250它会将llm_serving_args传入ray.llm._internal.serve.core.ingress.builder的build_openai_app由内部 builder 依据llm_configs列表创建 OpenAI 兼容的路由层LLMRouter与引擎部署层LLMDeployment。因此applications.args.llm_configs中的每个配置项都会生成一个可供外部以model_id访问的模型服务。model_loading_config中的两个字段含义如下对应 python/ray/llm/_internal/serve/core/configs/llm_config.py#L125-L138 的ModelLoadingConfigmodel_id: deepseek终端用户调用时使用的模型标识OpenAI 请求体中的model字段必须与此一致model_source: deepseek-ai/DeepSeek-R1权重来源可以是 Hugging Face 模型 ID、S3/GCS/Azure 镜像配置或本地路径省略时默认回退为将model_id当作 Hugging Face 模型 ID 使用。LLMConfigpython/ray/llm/_internal/serve/core/configs/llm_config.py#L152还支持llm_engine字段默认值为vLLM本示例即基于 vLLM 引擎驱动推理。runtime_env.env_vars中的VLLM_USE_V1: 1用于启用 vLLM 的 V1 新执行引擎。engine_kwargs是直接透传给底层 vLLM 引擎的配置字典python/ray/llm/_internal/serve/core/configs/llm_config.py#L171-L178In case of vLLM, this will include all the configuration knobs they provide out of the box即 vLLM 提供的全部原生配置旋钮都可在此设置。本示例包含两组关键的并行策略参数tensor_parallel_size: 8启用张量并行tensor parallelism将模型的单个大层拆分到 8 张 GPU 上并行计算。该值应根据集群节点实际使用的 GPU 数量调整。结合accelerator_type: H100Ray 会将引擎调度到具备 8 张 H100 的单个 GPU 节点上。pipeline_parallel_size: 2启用流水线并行pipeline parallelism将模型的全部层划分为 2 个顺序执行阶段。该值应根据集群 worker 节点数量调整——本示例 2 个节点、每节点 8 GPU正好对应 TP8 单节点内张量并行、PP2 跨节点流水线并行的组合。其余为吞吐与显存相关的调优参数gpu_memory_utilization: 0.92vLLM 可使用 GPU 显存的比例上限dtype: auto推理精度自动选择通常为 bf16max_num_seqs: 40单批次最多同时处理的序列数max_model_len: 16384模型支持的最大上下文长度tokenenable_chunked_prefill: true启用分块预填充将长 prefill 请求切成小块避免阻塞 decode 阶段的吞吐enable_prefix_caching: true启用前缀缓存重复的 prompt 前缀可直接复用 KV cache显著降低多轮或共享系统提示词场景的延迟。deployment_config.autoscaling_config控制引擎副本数min_replicas: 1、max_replicas: 1即固定单副本。关于 Serve 生产配置文件格式可参考 Ray Serve config documentation。验证 RayService 健康状态等待 RayService 资源变为健康状态可通过以下命令确认kubectl get rayservice deepseek-r1 -o yaml数分钟后输出应与以下内容类似status: activeServiceStatus: applicationStatuses: llm_app: serveDeploymentStatuses: LLMDeployment:deepseek: status: HEALTHY LLMRouter: status: HEALTHY status: RUNNINGNote模型下载与部署通常需要 20–30 分钟。在此期间可通过第 4 步的 Ray Dashboard 的 Cluster 标签页监控下载进度——随着权重写入磁盘可以看到磁盘占用持续增长。LLMDeployment引擎副本与LLMRouter路由副本均显示HEALTHY、应用整体RUNNING说明模型已就绪。这两类部署正是build_openai_app内部 builder 依据llm_configs自动生成的两类组件。Step 4查看 Ray Dashboard# 转发 head 服务的 8265 端口 kubectl port-forward svc/deepseek-r1-head-svc 8265:8265端口转发成功后在浏览器访问 Ray Dashboard 的Serve标签页可查看应用状态、部署信息、路由器、日志及其他相关功能。上图中可以看到llm_app应用、LLMDeployment:deepseek引擎部署与LLMRouter路由部署的运行状态以及各组件最近部署时间、副本数、配置与日志入口这正好与kubectl get rayservice输出的状态结构一一对应。Step 5发送请求先转发 Serve 应用服务的 8000 端口kubectl port-forward svc/deepseek-r1-serve-svc 8000注意该 Kubernetes Service 只有在 Ray Serve 应用启动并就绪后才会出现若端口转发报错请确认模型已完成部署即 Step 3 中状态为RUNNING/HEALTHY。随后使用 curl 调用 OpenAI 兼容的聊天补全接口测试服务$ curl http://localhost:8000/v1/chat/completions -H Content-Type: application/json -d { model: deepseek, messages: [ { role: user, content: I have four boxes. I put the red box on the bottom and put the blue box on top. Then I put the yellow box on top the blue. Then I take the blue box out and put it on top. And finally I put the green box on the top. Give me the final order of the boxes from bottom to top. Show your reasoning but be brief} ], temperature: 0.7 }请求体中的model: deepseek必须与serveConfigV2中model_loading_config.model_id保持一致。输出格式如下{ id: deepseek-653881a7-18f3-493b-a43f-adc8501f01f8, object: chat.completion, created: 1753345252, model: deepseek, choices: [ { index: 0, message: { role: assistant, reasoning_content: null, content: Okay, lets break this down step by step. ... The final order from bottom to top is: red, yellow, blue, green. ..., tool_calls: [] }, logprobs: null, finish_reason: stop, stop_reason: null } ], usage: { prompt_tokens: 81, total_tokens: 505, completion_tokens: 424, prompt_tokens_details: null }, prompt_logprobs: null }响应与 OpenAI Chat Completions 格式完全兼容返回id、object、choices、usage等标准字段任何基于 OpenAI SDK 的客户端都可直接对接该服务参考 python/ray/serve/llm/init.py#L200-L210 中client.chat.completions.create的调用示例。小结本指南走通了集群 → 算子 → 服务 → 观测 → 推理的完整链路GKE 上创建 CPU 控制节点与 2×8 H100 GPU 节点池安装 KubeRay Operator通过serveConfigV2以声明式配置部署 DeepSeek-R1用tensor_parallel_size8与pipeline_parallel_size2实现 TPPP 混合并行最终以 OpenAI 兼容接口对外服务。该模式可推广到任意 Hugging Face 模型——只需修改model_loading_config与engine_kwargs适配目标模型的规模与硬件拓扑即可。相关参考实现与文档示例入口 doc/source/cluster/kubernetes/examples/rayserve-llm-example.md、LLM 配置模型定义 python/ray/llm/_internal/serve/core/configs/llm_config.py、入口函数 python/ray/serve/llm/init.py。【免费下载链接】rayRay is an AI compute engine. Ray consists of a core distributed runtime and a set of AI Libraries for accelerating ML workloads.项目地址: https://gitcode.com/gh_mirrors/ra/ray创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
网站建设高端定制企业官网
RELATED

相关资讯

更多精彩内容,欢迎继续阅读

较早相关资讯

最新相关资讯

ARIS 工作流总览:从 idea 到 paper 的 13 条 pipeline 如何一次看全 2026/9/21 4:07:21

ARIS 工作流总览:从 idea 到 paper 的 13 条 pipeline 如何一次看全

ARIS 工作流总览:从 idea 到 paper 的 13 条 pipeline 如何一次看全 【免费下载链接】Auto-claude-code-research-in-sleep ARIS ⚔️ (Auto-Research-In-Sleep) — Lightweight Markdown-only skills for autonomous ML research: cross-model review loops, idea …

阅读更多 →
Roc 格式化器幂等性测试实战:从 issue 8851 快照看多行分发与字段访问的格式化处理 2026/9/21 4:04:21

Roc 格式化器幂等性测试实战:从 issue 8851 快照看多行分发与字段访问的格式化处理

Roc 格式化器幂等性测试实战:从 issue 8851 快照看多行分发与字段访问的格式化处理 【免费下载链接】roc A fast, friendly, functional language. 项目地址: https://gitcode.com/GitHub_Trending/ro/roc 导读:本文以 Roc 编译器仓库中的快照测试…

阅读更多 →
TypePHP编译器API参考:程序化调用PHP AOT编译器的完整指南 2026/9/21 4:04:21

TypePHP编译器API参考:程序化调用PHP AOT编译器的完整指南

TypePHP编译器API参考:程序化调用PHP AOT编译器的完整指南 【免费下载链接】typephp Compile PHP to Native Binaries 项目地址: https://gitcode.com/GitHub_Trending/ty/typephp TypePHP 是一款用 PHP 编写的原生 AOT 编译器(tpc)&a…

阅读更多 →
React Admin 实时数据提供者(Realtime Data Provider)接入完整指南:方法签名、内置适配器与自定义实现 2026/9/21 4:04:21

React Admin 实时数据提供者(Realtime Data Provider)接入完整指南:方法签名、内置适配器与自定义实现

前端UI组件 【免费下载链接】react-admin A frontend Framework for single-page applications on top of REST/GraphQL APIs, using TypeScript, React and Material Design 项目地址: https://gitcode.com/gh_mirrors/re/react-admin 点击查看 免费下载 本指南系…

阅读更多 →
VitePress 默认主题 Layout 指南:深入理解 doc、page、home 与自定义布局 2026/9/21 4:04:21

VitePress 默认主题 Layout 指南:深入理解 doc、page、home 与自定义布局

VitePress 默认主题 Layout 指南:深入理解 doc、page、home 与自定义布局 【免费下载链接】vitepress Vite & Vue powered static site generator. 项目地址: https://gitcode.com/gh_mirrors/vi/vitepress VitePress 通过 frontmatter 中的 layout 选项…

阅读更多 →
Weex 鸿蒙化实践:js-base64 纯 JS 编解码库在 WebSceneAPI 中的集成与使用指南 2026/9/21 4:04:21

Weex 鸿蒙化实践:js-base64 纯 JS 编解码库在 WebSceneAPI 中的集成与使用指南

移动开发跨平台前端UI组件OpenHarmony 【免费下载链接】weex A framework for building Mobile cross-platform UI 项目地址: https://gitcode.com/gh_mirrors/we/weex 点击查看 免费下载 导读 本文基于 WebSceneAPI 模块 内置的 js-base64 库(位于 co…

阅读更多 →

今日资讯

本周资讯

本月资讯

看完文章仍有疑问?

联系尧图顾问,获取一对一建站咨询

立即免费咨询 📞 400-888-8888
📞