fix(k8s): 同步 local 模式数据路径为 /app/sqlite3.db 与二进制同级

- deployment/quick-deploy: PVC 挂载 sqlite3.db/redka.db 到 /app/,含旧 data/ 迁移
- configmap 与 run.sh 状态输出对齐新路径
- README 补充 local 模式说明
This commit is contained in:
Logan.Li committed 2026-06-26 16:19:03 +08:00
1 parent d27a2e6cbe
commit 8df0acb338
7 files changed
+71 -10

No files matched your search

+12
View File
@@ -16,6 +16,7 @@ AIOps 平台在 Kubernetes 上的部署清单(Go/Gin 后端 + go:embed 前端
| `mysql.yaml` | MySQL 8.0 StatefulSet + Headless Service + 10Gi 持久卷 |
| `redis.yaml` | Redis 7 StatefulSet + Headless Service + 2Gi 持久卷 |
| `deployment.yaml` | AIOps Deployment(embed 单端口 8080)+ NodePort Service (30080) |
| `pvc-aiops-data.yaml` | local 模式 PVC:`sqlite3.db` / `redka.db` 与 `/app/aiops` 同级 |
| `ingress.yaml` | Ingress:所有流量 → aiops:8080(含 WebSocket 支持) |
## 架构
@@ -123,6 +124,17 @@ kubectl -n devops get pvc
## 配置说明
### local 模式(默认 `MODE=local`)
- 容器内工作目录 `/app`,数据文件与二进制同级:
- `/app/aiops` — 应用二进制(镜像内)
- `/app/sqlite3.db` — SQLite(PVC 持久化)
- `/app/redka.db` — 本地缓存(PVC 持久化)
- `replicas` 必须为 **1**(SQLite 不支持多副本共享);`./run.sh kubernetes scale` 扩到 >1 时会自动切 `MODE=release` + MySQL/Redis
- 旧版 PVC 若存有 `data/sqlite3.db`,init 容器会自动迁移到根路径
### 集群凭据
| 项目 | 来源 | 值 |
|------|------|----|
| MySQL 业务账号 | Secret `aiops-secret` | 用户 `aiops` / 密码 `aiops_pass_2026` / 库 `aiops` |
+1 -1
View File
@@ -15,7 +15,7 @@ data:
database:
driver: sqlite
dbname: data/sqlite3.db
dbname: sqlite3.db
max_conn: 100
max_idle: 10
+25 -1
View File
@@ -37,6 +37,25 @@ spec:
hostNetwork: true
dnsPolicy: ClusterFirstWithHostNet
enableServiceLinks: false
# 首次部署时在 PVC 中预创建库文件,避免 subPath 挂载成目录 // Logan.Li
initContainers:
- name: init-local-db
image: busybox:1.36
command:
- sh
- -c
- |
if [ -f /vol/data/sqlite3.db ] && [ ! -f /vol/sqlite3.db ]; then
cp /vol/data/sqlite3.db /vol/sqlite3.db
fi
if [ -f /vol/data/redka/redka.db ] && [ ! -f /vol/redka.db ]; then
cp /vol/data/redka/redka.db /vol/redka.db
fi
[ -f /vol/sqlite3.db ] || install -m 644 /dev/null /vol/sqlite3.db
[ -f /vol/redka.db ] || install -m 644 /dev/null /vol/redka.db
volumeMounts:
- name: data
mountPath: /vol
containers:
- name: aiops
image: 10.10.10.72/library/aiops:embed
@@ -77,8 +96,13 @@ spec:
readOnly: true
- name: uploads
mountPath: /app/uploads
# local 模式:sqlite3.db / redka.db 与 /app/aiops 同级持久化 // Logan.Li
- name: data
mountPath: /app/data
mountPath: /app/sqlite3.db
subPath: sqlite3.db
- name: data
mountPath: /app/redka.db
subPath: redka.db
readinessProbe:
httpGet:
+1 -1
View File
@@ -1,4 +1,4 @@
# pvc-aiops-data.yaml — local 模式 SQLite + redka 数据持久化
# pvc-aiops-data.yaml — local 模式 sqlite3.db + redka.db 持久化(挂载到 /app/ 与二进制同级)
# 部署: kubectl apply -f pvc-aiops-data.yaml
apiVersion: v1
kind: PersistentVolumeClaim
+25 -3
View File
@@ -4,7 +4,7 @@
#
# 两种模式:
# 远程模式 (默认): MODE=release, 连接外部 MySQL + Redis
# 本地模式: MODE=local, 自动 SQLite (data/sqlite3.db) + redka 本地缓存
# 本地模式: MODE=local, 自动 SQLite (sqlite3.db) + redka (redka.db),与二进制同级 /app/
---
apiVersion: v1
kind: ConfigMap
@@ -19,7 +19,7 @@ data:
database:
driver: sqlite
dbname: data/sqlite3.db
dbname: sqlite3.db
redis:
driver: redka
@@ -55,6 +55,24 @@ spec:
spec:
hostNetwork: true
dnsPolicy: ClusterFirstWithHostNet
initContainers:
- name: init-local-db
image: busybox:1.36
command:
- sh
- -c
- |
if [ -f /vol/data/sqlite3.db ] && [ ! -f /vol/sqlite3.db ]; then
cp /vol/data/sqlite3.db /vol/sqlite3.db
fi
if [ -f /vol/data/redka/redka.db ] && [ ! -f /vol/redka.db ]; then
cp /vol/data/redka/redka.db /vol/redka.db
fi
[ -f /vol/sqlite3.db ] || install -m 644 /dev/null /vol/sqlite3.db
[ -f /vol/redka.db ] || install -m 644 /dev/null /vol/redka.db
volumeMounts:
- name: data
mountPath: /vol
containers:
- name: aiops
image: aiops:embed
@@ -84,7 +102,11 @@ spec:
subPath: config.yaml
readOnly: true
- name: data
mountPath: /app/data
mountPath: /app/sqlite3.db
subPath: sqlite3.db
- name: data
mountPath: /app/redka.db
subPath: redka.db
resources:
requests:
cpu: 100m