Files
aiops/deploy/kubernetes/README.md
T
attacker 65636b3f5a fix: favicon .ico 生成 + README 更新 + run.sh kubernetes 别名
- 新增 frontend/public/favicon.ico (4 size: 16/32/48/64)
- index.html .ico 引用调整到 .svg 前面(兼容旧浏览器)
- README.md 全量更新:Kubernetes 完整命令列表 + K8s 管理亮点
- run.sh 主入口添加 k8s 别名(向后兼容)
- aiops-development skill 更新部署命令和 favicon 文档
2026-06-25 00:53:57 +08:00

152 lines
4.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# AIOps Kubernetes 部署
AIOps 平台在 Kubernetes 上的部署清单(Go/Gin 后端 + go:embed 前端 + MySQL 8.0 + Redis 7)。
**单容器架构**:前端通过 `go:embed` 嵌入后端二进制,一个容器同时服务 API + WebSocket + SPA 静态资源,端口统一 8080。
所有资源部署在 **`devops`** 命名空间。
## 目录结构
| 文件 | 说明 |
|------|------|
| `namespace.yaml` | `devops` 命名空间 |
| `secret.yaml` | MySQL/JWT 密码(Secret) |
| `configmap.yaml` | 后端 `config.yaml`(ConfigMap) |
| `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) |
| `ingress.yaml` | Ingress:所有流量 → aiops:8080(含 WebSocket 支持) |
## 架构
```
NodePort:30080 / Ingress
│
▼
┌─── aiops (Deployment) ───┐
│ 单端口 8080: │
│ • API (/api/*) │
│ • WebSocket (/ws/*) │
│ • 前端 SPA (go:embed) │
└───────────┬───────────────┘
│
┌──────────────┼──────────────┐
▼ ▼
MySQL 8.0 Redis 7
(StatefulSet) (StatefulSet)
mysql:3306 redis:6379
10Gi PV 2Gi PV
```
## 快速部署
### 方式一:run.sh 一键部署(推荐)
```bash
# 构建镜像 + 部署全部资源
./run.sh kubernetes deploy
# 查看状态
./run.sh kubernetes status
# 查看日志
./run.sh kubernetes logs
# 更新(重新构建镜像 + 滚动更新)
./run.sh kubernetes upgrade
# 清理
./run.sh kubernetes delete
```
### 方式二:手动 kubectl
```bash
cd deploy/kubernetes
# 1. 全量部署(文件按序: namespace → secret → configmap → mysql → redis → deployment)
kubectl apply -f namespace.yaml
kubectl apply -f secret.yaml
kubectl apply -f configmap.yaml
kubectl apply -f mysql.yaml
kubectl apply -f redis.yaml
# 2. 等待数据库就绪
kubectl -n devops rollout status statefulset/mysql
kubectl -n devops rollout status statefulset/redis
# 3. 构建镜像(在本地)
cd ../..
docker build -f Dockerfile.embed -t aiops:embed .
# 4. 部署应用
kubectl apply -f deployment.yaml
kubectl -n devops rollout status deployment/aiops
# 5. Ingress(按需修改 host)
kubectl apply -f ingress.yaml
```
## 访问
```bash
# NodePort 方式
curl http://<NODE_IP>:30080/health
# 或配置 Ingress host
echo "<INGRESS_IP> aiops.local" | sudo tee -a /etc/hosts
# 浏览器: http://aiops.local
```
## 常用运维命令
```bash
# 查看所有资源
kubectl -n devops get all,pvc,configmap,secret
# 查看应用日志
kubectl -n devops logs -f deployment/aiops
# 进入应用容器
kubectl -n devops exec -it deployment/aiops -- bash
# 进入 MySQL
kubectl -n devops exec -it mysql-0 -- mysql -uaiops -paiops_pass_2026 aiops
# 滚动更新(重新构建镜像后)
kubectl -n devops rollout restart deployment/aiops
# 查看 PVC
kubectl -n devops get pvc
```
## 配置说明
| 项目 | 来源 | 值 |
|------|------|----|
| MySQL 业务账号 | Secret `aiops-secret` | 用户 `aiops` / 密码 `aiops_pass_2026` / 库 `aiops` |
| MySQL root | Secret `aiops-secret` | `aiops_root_2026` |
| JWT | Secret `aiops-secret` | `aiops-jwt-secret-key-2026` |
| Redis | 无密码 | db `0` |
> ⚠️ 生产环境请修改 `secret.yaml` 和 `configmap.yaml` 中的默认密码。
## 资源限额
| 组件 | CPU 请求/上限 | 内存请求/上限 |
|------|---------------|---------------|
| aiops | 100m / 1 | 256Mi / 1Gi |
| mysql | 250m / 1 | 512Mi / 2Gi |
| redis | 50m / 250m | 128Mi / 256Mi |
## 清理
```bash
./run.sh kubernetes delete
# 或手动(持久卷需单独删)
kubectl delete -f deploy/kubernetes/
kubectl -n devops delete pvc --all
```