在 Kubernetes 上部署 Chatwoot + Dify(生产级)
多节点 K8s 上跑 Chatwoot + Dify,配置 HPA、Ingress、Cert-Manager、PVC,端到端可上线。
Kubernetes (1.28+) 180 分钟
前提#
- 一个 K8s 集群(GKE / EKS / ACK / 自建 kubeadm 都行)
- 至少 3 节点,每节点 4C8G
- 域名 + 证书(用 cert-manager 自动签发)
总览#
步骤 1:基础组件#
# Ingress NGINX
helm install ingress-nginx ingress-nginx/ingress-nginx \
--namespace ingress-nginx --create-namespace
# cert-manager
helm install cert-manager jetstack/cert-manager \
--namespace cert-manager --create-namespace \
--set installCRDs=true
# 创建 ClusterIssuer(Let's Encrypt)
kubectl apply -f cluster-issuer.yaml
步骤 2:Chatwoot(Helm)#
helm repo add chatwoot https://chatwoot.github.io/charts
helm install chatwoot chatwoot/chatwoot \
--namespace chatwoot --create-namespace \
-f chatwoot-values.yaml
chatwoot-values.yaml 关键配置:
ingress:
enabled: true
className: nginx
annotations:
cert-manager.io/cluster-issuer: letsencrypt-prod
hosts:
- host: support.example.com
tls:
- hosts: [support.example.com]
secretName: chatwoot-tls
postgresql:
enabled: true
persistence:
size: 80Gi
redis:
enabled: true
步骤 3:Dify(自建 manifests,官方暂无 Helm)#
git clone https://github.com/langgenius/dify
cd dify/kubernetes
kubectl create namespace dify
kubectl -n dify apply -f .
Dify 的 manifests 默认是单副本,需要把 api、worker 改成 Deployment + HPA:
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: dify-api
namespace: dify
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: dify-api
minReplicas: 2
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target: { type: Utilization, averageUtilization: 70 }
步骤 4:监控#
helm install kube-prometheus-stack prometheus-community/kube-prometheus-stack \
--namespace monitoring --create-namespace
挂个 Grafana 看 Pod CPU / 内存、Ingress 请求量。
常见坑#
- PVC 用 ReadWriteMany:Chatwoot 多副本时需要共享附件目录
- Sidekiq 队列饱和:单独给 Sidekiq 加 HPA
- Cold Start:Dify worker 启动慢,HPA
behavior加 stabilizationWindowSeconds
月成本参考#
| 集群 | 节点 | 月成本(GCP) |
|---|---|---|
| 测试 | 3 × e2-medium | ~$60 |
| 小型生产 | 3 × n2-standard-4 | ~$280 |
| 中型生产 | 6 × n2-standard-4 | ~$560 |