内网 Kubernetes 部署 Ollama + DeepSeek-R1 1.5B 模型 + Open WebUI 完整指南
DeepSeek-R1不同尺寸模型版本区别对比
DeepSeek-R1-671b是基础大模型尺寸,其他的蒸馏后的小模型,关于不同尺寸的DeepSeek-R1版本介绍、参数量、特点、使用场景和硬件配置,可以参考下表:
DeepSeek模型版本 | 参数量 | 特点 | 适用场景 | 硬件配置 |
---|---|---|---|---|
DeepSeek-R1-1.5B | 1.5B | 轻量级模型,参数量少,模型规模小 | 适用于轻量级任务,如短文本生成、基础问答等 | 4核处理器、8G内存,无需显卡 |
DeepSeek-R1-7B | 7B | 平衡型模型,性能较好,硬件需求适中 | 适合中等复杂度任务,如文案撰写、表格处理、统计分析等 | 8核处理器、16G内存,Ryzen7或更高,RTX 3060(12GB)或更高 |
DeepSeek-R1-8B | 8B | 性能略强于7B模型,适合更高精度需求 | 适合需要更高精度的轻量级任务,比如代码生成、逻辑推理等 | 8核处理器、16G内存,Ryzen7或更高,RTX 3060(12GB)或4060 |
DeepSeek-R1-14B | 14B | 高性能模型,擅长复杂的任务,如数学推理、代码生成 | 可处理复杂任务,如长文本生成、数据分析等 | i9-13900K或更高、32G内存,RTX 4090(24GB)或A5000 |
DeepSeek-R1-32B | 32B | 专业级模型,性能强大,适合高精度任务 | 适合超大规模任务,如语言建模、大规模训练、金融预测等 | Xeon 8核、128GB内存或更高,2-4张A100(80GB)或更高 |
DeepSeek-R1-70B | 70B | 顶级模型,性能最强,适合大规模计算和高复杂任务 | 适合高精度专业领域任务,比如多模态任务预处理。这些任务对硬件要求非常高,需要高端的 CPU 和显卡,适合预算充足的企业或研究机构使用 | Xeon 8核、128GB内存或更高,8张A100/H100(80GB)或更高 |
DeepSeek-R1-671B | 671B | 超大规模模型,性能卓越,推理速度快,适合极高精度需求 | 适合国家级 / 超大规模 AI 研究,如气候建模、基因组分析等,以及通用人工智能探索 | 64核、512GB或更高,8张A100/H100 |
1. 前置条件
1.1 硬件要求
- GPU 节点:至少 1 个 NVIDIA GPU(显存 ≥ 8GB)
- CPU:≥ 4 核
- 内存:≥ 16GB
- 存储:≥ 50GB(模型持久化存储)
1.2 软件要求
- Kubernetes 集群:v1.24+(已启用 GPU 支持)
- NVIDIA 驱动:≥ 515.65.01
- 容器运行时:containerd/docker +
nvidia-container-toolkit
- 私有镜像仓库(可选):Harbor/Docker Registry
2. 环境准备
2.1 GPU 节点配置
# 在所有 GPU 节点执行
# 1. 安装 NVIDIA 驱动
sudo apt-get install -y nvidia-driver-535
# 2. 安装 nvidia-container-toolkit
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
curl -s -L https://nvidia.github.io/libnvidia-container/gpgkey | sudo apt-key add -
curl -s -L https://nvidia.github.io/libnvidia-container/$distribution/libnvidia-container.list | sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list
sudo apt-get update && sudo apt-get install -y nvidia-container-toolkit
sudo systemctl restart containerd
2.2 离线镜像准备
在一台可联网的机器下载以下镜像并导入内网:
# Ollama 官方镜像
docker pull ollama/ollama:0.1.33
# Open WebUI 镜像
docker pull ghcr.io/open-webui/open-webui:main
# 导出镜像
docker save ollama/ollama:0.1.33 -o ollama.tar
docker save ghcr.io/open-webui/open-webui:main -o open-webui.tar
# 在内网节点加载镜像
docker load -i ollama.tar
docker load -i open-webui.tar
3. 部署 Ollama
3.1 创建 Namespace
kubectl create namespace llm
3.2 部署 Ollama StatefulSet
创建 ollama-statefulset.yaml
:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: ollama-pvc
namespace: llm
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 50Gi
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: ollama
namespace: llm
spec:
serviceName: ollama
replicas: 1
selector:
matchLabels:
app: ollama
template:
metadata:
labels:
app: ollama
spec:
containers:
- name: ollama
image: ollama/ollama:0.5.5
resources:
limits:
nvidia.com/gpu: 1 # 申请 GPU
volumeMounts:
- name: ollama-data
mountPath: /root/.ollama
ports:
- containerPort: 11434
volumes:
- name: ollama-data
persistentVolumeClaim:
claimName: ollama-pvc
应用配置:
kubectl apply -f ollama-statefulset.yaml
3.3 创建 Service
创建 ollama-service.yaml
:
apiVersion: v1
kind: Service
metadata:
name: ollama
namespace: llm
spec:
selector:
app: ollama
ports:
- protocol: TCP
port: 11434
targetPort: 11434
应用配置:
kubectl apply -f ollama-service.yaml
4 获取模型数据包
注意我现在本地 windows 电脑上安装了 ollama 这个安装链接如下
https://ollama.com/download/windows
点击 models 查看对应的模型执行方式
注意需要先本地联网节点上下载 ollama,然后基于 ollama 下载所需的大模型数据包
如:
这里我下载 deepseek-r1:1.5b
PS C:\Windows\System32> ollama run deepseek-r1:1.5b
pulling manifest
pulling aabd4debf0c8... 26% ▕██████████████ ▏ 288 MB/1.1 GB 509 KB/s 27m5s
获取 modelfile 命令 ollama show deepseek-r1:1.5b --modelfile
ollama show deepseek-r1:1.5b --modelfile
# Modelfile generated by "ollama show"
# To build a new Modelfile based on this, replace FROM with:
# FROM deepseek-r1:1.5b
FROM C:\Users\as953\.ollama\models\blobs\sha256-aabd4debf0c8f08881923f2c25fc0fdeed24435271c2b3e92c4af36704040dbc
TEMPLATE """{{- if .System }}{{ .System }}{{ end }}
{{- range $i, $_ := .Messages }}
{{- $last := eq (len (slice $.Messages $i)) 1}}
{{- if eq .Role "user" }}<|User|>{{ .Content }}
{{- else if eq .Role "assistant" }}<|Assistant|>{{ .Content }}{{- if not $last }}<|end▁of▁sentence|>{{- end }}
{{- end }}
{{- if and $last (ne .Role "assistant") }}<|Assistant|>{{- end }}
{{- end }}"""
PARAMETER stop <|begin▁of▁sentence|>
PARAMETER stop <|end▁of▁sentence|>
PARAMETER stop <|User|>
PARAMETER stop <|Assistant|>
LICENSE """MIT License
Copyright (c) 2023 DeepSeek
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""
C:\Users\as953\.ollama\models\blobs
模型路径,通过 hash 和大小来判断刚才下载的模型,然后我们再将该模型上传至服务器中
5. 部署 DeepSeek-R1 1.5B 模型
5.1 准备模型文件
将 deepseek-r1:1.5b
的 GGUF 格式模型文件(如 deepseek-r1-1.5b.Q4_K_M.gguf
)放入 PVC 挂载目录:
# 查找 Ollama Pod 名称
OLLAMA_POD=$(kubectl get pods -n llm -l app=ollama -o jsonpath='{.items[0].metadata.name}')
5.2 创建 Modelfile
可以看到他的 hash 为 aabd4debf0c8 ,等会我们基于这个 aabd4debf0c8 hash 找到对应最大的文件,这个就是 gguf 文件,然后通过以下命令:
# 修改 aabd4debf0c8... 文件为 gguf 文件类型
mv sha256-aabd4debf0c8f08881923f2c25fc0fdeed24435271c2b3e92c4af36704040dbc deepseek-r1.1.5b.gguf
# 复制模型文件到 POD
kubectl cp ./deepseek-r1-1.5b.Q4_K_M.gguf $OLLAMA_POD:/root/.ollama/models -n llm
将上面的 modelfile 文件传入至 Pod
kubectl cp ./Modelfile $OLLAMA_POD:/root/.ollama/models -n llm
加载模型到 Ollama:
kubectl exec -it $OLLAMA_POD -n llm -- ollama create deepseek-r1-1.5b -f /root/.ollama/models/Modelfile
transferring model data
creating model layer
creating parameters layer
creating config layer
using already created layer sha256:aabd4debf0c8f08881923f2c25fc0fdeed24435271c2b3e92c4af36704040dbc
using already created layer sha256:d14a064ea8b35821e3d491b1c6a82a9488bbd109aa0f760b2bd1f27c161fd58c
writing layer sha256:314b5bf47aff811fe364ca17d4065a74d06012fc81bb17a471eac5ef32d4621f
writing manifest
success
运行大模型
ollmam run deepseek-r:1.5b
6. 部署 Open WebUI
6.1 创建 WebUI Deployment
创建 webui-deployment.yaml
:
apiVersion: apps/v1
kind: Deployment
metadata:
name: open-webui
namespace: llm
spec:
replicas: 1
selector:
matchLabels:
app: open-webui
template:
metadata:
labels:
app: open-webui
spec:
containers:
- name: webui
image: ghcr.io/open-webui/open-webui:main
env:
- name: OLLAMA_API_BASE_URL
value: "http://ollama.llm.svc.cluster.local:11434"
ports:
- containerPort: 8080
应用配置:
kubectl apply -f webui-deployment.yaml
6.2 创建 WebUI Service
创建 webui-service.yaml
:
apiVersion: v1
kind: Service
metadata:
name: open-webui
namespace: llm
spec:
type: NodePort
selector:
app: open-webui
ports:
- protocol: TCP
port: 8080
targetPort: 8080
nodePort: 30080
应用配置:
kubectl apply -f webui-service.yaml
7. 验证部署
7.1 检查服务状态
kubectl get pods,svc -n llm
7.2 访问 Open WebUI
通过浏览器访问:
http://
7.3 添加大模型
点击 root ,点击设置
点击管理员设置
点击外部链接
编辑外部链接并且这里需要注意使用我们当前 ollama K8S DNS即可、然后在选择对应的大模型数据
跳转到新的对话就可以看到已经有 deepseek-r1:1.5b 大模型
沟通测试
8. 故障排查
8.1 查看日志
kubectl logs -f <ollama-pod-name> -n llm
kubectl logs -f <webui-pod-name> -n llm
8.2 GPU 资源监控
watch -n 1 nvidia-smi
9. 清理资源
kubectl delete namespace llm
注意事项:
- 确保模型文件符合 Ollama 支持的格式(GGUF)
- 内网需提前配置镜像仓库或手动加载镜像
- 根据实际硬件调整 GPU 资源限制
- 生产环境建议启用 TLS 加密和访问控制
- 后期替换大模型数据包的 gguf 文件即可