MCP应用k8s部署
一、概述
生产环境dify是部署在k8s里面的,MCP应用虽然在ECS的docker中运行,没法做到统一管理,所以需要部署在k8s里面才行。
二、部署
推送镜像
上一篇文章,已经制作好了docker镜像,链接:https://www.cnblogs.com/xiao987334176/p/18827297
这里就需要把镜像推送到harbor私有仓库
docker tag mysql_mcp_server_pro:v1 harbor.qq.com:8083/mcp/mysql_mcp_server_pro:v1 docker push harbor.qq.com:8083/mcp/mysql_mcp_server_pro:v1
命名空间
创建命名空间mcp
kubectl create namespace mcp
创建拉取镜像需要的密钥
kubectl create secret docker-registry harbor-key --docker-server=harbor.qq.com:8083 --docker-username=devops --docker-password=1sB5r9UShgK5 --namespace=mcp
编写yaml文件
Deployment.yaml
apiVersion: apps/v1 kind: Deployment metadata: namespace: mcp name: mysql-mcp-server-pro labels: app: mysql-mcp-server-pro spec: selector: matchLabels: app: mysql-mcp-server-pro replicas: 1 template: metadata: labels: app: mysql-mcp-server-pro spec: imagePullSecrets: - name: harbor-key containers: - name: mysql-mcp-server-pro image: "harbor.qq.com/mcp/mysql_mcp_server_pro:v1" imagePullPolicy: Always env: - name: MYSQL_HOST value: '192.168.20.128' - name: MYSQL_PORT value: '3306' - name: MYSQL_USER value: 'root' - name: MYSQL_PASSWORD value: 'abcd@1234' - name: MYSQL_DATABASE value: 'test' resources: limits: cpu: 0.1 memory: 300Mi requests: cpu: 0.1 memory: 100Mi ports: - containerPort: 9000
Service.yaml
apiVersion: v1 kind: Service metadata: namespace: mcp name: mysql-mcp-server-pro-svc labels: app: mysql-mcp-server-pro-svc spec: ports: - port: 9000 name: mysql-mcp-server-pro-svc selector: app: mysql-mcp-server-pro
发布应用
kubectl apply -f Deployment.yaml
kubectl apply -f Service.yaml
三、dify测试
登录dify,编辑插件MCP SSE

修改配置

修改为k8s svc地址
{ "mysql-mcp-server-pro": { "url": "http://mysql-mcp-server-pro-svc.mcp:9000/sse", "headers": {}, "timeout": 60, "sse_read_timeout": 300 } }
进入dify工作流,修改mcp地址

测试dify工作流


浙公网安备 33010602011771号