Files
juwan-backend/deploy/k01/README.md
T

92 lines
3.1 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.
# k01 业务集群
k01 是 juwan-backend 的 k3s 单节点集群。公网入口由 center 的 Caddy 接管——`/wt/*` 走 UDP 直达 chat-api,其余路径反代到 envoy-gateway NodePort 30080。演示阶段一台机器跑完数据层与全部 Go 服务,之后可以加 k02 / k03 扩展。
部署机参考:Vultr Regular / 1 vCPU / 1 GB RAM / 32 GB NVMe。
## 前置条件
- Ubuntu 26.04 LTSroot
- center 已部署,`registry.juwan.xhttp.zip` 可推可拉
- 仓库已复制到 `/root/juwan-backend`
- `/root/registry-password` 文件存放 zot admin 密码(`chmod 600`
## 首次部署
```bash
cd /root/juwan-backend/deploy/k01
# 装 k3s(禁用内置 traefik+ Helm + 四个 Operator
bash install-k3s.sh
# 准备 .env,填 zot Admin 密码 / Brevo SMTP / Garage S3 凭据
cp .env.example .env
nano .env
# 应用 namespace + RBAC,生成全部 k8s Secret
kubectl apply -f 00-base/
bash secrets.sh
# 应用基础设施(Operator CR
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
# 等 PostgreSQL Cluster 全部 Ready 后再灌 schema
bash 01-infra/load-schema.sh
# 启动业务服务
kubectl apply -f 02-service/
kubectl -n juwan get pods -w
```
## 做什么
四层结构。控制面是 k3s server,跑着 CNPG / Strimzi / Redis / MongoDB 四个 Operator 管理有状态服务。
数据层 11 个 per-domain PostgreSQL Cluster + 12 个 RedisReplication + 1 个 MongoDBCommunitychat+ Strimzi KRaft Kafka1 broker)。
业务层 27 个 Go 服务镜像指向 `registry.juwan.xhttp.zip/juwan/<name>:latest`,每个 domain 一套 rpc + api,外加 snowflake、authz-adapter、email-mq 和 frontend。所有 Deployment 带 `imagePullSecrets: registry-creds`containerd 的 `registries.yaml` 配了 zot admin 凭据。
email-api 跟 user-rpc 共用 user-redis 实例,因为注册和重置密码的验证码 key 跨服务读写。
chat-api 的 WebTransport 走 UDP 8443 hostPortcenter Caddy 的 PR 7669 fork 把这路流量终结后反代过来。
## 生成的 Secret
`secrets.sh``secrets/` 目录填满随机密码,同时 `kubectl create secret``juwan` namespace。需要用户自己填的是 `.env` 里的 zot admin 密码、Brevo SMTP key 和 Garage S3 access key。
CNPG 每个 Cluster Ready 后自动生成 `<cluster>-app` Secretusername/password/dbname/host/port),业务 pod 的 env 直接从这些 Secret 取值。
## 加节点
k01 上取 k3s 的 node-token
```bash
cat /var/lib/rancher/k3s/server/node-token
```
k02 加入集群:
```bash
curl -sfL https://get.k3s.io | \
K3S_URL=https://140.82.15.92:6443 K3S_TOKEN=<token> \
sh -
scp root@140.82.15.92:/etc/rancher/k3s/registries.yaml /etc/rancher/k3s/
systemctl restart k3s-agent
```
pod 调度靠 k3s 自动分配。有状态的想粘在指定 node 上就加 `nodeSelector`
## 日常操作
```bash
kubectl -n juwan get pods -o wide
kubectl -n juwan rollout restart deploy/user-rpc
kubectl -n kafka get kafka,kafkatopic,kafkanodepool
```