华为云kubernetes摆设deepseek r1、ollama和open-webui(已踩过坑) ...

打印 上一主题 下一主题

主题 1925|帖子 1925|积分 5775

1 概述

ollama是一个管理大模型的一个中心层,通过它你可以下载并管理deepseek R1、llama3等大模型。
open-webui是一个web界面(界面计划受到chatgpt启发),可以集成ollama API、 OpenAI的 API。
用常见的web应用架构来类比,open-webui是前端,ollama是后端,大模型是数据库。

文本介绍华为云kubernetes摆设open-webui最新版、ollama最新版、DeepSeek-R1-Distill-Qwen-1.5B(因为小模型可以只使用CPU,节省本文测试的成本)。


2 云资源情况准备

2.1 购买文件存储SFS Turbo




2.2 购买kubernetes集群




2.3 在k8s中创建storageclass对象

参数everest.io/share-access-to是VPC的ID。
参数everest.io/share-export-location是sfs turbo实例的共享路径:自界说子目次,sfs turbo实例的共享路径是在sfs实例的详细页查询,自界说子目次可以是任意路径。
参数everest.io/volume-id是sfs turbo实例的ID。
只需要修改以上三个参数。
在本文,storageclass的名称叫做sfsturbo-subpath-sc。
  1. apiVersion: storage.k8s.io/v1
  2. allowVolumeExpansion: true
  3. kind: StorageClass
  4. metadata:
  5.   name: sfsturbo-subpath-sc
  6. mountOptions:
  7. - lock
  8. parameters:
  9.   csi.storage.k8s.io/csi-driver-name: sfsturbo.csi.everest.io
  10.   csi.storage.k8s.io/fstype: nfs
  11.   everest.io/archive-on-delete: "true"
  12.   everest.io/share-access-to: xxxxxxxxxxxxxxxxxx   # VPC ID
  13.   everest.io/share-expand-type: bandwidth
  14.   everest.io/share-export-location: xxxxx.sfsturbo.internal:/mydir   # sfs turbo实例的共享路径:自定义子目录
  15.   everest.io/share-source: sfs-turbo
  16.   everest.io/share-volume-type: STANDARD
  17.   everest.io/volume-as: subpath
  18.   everest.io/volume-id: xxxxxxxxxxxxx   # sfs turbo实例的ID
  19. provisioner: everest-csi-provisioner
  20. reclaimPolicy: Delete
  21. volumeBindingMode: Immediate
复制代码


2.4 购买用于暴露容器的负载均衡器ELB



3 摆设

3.1 创建namespace

ollama和open webui都摆设在此namespace。
  1. kubectl create ns ollama
复制代码

3.1 摆设ollama

statefulset使用刚刚创建的存储类sfsturbo-subpath-sc。
确保PVC的磁盘容量能存储下全部待下载的大模型。
  1. apiVersion: apps/v1
  2. kind: StatefulSet
  3. metadata:
  4.   name: ollama
  5.   namespace: ollama
  6. spec:
  7.   serviceName: "ollama"
  8.   replicas: 1
  9.   selector:
  10.     matchLabels:
  11.       app: ollama
  12.   template:
  13.     metadata:
  14.       labels:
  15.         app: ollama
  16.     spec:
  17.       containers:
  18.         - name: ollama
  19.           image: swr.cn-south-1.myhuaweicloud.com/migrator/ollama:0.5.7
  20.           ports:
  21.             - containerPort: 11434
  22.           resources:
  23.             requests:
  24.               cpu: "1000m"
  25.               memory: "2Gi"
  26.               # nvidia.com/gpu: "4"  # 如果要用英伟达GPU,请声明下GPU卡的数量
  27.             limits:
  28.               cpu: "4000m"
  29.               memory: "4Gi"
  30.           volumeMounts:
  31.             - name: ollama-volume
  32.               mountPath: /root/.ollama
  33.           tty: true
  34.   volumeClaimTemplates:
  35.     - metadata:
  36.         name: ollama-volume
  37.       spec:
  38.         storageClassName: sfsturbo-subpath-sc
  39.         accessModes: ["ReadWriteOnce"]
  40.         resources:
  41.           requests:
  42.             storage: 200Gi  # 确保磁盘容量能存储下所有待下载的大模型
  43. ---
  44. apiVersion: v1
  45. kind: Service
  46. metadata:
  47.   name: ollama
  48.   namespace: ollama
  49.   labels:
  50.     app: ollama
  51. spec:
  52.   type: ClusterIP
  53.   ports:
  54.     - port: 11434
  55.       protocol: TCP
  56.       targetPort: 11434
  57.   selector:
  58.     app: ollama
复制代码


3.1 摆设open webui(重点)



  • deployment挂载一个固定的PVC,PVC使用刚刚创建的存储类sfsturbo-subpath-sc。
  • OLLAMA_BASE_URL情况变量是ollama的地址。
  • 无法毗连huggingface.co:
    由于在国内情况是无法毗连huggingface.co,最终导致open webui的界面是一片空缺(应用日志报错:MaxRetryError("HTTPSConnectionPool(host=‘huggingface.co’, port=443)),因此需要增长情况变量HF_ENDPOINT=https://hf-mirror.com。
  • 无法毗连openai:
    由于不使用openai,因此将情况变量OPENAI_API_BASE_URL和OPENAI_API_KEY都设置成None,否则open webui在国内情况是无法毗连openai,最终导致open webui的界面是一片空缺(应用日志报错:Connection error: Cannot connect to host api.openai.com:443)。
  1. apiVersion: v1
  2. kind: PersistentVolumeClaim
  3. metadata:
  4.   name: webui-pvc
  5.   namespace: ollama
  6.   labels:
  7.     app: webui
  8. spec:
  9.   storageClassName: sfsturbo-subpath-sc
  10.   accessModes: ["ReadWriteOnce"]
  11.   resources:
  12.     requests:
  13.       storage: 2Gi
  14. ---
  15. apiVersion: apps/v1
  16. kind: Deployment
  17. metadata:
  18.   name: webui
  19.   namespace: ollama
  20. spec:
  21.   replicas: 1
  22.   selector:
  23.     matchLabels:
  24.       app: webui
  25.   template:
  26.     metadata:
  27.       labels:
  28.         app: webui
  29.     spec:
  30.       containers:
  31.         - name: webui
  32.           image: swr.cn-south-1.myhuaweicloud.com/migrator/open-webui:main
  33.           env:
  34.             - name: OLLAMA_BASE_URL             # 这是ollama的地址
  35.               value: http://ollama:11434            
  36.             - name: HF_ENDPOINT                 # 国内环境无法连接huggingface.co
  37.               value: https://hf-mirror.com
  38.             - name: OPENAI_API_KEY
  39.               value: None
  40.             - name: OPENAI_API_BASE_URL
  41.               value: None
  42.           tty: true
  43.           ports:
  44.             - containerPort: 8080
  45.           resources:
  46.             requests:
  47.               cpu: "500m"
  48.               memory: "500Mi"
  49.             limits:
  50.               cpu: "1000m"
  51.               memory: "1Gi"
  52.           volumeMounts:
  53.             - name: webui-volume
  54.               mountPath: /app/backend/data
  55.       volumes:
  56.         - name: webui-volume
  57.           persistentVolumeClaim:
  58.             claimName: webui-pvc
  59. ---
  60. apiVersion: v1
  61. kind: Service
  62. metadata:
  63.   name: webui
  64.   namespace: ollama
  65.   labels:
  66.     app: webui
  67. spec:
  68.   type: ClusterIP
  69.   ports:
  70.     - port: 8080
  71.       protocol: TCP
  72.       targetPort: 8080
  73.   selector:
  74.     app: webui
复制代码

接着为open webui容器添加ingress路由以在公网暴露:



4 下载模型

进入ollama容器:
  1. kubectl exec -it ollama-0 -n ollama bash
复制代码
在容器内执行ollama pull下令下载大模型DeepSeek-R1-Distill-Qwen-1.5B。
  1. nohup ollama pull deepseek-r1:1.5b &
  2. tail -f nohup.out
复制代码
有哪些deepseek模型可以下载,请去https://ollama.com/library/deepseek-r1地址里搜刮。

5 与大模型对话

在浏览器地址输入负载均衡器ELB的公网IP,打开网页后需要先设置open webui的管理员账号密码,登录乐成后即可选择刚刚下载的deepseek模型来谈天。



6 小结

文本介绍使用华为云kubernetes摆设open-webui最新版、ollama最新版、DeepSeek-R1-Distill-Qwen-1.5B。在现实过程中,花费时间最多的是open-webui,因为它默认去访问在国内无法访问的两个外国地址:huggingface.co和api.openai.com,而访问这些地址最终又导致界面变成空缺。

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

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

西河刘卡车医

论坛元老
这个人很懒什么都没写!
快速回复 返回顶部 返回列表