在Kubernetes上部署DeepSeek-R1进行高效AI推理

server/2025/2/21 2:01:37/

在本篇文章中,我们将介绍如何使用亚马逊云科技的Kubernetes服务Amazon EKS Auto Mode,在亚马逊云科技上部署DeepSeek模型。Amazon EKS Auto Mode提供了更强的灵活性和可扩展性,同时无需管理Kubernetes控制节点、计算、存储和网络组件,大大简化了部署流程。

为什么要在Amazon EKS上部署DeepSeek?

  • 开源与开放性:DeepSeek采用开源方式,让更多企业和开发人员可以访问和使用其先进的语言模型,推动AI发展。
  • 增强推理能力:DeepSeek-R1采用Chain of Thought (CoT) 推理,使模型可以将复杂问题拆解为多个可管理的步骤,提升其解决数学问题、逻辑推理等任务的能力。
  • 简化Amazon EKS上的托管:通过Amazon EKS Auto Mode托管DeepSeek,无需管理底层Kubernetes基础设施,让大家专注于部署和使用模型。

在Amazon EKS Auto Mode上部署DeepSeek-R1

在本教程中,我们将使用DeepSeek-R1-Distill-Llama-8B模型,这是一个DeepSeek的轻量级蒸馏版本,相比完整的DeepSeek-R1(671B参数)模型,它占用更少的计算资源(如GPU),但性能稍逊于完整版本。如果大家希望部署完整的DeepSeek-R1模型,可以在vLLM配置中替换蒸馏版模型。

安装前置所需依赖

本教程使用亚马逊云科技CloudShell来简化安装过程。

# Installing kubectl
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl# Install Terraform
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/AmazonLinux/hashicorp.repo
sudo yum -y install terraform

使用Terraform创建Amazon EKS Auto Mode集群

接下来我们将使用Terraform快速创建云基础架构,包括:

  • VPC(虚拟私有云)
  • ECR(Elastic Container Registry)镜像仓库
  • 启用Auto Mode的EKS集群
# Clone the GitHub repo with the manifests
git clone -b v0.1 https://github.com/aws-samples/deepseek-using-vllm-on-eks
cd deepseek-using-vllm-on-eks# Apply the Terraform configuration
terraform init
terraform apply -auto-approve# After Terraform finishes, configure kubectl with the new EKS cluster
$(terraform output configure_kubectl | jq -r)

创建EKS Auto Mode NodePool

为了启用模型的GPU支持,需要创建自定义NodePool。

# Create a custom NodePool with GPU support
kubectl apply -f manifests/gpu-nodepool.yaml# Check if the NodePool is in 'Ready' state
kubectl get nodepool/gpu-nodepool

部署DeepSeek模型

我们将使用vLLM部署DeepSeek-R1-Distill-Llama-8B模型。为简化流程,我们提供了一个sed命令,方便大家快速设置模型名称和参数。

# Use the sed command to replace the placeholder with the model name and configuration parameters
sed -i "s|__MODEL_NAME_AND_PARAMETERS__|deepseek-ai/DeepSeek-R1-Distill-Llama-8B --max_model 2048|g" manifests/deepseek-deployment-gpu.yaml# Deploy the DeepSeek model on Kubernetes
kubectl apply -f manifests/deepseek-deployment-gpu.yaml# Check the pods in the 'deepseek' namespace 
kubectl get po -n deepseek
  • 部署完成后,Pod可能会短暂处于Pending状态,因为EKS Auto Mode需要自动配置EC2实例,并安装必要的GPU驱动。
  • 如果Pod在Pending状态停留较长时间,请检查AWS账户的GPU实例可创建的额度,确保能够启动所需的GPU实例。
  • 可以在亚马逊云科技EC2实例配额文档中查看详细信息。
  • 注意:这些配额基于vCPU,而非实例的数量,因此申请云资源额度时需要按vCPU数量进行调整。
# Wait for the pod to reach the 'Running' state
watch -n 1 kubectl get po -n deepseek# Verify that a new Node has been created
kubectl get nodes -l owner=data-engineer# Check the logs to confirm that vLLM has started
kubectl logs deployment.apps/deepseek-deployment -n deepseek

当部署准备就绪后,日志记录中会显示提示:Application startup complete

与DeepSeek LLM交互

接下来,我们可以创建本地代理,然后使用curl请求与模型交互。

# Set up a proxy to forward the service port to your local terminal
kubectl port-forward svc/deepseek-svc -n deepseek 8080:80 > port-forward.log 2>&1 &# Send a curl request to the model
curl -X POST "http://localhost:8080/v1/chat/completions" -H "Content-Type: application/json" --data '{"model": "deepseek-ai/DeepSeek-R1-Distill-Llama-8B","messages": [{"role": "user","content": "What is Kubernetes?"}]}'
  • 响应时间可能会根据模型的计算复杂度有所不同,一般需要几秒钟。
  • 可以通过deepseek-deployment日志来监控模型的执行情况。

为模型构建Chatbot UI

尽管我们可以通过API直接发送请求调用EKS上的模型,但我们也可以构建一个更方便交互的Chatbot UI界面,以便用户能更方便地与模型交互。UI的源代码已经在GitHub仓库中提供。

# Retrieve the ECR repository URI created by Terraform
export ECR_REPO=$(terraform output ecr_repository_uri | jq -r)# Build the container image for the Chatbot UI
docker build -t $ECR_REPO:0.1 chatbot-ui/application/.# Login to ECR and push the image
aws ecr get-login-password | docker login --username AWS --password-stdin $ECR_REPO
docker push $ECR_REPO:0.1# Update the deployment manifest to use the image
sed -i "s#__IMAGE_DEEPSEEK_CHATBOT__#$ECR_REPO:0.1#g" chatbot-ui/manifests/deployment.yaml# Generate a random password for the Chatbot UI login
sed -i "s|__PASSWORD__|$(openssl rand -base64 12 | tr -dc A-Za-z0-9 | head -c 16)|" chatbot-ui/manifests/deployment.yaml# Deploy the UI and create the ingress class required for load balancers
kubectl apply -f chatbot-ui/manifests/ingress-class.yaml
kubectl apply -f chatbot-ui/manifests/deployment.yaml# Get the URL for the load balancer to access the application
echo http://$(kubectl get ingress/deepseek-chatbot-ingress -n deepseek -o json | jq -r '.status.loadBalancer.ingress[0].hostname')
  • 等待几秒钟,让负载均衡器(Load Balancer)完成部署。
  • 访问Chatbot UI时,需要输入存储在Kubernetes Secret中的用户名和密码。
echo -e "Username=$(kubectl get secret deepseek-chatbot-secrets -n deepseek -o jsonpath='{.data.admin-username}' | base64 --decode)\nPassword=$(kubectl get secret deepseek-chatbot-secrets -n deepseek -o jsonpath='{.data.admin-password}' | base64 --decode)"
  • 登录后,大家将在界面中看到我们的Chatbot UI界面,在这里可直接与模型交互!

总结

通过本教程,大家可以高效地在Amazon EKS上部署DeepSeek R1模型,利用其灵活的扩展选项和精细化计算资源控制,在优化成本的同时保持高性能。该方案充分利用了Kubernetes的原生功能,结合Amazon EKS的Auto Mode特性,提供了一种高度自定义的部署方式,可以根据具体的运营需求和预算进行精确调整。

如果大家希望进一步探索其他部署模式(如使用Neuron或开源Karpenter进行部署),可以访问GitHub仓库deepseek-using-vllm-on-eks,获取更多代码示例。


http://www.ppmy.cn/server/169422.html

相关文章

全功能Python测试框架:pytest

python通用测试框架大多数人用的是unittestHTMLTestRunner,这段时间看到了pytest文档,发现这个框架和丰富的plugins很好用,所以来学习下pytest. pytest是一个非常成熟的全功能的Python测试框架,主要有以下几个特点: …

23种设计模式 - 适配器模式

模式定义 适配器模式(Adapter Pattern)是一种结构型设计模式,用于解决接口不兼容问题。它通过将一个类的接口转换为客户端期望的接口,使原本因接口不匹配而无法协同工作的类能够协同工作。适配器模式分为类适配器(通过…

el与data的2种写法

el的2种写法 1.el: #root, <div id"root"> </div><script type"text/javascript">const x new Vue({el: #root,data: {name: 伏尔加}})</script> 2. x.$mount(#root) <div id"root"> </div><script …

Python 自然语言处理(NLP)和文本挖掘的常规操作过程

Python 自然语言处理&#xff08;NLP&#xff09;和文本挖掘 自然语言处理&#xff08;NLP&#xff09;和文本挖掘是数据科学中的重要领域&#xff0c;涉及对文本数据的分析和处理。Python 提供了丰富的库和工具&#xff0c;用于执行各种 NLP 和文本挖掘任务。以下是一些常见的…

超全Deepseek资料包,deepseek下载安装部署提示词及本地部署指南介绍

该资料包涵盖了DeepSeek模型的下载、安装、部署以及本地运行的详细指南&#xff0c;适合希望在本地环境中高效运行DeepSeek模型的用户。资料包不仅包括基础的安装步骤&#xff0c;还提供了68G多套独立部署视频教程教程&#xff0c;针对不同硬件配置的模型选择建议&#xff0c;以…

在项目中调用本地Deepseek(接入本地Deepseek)

前言 之前发表的文章已经讲了如何本地部署Deepseek模型&#xff0c;并且如何给Deepseek模型投喂数据、搭建本地知识库&#xff0c;但大部分人不知道怎么应用&#xff0c;让自己的项目接入AI模型。 文末有彩蛋哦&#xff01;&#xff01;&#xff01; 要接入本地部署的deepsee…

加强地面塌陷隐患防治,构筑城市地质安全防线

随着我国城市现代化建设进程的加快&#xff0c;城市基础建设和房地产开发呈现出高速发展的态势。然而&#xff0c;在这一繁荣景象的背后&#xff0c;城市地面塌陷问题却日益凸显&#xff0c;成为影响城市地质环境安全的重要因素之一。与传统的地质灾害相比&#xff0c;城市地面…

2025.2.19——1500

2025.2.19——1500 A 1500 B 1500 C 1500 D 1500 ------------------------------------------------ 思维/图论位运算/思维数学/思维构造/思维 A 存在路径即在一个连通块。加上必须加的边&#xff0c;删去必须要删去的边。并查集维护查询&#xff0c;考虑一下删边和加边…