# k01 业务集群部署 承载 juwan-backend 全部业务的 k3s 单节点集群(演示阶段),后续可扩 k02 / k03。 ## 架构层次 | 层 | 组件 | |---|---| | 控制面 | k3s server(已禁用内置 traefik) | | Operator | CloudNativePG / Strimzi Kafka / Ot-Container-Kit Redis / MongoDB Community | | 数据 | 11 CNPG Cluster / 12 RedisReplication / Strimzi KRaft Kafka 1 broker / MongoDBCommunity 单实例 | | 网络 | envoy-gateway(NodePort 30080)/ ratelimit + rl-redis | | 业务 | snowflake、authz-adapter、12 rpc、14 api、email-mq、frontend | ## 入口路径 ``` juwan.xhttp.zip ├─ /wt/* → center Caddy → k01 chat-api UDP 8443(hostPort) └─ 其他 → center Caddy → k01 envoy-gateway TCP 30080 ``` ## 前置条件 - Ubuntu 26.04 LTS,root - center 已部署,registry.juwan.xhttp.zip 可推可拉 - DNS:`juwan.xhttp.zip` A 记录指向 k01(140.82.15.92) - 仓库已复制到 `/root/juwan-backend` ## 首次部署 ```bash cd /root/juwan-backend/deploy/k01 # 1. zot admin 密码写到文件供 install-k3s 读取 echo "" > /root/registry-password chmod 600 /root/registry-password # 2. 装 k3s + 4 个 Operator bash install-k3s.sh # 3. 准备 .env,填入 zot 凭据 / brevo SMTP / garage S3 凭据等 cp .env.example .env nano .env # 4. 应用 namespace + RBAC,生成所有 k8s Secret kubectl apply -f 00-base/ bash secrets.sh # 5. 应用基础设施 kubectl apply -f 01-infra/postgres.yaml kubectl apply -f 01-infra/redis.yaml kubectl apply -f 01-infra/mongo.yaml kubectl apply -f 01-infra/kafka.yaml kubectl apply -f 01-infra/ratelimit.yaml kubectl apply -f 01-infra/envoy.yaml # 等所有 CNPG Cluster Ready,灌入 schema + fixture bash 01-infra/load-schema.sh # 6. 应用业务服务 kubectl apply -f 02-service/ # 7. 观察 pod kubectl -n juwan get pods -w ``` ## 凭据管理 `secrets.sh` 生成的全部明文密码写入 `secrets/` 目录,`chmod 600`,`.gitignore` 已排除。 | Secret | 用途 | |---|---| | `registry-creds` | imagePullSecret(zot) | | `jwt-secret` | user-rpc 签发 / 校验 JWT | | `admin-bootstrap` | user-rpc 启动时插入 admin 账号 | | `email-smtp` | email-mq 发邮件 | | `objectstory-s3` | objectstory-rpc 接 garage | | `chat-wt-tls` | chat-api WT 自签证书(来自 `deploy/dev/certs`) | | `-redis` | 12 个 RedisReplication 的 password | | `chat-mongodb-app-user-password` | MongoDB SCRAM 密码 | | `-app` | CNPG 自动生成的 PG 凭据 | ## 已知限制 - snowflake 使用 Deployment + WorkerId=0。扩到多副本前需让 snowflake 业务代码支持从 env 读 WorkerId。 - chat-api UDP 8443 走 hostPort,扩 k02/k03 时新 node 需开放 UDP 8443,DNS 也要做轮询或 LB。 - email-api 复用 user-redis 实例(验证码 key 与 user-rpc 共享读写),跟 dev 行为一致。 - HPA 暂不部署。加副本前把 `replicas: 1` 改大或加 HPA。 ## 加节点(k02 / k03) ```bash # 在 k01 取 token cat /var/lib/rancher/k3s/server/node-token # 在 k02 上 curl -sfL https://get.k3s.io | \ K3S_URL=https://140.82.15.92:6443 K3S_TOKEN= \ sh - # 复制 registries.yaml scp root@140.82.15.92:/etc/rancher/k3s/registries.yaml \ /etc/rancher/k3s/registries.yaml systemctl restart k3s-agent ``` ## 与 center 协同 | 事项 | 哪一边 | |---|---| | `juwan.xhttp.zip` LE 证书 | center Caddy 自动签 | | WebTransport 终结 | center Caddy(PR 7669 fork) | | WebTransport 上游 | k01 chat-api UDP 8443(hostPort) | | envoy-gateway 上游 | k01 NodePort 30080 | | 镜像拉取 | k01 containerd → registry.juwan.xhttp.zip | | S3 后端 | k01 objectstory-rpc → s3.juwan.xhttp.zip → center Garage | | CD 触发 | gitea Actions runner(在 center) → kubectl 远程操作 k01 |