feat: 添加 Dockerfile、docker-compose 及 K8s kustomize 部署文件
This commit is contained in:
+118
@@ -0,0 +1,118 @@
|
||||
# GraphRAG Studio — Kubernetes 部署指南
|
||||
|
||||
## 目录结构
|
||||
|
||||
```
|
||||
k8s/
|
||||
├── base/ # 共享资源(所有环境通用)
|
||||
│ ├── kustomization.yaml
|
||||
│ ├── backend-deployment.yaml
|
||||
│ ├── backend-service.yaml
|
||||
│ ├── frontend-deployment.yaml
|
||||
│ ├── frontend-service.yaml
|
||||
│ └── persistent-volume-claims.yaml
|
||||
├── overlays/
|
||||
│ ├── test/ # 测试环境
|
||||
│ │ ├── kustomization.yaml
|
||||
│ │ ├── namespace.yaml # → graphrag-test
|
||||
│ │ └── ingress.yaml # → test-graphrag.plfai.cn
|
||||
│ └── prod/ # 生产环境
|
||||
│ ├── kustomization.yaml
|
||||
│ ├── namespace.yaml # → graphrag-prod
|
||||
│ ├── replicas-patch.yaml # → 后端 2 副本
|
||||
│ └── ingress.yaml # → graphrag.plfai.cn
|
||||
└── README.md
|
||||
```
|
||||
|
||||
## 环境差异
|
||||
|
||||
| 项目 | test | prod |
|
||||
|------|------|------|
|
||||
| 命名空间 | `graphrag-test` | `graphrag-prod` |
|
||||
| 前端域名 | `test-graphrag.plfai.cn` | `graphrag.plfai.cn` |
|
||||
| 后端域名 | `test-graphrag-backend.plfai.cn` | `graphrag-backend.plfai.cn` |
|
||||
| 后端副本 | 1 | 2 |
|
||||
| 资源名前缀 | `test-` | `prod-` |
|
||||
| ConfigMap / Secret | 各自独立 | 各自独立 |
|
||||
|
||||
## 架构
|
||||
|
||||
```
|
||||
浏览器 → Ingress
|
||||
├── test-graphrag.plfai.cn ──→ graphrag-test/frontend:80
|
||||
├── test-graphrag-backend.plfai.cn ──→ graphrag-test/backend:8000
|
||||
├── graphrag.plfai.cn ──→ graphrag-prod/frontend:80
|
||||
└── graphrag-backend.plfai.cn ──→ graphrag-prod/backend:8000
|
||||
```
|
||||
|
||||
## 部署
|
||||
|
||||
### 1. 配置密钥
|
||||
|
||||
```bash
|
||||
# 编辑 test 环境 Secret
|
||||
vim k8s/overlays/test/kustomization.yaml
|
||||
# 修改 secretGenerator.literals 中的实际 Key
|
||||
|
||||
# 编辑 prod 环境 Secret
|
||||
vim k8s/overlays/prod/kustomization.yaml
|
||||
# 修改 secretGenerator.literals 中的实际 Key
|
||||
```
|
||||
|
||||
### 2. 构建镜像
|
||||
|
||||
```bash
|
||||
# 在项目根目录执行
|
||||
docker build -t graphrag-backend:latest -f backend/Dockerfile .
|
||||
docker build -t graphrag-frontend:latest -f frontend/Dockerfile .
|
||||
```
|
||||
|
||||
### 3. 部署
|
||||
|
||||
```bash
|
||||
# 部署测试环境
|
||||
kubectl apply -k k8s/overlays/test
|
||||
|
||||
# 部署生产环境
|
||||
kubectl apply -k k8s/overlays/prod
|
||||
```
|
||||
|
||||
### 4. 预览生成的 YAML(不实际部署)
|
||||
|
||||
```bash
|
||||
kubectl kustomize k8s/overlays/test
|
||||
kubectl kustomize k8s/overlays/prod
|
||||
```
|
||||
|
||||
### 5. 验证
|
||||
|
||||
```bash
|
||||
# 检查所有 Pod
|
||||
kubectl -n graphrag-test get pods
|
||||
kubectl -n graphrag-prod get pods
|
||||
|
||||
# 检查 Ingress
|
||||
kubectl -n graphrag-test get ingress
|
||||
kubectl -n graphrag-prod get ingress
|
||||
|
||||
# 测试
|
||||
curl -s https://test-graphrag.plfai.cn # 前端
|
||||
curl -s https://test-graphrag-backend.plfai.cn/api/v1/health # 后端
|
||||
# 生产
|
||||
curl -s https://graphrag.plfai.cn # 前端
|
||||
curl -s https://graphrag-backend.plfai.cn/api/v1/health # 后端
|
||||
```
|
||||
|
||||
### 6. 删除
|
||||
|
||||
```bash
|
||||
kubectl delete -k k8s/overlays/test
|
||||
kubectl delete -k k8s/overlays/prod
|
||||
```
|
||||
|
||||
## 注意事项
|
||||
|
||||
1. **Secret 安全**:Kustomize 的 `secretGenerator` 输出为 base64 编码,生产建议配合 External Secrets Operator 或 Sealed Secrets
|
||||
2. **PVC**:base 中 PVC 使用 `ReadWriteOnce`,prod 后端 2 副本需确保存储类支持,或改用对象存储
|
||||
3. **Ingress Controller**:集群需已安装 nginx-ingress-controller
|
||||
4. **TLS**:当前 Ingress 未配置 TLS,生产环境请添加 cert-manager 注解
|
||||
@@ -0,0 +1,62 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: backend
|
||||
labels:
|
||||
app: graphrag
|
||||
component: backend
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: graphrag
|
||||
component: backend
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: graphrag
|
||||
component: backend
|
||||
spec:
|
||||
containers:
|
||||
- name: backend
|
||||
image: graphrag-backend:latest
|
||||
imagePullPolicy: IfNotPresent
|
||||
ports:
|
||||
- containerPort: 8000
|
||||
protocol: TCP
|
||||
envFrom:
|
||||
- configMapRef:
|
||||
name: graphrag-config
|
||||
- secretRef:
|
||||
name: graphrag-secrets
|
||||
volumeMounts:
|
||||
- name: backend-data
|
||||
mountPath: /app/backend/data
|
||||
- name: mineru-output
|
||||
mountPath: /app/mineru_mvp/output
|
||||
resources:
|
||||
requests:
|
||||
memory: "512Mi"
|
||||
cpu: "250m"
|
||||
limits:
|
||||
memory: "2Gi"
|
||||
cpu: "1000m"
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
path: /api/v1/health
|
||||
port: 8000
|
||||
initialDelaySeconds: 20
|
||||
periodSeconds: 30
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
path: /api/v1/health
|
||||
port: 8000
|
||||
initialDelaySeconds: 10
|
||||
periodSeconds: 10
|
||||
volumes:
|
||||
- name: backend-data
|
||||
persistentVolumeClaim:
|
||||
claimName: backend-data-pvc
|
||||
- name: mineru-output
|
||||
persistentVolumeClaim:
|
||||
claimName: mineru-output-pvc
|
||||
@@ -0,0 +1,17 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: backend
|
||||
labels:
|
||||
app: graphrag
|
||||
component: backend
|
||||
spec:
|
||||
type: ClusterIP
|
||||
selector:
|
||||
app: graphrag
|
||||
component: backend
|
||||
ports:
|
||||
- name: http
|
||||
port: 8000
|
||||
targetPort: 8000
|
||||
protocol: TCP
|
||||
@@ -0,0 +1,45 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: frontend
|
||||
labels:
|
||||
app: graphrag
|
||||
component: frontend
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: graphrag
|
||||
component: frontend
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: graphrag
|
||||
component: frontend
|
||||
spec:
|
||||
containers:
|
||||
- name: frontend
|
||||
image: graphrag-frontend:latest
|
||||
imagePullPolicy: IfNotPresent
|
||||
ports:
|
||||
- containerPort: 80
|
||||
protocol: TCP
|
||||
resources:
|
||||
requests:
|
||||
memory: "64Mi"
|
||||
cpu: "100m"
|
||||
limits:
|
||||
memory: "256Mi"
|
||||
cpu: "500m"
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
path: /
|
||||
port: 80
|
||||
initialDelaySeconds: 5
|
||||
periodSeconds: 30
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
path: /
|
||||
port: 80
|
||||
initialDelaySeconds: 3
|
||||
periodSeconds: 10
|
||||
@@ -0,0 +1,17 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: frontend
|
||||
labels:
|
||||
app: graphrag
|
||||
component: frontend
|
||||
spec:
|
||||
type: ClusterIP
|
||||
selector:
|
||||
app: graphrag
|
||||
component: frontend
|
||||
ports:
|
||||
- name: http
|
||||
port: 80
|
||||
targetPort: 80
|
||||
protocol: TCP
|
||||
@@ -0,0 +1,9 @@
|
||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||
kind: Kustomization
|
||||
|
||||
resources:
|
||||
- backend-deployment.yaml
|
||||
- backend-service.yaml
|
||||
- frontend-deployment.yaml
|
||||
- frontend-service.yaml
|
||||
- persistent-volume-claims.yaml
|
||||
@@ -0,0 +1,21 @@
|
||||
apiVersion: v1
|
||||
kind: PersistentVolumeClaim
|
||||
metadata:
|
||||
name: backend-data-pvc
|
||||
spec:
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
resources:
|
||||
requests:
|
||||
storage: 10Gi
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: PersistentVolumeClaim
|
||||
metadata:
|
||||
name: mineru-output-pvc
|
||||
spec:
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
resources:
|
||||
requests:
|
||||
storage: 5Gi
|
||||
@@ -0,0 +1,29 @@
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: graphrag-ingress
|
||||
annotations:
|
||||
nginx.ingress.kubernetes.io/proxy-body-size: "200m"
|
||||
nginx.ingress.kubernetes.io/proxy-read-timeout: "120"
|
||||
spec:
|
||||
rules:
|
||||
- host: graphrag-backend.plfai.cn
|
||||
http:
|
||||
paths:
|
||||
- path: /
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: backend
|
||||
port:
|
||||
number: 8000
|
||||
- host: graphrag.plfai.cn
|
||||
http:
|
||||
paths:
|
||||
- path: /
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: frontend
|
||||
port:
|
||||
number: 80
|
||||
@@ -0,0 +1,29 @@
|
||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||
kind: Kustomization
|
||||
|
||||
namespace: graphrag-prod
|
||||
|
||||
namePrefix: prod-
|
||||
|
||||
resources:
|
||||
- ../../base
|
||||
- namespace.yaml
|
||||
|
||||
configMapGenerator:
|
||||
- name: graphrag-config
|
||||
behavior: replace
|
||||
literals:
|
||||
- DEEPSEEK_BASE_URL=https://api.deepseek.com
|
||||
- MINERU_PIPELINE=/app/mineru_mvp/pipeline.py
|
||||
- MINERU_PYTHON=/opt/venv/bin/python
|
||||
|
||||
secretGenerator:
|
||||
- name: graphrag-secrets
|
||||
behavior: replace
|
||||
literals:
|
||||
- DEEPSEEK_API_KEY=sk-prod-placeholder
|
||||
- MINERU_API_TOKEN=prod-placeholder
|
||||
|
||||
patches:
|
||||
- path: ingress.yaml
|
||||
- path: replicas-patch.yaml
|
||||
@@ -0,0 +1,4 @@
|
||||
apiVersion: v1
|
||||
kind: Namespace
|
||||
metadata:
|
||||
name: graphrag-prod
|
||||
@@ -0,0 +1,6 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: backend
|
||||
spec:
|
||||
replicas: 2
|
||||
@@ -0,0 +1,29 @@
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: graphrag-ingress
|
||||
annotations:
|
||||
nginx.ingress.kubernetes.io/proxy-body-size: "200m"
|
||||
nginx.ingress.kubernetes.io/proxy-read-timeout: "120"
|
||||
spec:
|
||||
rules:
|
||||
- host: test-graphrag-backend.plfai.cn
|
||||
http:
|
||||
paths:
|
||||
- path: /
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: backend
|
||||
port:
|
||||
number: 8000
|
||||
- host: test-graphrag.plfai.cn
|
||||
http:
|
||||
paths:
|
||||
- path: /
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: frontend
|
||||
port:
|
||||
number: 80
|
||||
@@ -0,0 +1,28 @@
|
||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||
kind: Kustomization
|
||||
|
||||
namespace: graphrag-test
|
||||
|
||||
namePrefix: test-
|
||||
|
||||
resources:
|
||||
- ../../base
|
||||
- namespace.yaml
|
||||
|
||||
configMapGenerator:
|
||||
- name: graphrag-config
|
||||
behavior: replace
|
||||
literals:
|
||||
- DEEPSEEK_BASE_URL=https://api.deepseek.com
|
||||
- MINERU_PIPELINE=/app/mineru_mvp/pipeline.py
|
||||
- MINERU_PYTHON=/opt/venv/bin/python
|
||||
|
||||
secretGenerator:
|
||||
- name: graphrag-secrets
|
||||
behavior: replace
|
||||
literals:
|
||||
- DEEPSEEK_API_KEY=sk-test-placeholder
|
||||
- MINERU_API_TOKEN=test-placeholder
|
||||
|
||||
patches:
|
||||
- path: ingress.yaml
|
||||
@@ -0,0 +1,4 @@
|
||||
apiVersion: v1
|
||||
kind: Namespace
|
||||
metadata:
|
||||
name: graphrag-test
|
||||
Reference in New Issue
Block a user