IT评测·应用市场-qidao123.com

标题: 在Kubernetes上摆设DeepSeek-R1举行高效AI推理 [打印本页]

作者: 道家人    时间: 2025-2-18 17:10
标题: 在Kubernetes上摆设DeepSeek-R1举行高效AI推理
在本篇文章中,我们将先容如何使用亚马逊云科技的Kubernetes服务Amazon EKS Auto Mode,在亚马逊云科技上摆设DeepSeek模型。Amazon EKS Auto Mode提供了更强的灵活性和可扩展性,同时无需管理Kubernetes控制节点、盘算、存储和网络组件,大大简化了摆设流程。



为什么要在Amazon EKS上摆设DeepSeek?




在Amazon EKS Auto Mode上摆设DeepSeek-R1

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


安装前置所需依靠

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


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


使用Terraform创建Amazon EKS Auto Mode集群

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

  1. # Clone the GitHub repo with the manifests
  2. git clone -b v0.1 https://github.com/aws-samples/deepseek-using-vllm-on-eks
  3. cd deepseek-using-vllm-on-eks
  4. # Apply the Terraform configuration
  5. terraform init
  6. terraform apply -auto-approve
  7. # After Terraform finishes, configure kubectl with the new EKS cluster
  8. $(terraform output configure_kubectl | jq -r)
复制代码

创建EKS Auto Mode NodePool

为了启用模型的GPU支持,需要创建自界说NodePool。
  1. # Create a custom NodePool with GPU support
  2. kubectl apply -f manifests/gpu-nodepool.yaml
  3. # Check if the NodePool is in 'Ready' state
  4. kubectl get nodepool/gpu-nodepool
复制代码

摆设DeepSeek模型

我们将使用vLLM摆设DeepSeek-R1-Distill-Llama-8B模型。为简化流程,我们提供了一个sed下令,方便各人快速设置模型名称和参数。
  1. # Use the sed command to replace the placeholder with the model name and configuration parameters
  2. sed -i "s|__MODEL_NAME_AND_PARAMETERS__|deepseek-ai/DeepSeek-R1-Distill-Llama-8B --max_model 2048|g" manifests/deepseek-deployment-gpu.yaml
  3. # Deploy the DeepSeek model on Kubernetes
  4. kubectl apply -f manifests/deepseek-deployment-gpu.yaml
  5. # Check the pods in the 'deepseek' namespace
  6. kubectl get po -n deepseek
复制代码

  1. # Wait for the pod to reach the 'Running' state
  2. watch -n 1 kubectl get po -n deepseek
  3. # Verify that a new Node has been created
  4. kubectl get nodes -l owner=data-engineer
  5. # Check the logs to confirm that vLLM has started
  6. kubectl logs deployment.apps/deepseek-deployment -n deepseek
复制代码
当摆设准备就绪后,日记记载中会表现提示:Application startup complete


与DeepSeek LLM交互

接下来,我们可以创建本地署理,然后使用curl哀求与模型交互。
  1. # Set up a proxy to forward the service port to your local terminal
  2. kubectl port-forward svc/deepseek-svc -n deepseek 8080:80 > port-forward.log 2>&1 &
  3. # Send a curl request to the model
  4. curl -X POST "http://localhost:8080/v1/chat/completions" -H "Content-Type: application/json" --data '{
  5. "model": "deepseek-ai/DeepSeek-R1-Distill-Llama-8B",
  6. "messages": [
  7. {
  8. "role": "user",
  9. "content": "What is Kubernetes?"
  10. }
  11. ]
  12. }'
复制代码



为模型构建Chatbot UI

尽管我们可以通过API直接发送哀求调用EKS上的模型,但我们也可以构建一个更方便交互的Chatbot UI界面,以便用户能更方便地与模型交互。UI的源代码已经在GitHub堆栈中提供。
  1. # Retrieve the ECR repository URI created by Terraform
  2. export ECR_REPO=$(terraform output ecr_repository_uri | jq -r)
  3. # Build the container image for the Chatbot UI
  4. docker build -t $ECR_REPO:0.1 chatbot-ui/application/.
  5. # Login to ECR and push the image
  6. aws ecr get-login-password | docker login --username AWS --password-stdin $ECR_REPO
  7. docker push $ECR_REPO:0.1
  8. # Update the deployment manifest to use the image
  9. sed -i "s#__IMAGE_DEEPSEEK_CHATBOT__#$ECR_REPO:0.1#g" chatbot-ui/manifests/deployment.yaml
  10. # Generate a random password for the Chatbot UI login
  11. sed -i "s|__PASSWORD__|$(openssl rand -base64 12 | tr -dc A-Za-z0-9 | head -c 16)|" chatbot-ui/manifests/deployment.yaml
  12. # Deploy the UI and create the ingress class required for load balancers
  13. kubectl apply -f chatbot-ui/manifests/ingress-class.yaml
  14. kubectl apply -f chatbot-ui/manifests/deployment.yaml
  15. # Get the URL for the load balancer to access the application
  16. echo http://$(kubectl get ingress/deepseek-chatbot-ingress -n deepseek -o json | jq -r '.status.loadBalancer.ingress[0].hostname')
复制代码

  1. 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)"
复制代码





总结

通过本教程,各人可以高效地在Amazon EKS上摆设DeepSeek R1模型,使用其灵活的扩展选项和精致化盘算资源控制,在优化成本的同时保持高性能。该方案充实使用了Kubernetes的原生功能,联合Amazon EKS的Auto Mode特性,提供了一种高度自界说的摆设方式,可以根据具体的运营需求和预算举行精确调解。
如果各人盼望进一步探索其他摆设模式(如使用Neuron或开源Karpenter举行摆设),可以访问GitHub堆栈deepseek-using-vllm-on-eks,获取更多代码示例。


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。




欢迎光临 IT评测·应用市场-qidao123.com (https://dis.qidao123.com/) Powered by Discuz! X3.4