Merge branch 'steelhead'

This commit is contained in:
2026-08-06 06:50:38 +08:00
29 changed files with 1320 additions and 354 deletions
+38 -1
View File
@@ -7,9 +7,10 @@
| 文件 | 说明 |
| --- | --- |
| `namespace.yaml` | Namespace:项目专属命名空间 `arcticnewone` |
| `deployment.yaml` | Deployment:SWR 镜像、副本数 1、私有镜像拉取 secrets |
| `deployment.yaml` | Deployment:SWR 镜像、副本数 1、私有镜像拉取 secrets、数据库/SMTP 环境变量 |
| `service.yaml` | Service:ClusterIP,80 端口转发到容器 3000 端口 |
| `ingress.yaml` | Ingress:域名 `personal.virtheart.com`,Traefik + cert-manager 自动签发证书 |
| `postgres.yaml` | (可选)集群内 PostgreSQL StatefulSet + PVC,仅在没有外部数据库时使用 |
`namespace.yaml` 负责创建 `arcticnewone` 命名空间;deployment/service/ingress 三个 YAML 的 `metadata` 均已指定 `namespace: arcticnewone`。
@@ -32,6 +33,24 @@ export SWR_PASSWORD="<密码>"
说明:脚本通过 `--output "type=image,push=true,oci-mediatypes=false"` 一步完成多架构构建推送,使用 Docker V2 manifest 格式(而非 OCI 格式,这是 SWR 兼容的关键),并禁用 provenance/SBOM(`--provenance=false --sbom=false`),保证 SWR 可正常解析。
## 数据库(PostgreSQL)
应用依赖 PostgreSQL 16+ 存储用户、联系留言与订阅数据。两种方式二选一:
### 方式 A:使用云托管数据库(推荐)
使用华为云 RDS for PostgreSQL 等托管服务(自带备份与高可用),创建数据库 `arcticnewone`,连接串格式:
`postgres://<用户>:<密码>@<主机>:<端口>/arcticnewone`
### 方式 B:集群内部署(deploy/postgres.yaml)
```bash
kubectl apply -f deploy/postgres.yaml
```
会创建一个 StatefulSet + PVC(8Gi),数据库地址为 `arcticnewone-postgres.arcticnewone.svc.cluster.local:5432`。
仅建议在测试/低负载场景使用;数据持久化依赖集群存储类。
## 部署前置条件
1. 镜像已构建并推送到华为云 SWR(通过项目根目录 `./build-and-push.sh` 执行,见上方「镜像构建与推送」)
@@ -47,6 +66,22 @@ export SWR_PASSWORD="<密码>"
--dry-run=client -o yaml | kubectl apply -f -
```
5. 创建应用配置 Secret `arcticnewone-secrets`(`database-url` 与 `jwt-secret` 必填;SMTP 项可选,不配置时联系表单/订阅仅入库不发邮件):
```bash
kubectl create secret generic arcticnewone-secrets -n arcticnewone \
--from-literal=database-url='postgres://arcticnewone:<密码>@<数据库地址>:5432/arcticnewone' \
--from-literal=jwt-secret='<随机长字符串,建议 openssl rand -hex 32>' \
--from-literal=postgres-password='<集群内数据库密码,仅方式 B 需要>' \
--from-literal=smtp-host='smtp.example.com' \
--from-literal=smtp-port='465' \
--from-literal=smtp-user='<SMTP 用户名>' \
--from-literal=smtp-pass='<SMTP 密码>' \
--from-literal=smtp-from='北极新一 <noreply@virtheart.com>' \
--from-literal=smtp-contact-to='chenchun@virtheart.com' \
--dry-run=client -o yaml | kubectl apply -f -
```
## 部署步骤
```bash
@@ -57,12 +92,14 @@ kubectl apply -f deploy/ingress.yaml
```
`namespace.yaml` 需最先应用;其余三个 YAML 自带 `namespace: arcticnewone`,`kubectl apply` 时无需额外指定。
若使用集群内数据库,还需先应用 `deploy/postgres.yaml`。
部署后验证:
```bash
kubectl get deploy,svc,ingress -n arcticnewone
kubectl rollout status deployment/arcticnewone -n arcticnewone
kubectl logs deploy/arcticnewone -n arcticnewone | grep '\[db\]' # 确认数据库连接成功
curl -I https://personal.virtheart.com
```
+49
View File
@@ -46,6 +46,55 @@ spec:
value: "0.0.0.0"
- name: PORT
value: "3000"
# 数据库连接(必填)
- name: NUXT_DATABASE_URL
valueFrom:
secretKeyRef:
name: arcticnewone-secrets
key: database-url
# JWT 签名密钥(必填)
- name: NUXT_JWT_SECRET
valueFrom:
secretKeyRef:
name: arcticnewone-secrets
key: jwt-secret
# SMTP 邮件通知(可选;不配置时表单/订阅仅入库)
- name: NUXT_SMTP_HOST
valueFrom:
secretKeyRef:
name: arcticnewone-secrets
key: smtp-host
optional: true
- name: NUXT_SMTP_PORT
valueFrom:
secretKeyRef:
name: arcticnewone-secrets
key: smtp-port
optional: true
- name: NUXT_SMTP_USER
valueFrom:
secretKeyRef:
name: arcticnewone-secrets
key: smtp-user
optional: true
- name: NUXT_SMTP_PASS
valueFrom:
secretKeyRef:
name: arcticnewone-secrets
key: smtp-pass
optional: true
- name: NUXT_SMTP_FROM
valueFrom:
secretKeyRef:
name: arcticnewone-secrets
key: smtp-from
optional: true
- name: NUXT_SMTP_CONTACT_TO
valueFrom:
secretKeyRef:
name: arcticnewone-secrets
key: smtp-contact-to
optional: true
resources:
requests:
cpu: 100m
+87
View File
@@ -0,0 +1,87 @@
# =========================================================
# Arcticnewone 可选生产数据库 - PostgreSQL StatefulSet
#
# 说明:
# - 仅当生产环境没有可用的 PostgreSQL(如华为云 RDS)时才使用本文件
# - 建议优先使用云托管数据库(RDS),自带备份/高可用,运维成本更低
# - 数据保存在 PVC(8Gi 本地存储类),如需扩容请先调整 storage
# - 部署后创建 Secret 提供连接信息(见 deploy/README.md)
# =========================================================
apiVersion: v1
kind: Service
metadata:
name: arcticnewone-postgres
namespace: arcticnewone
labels:
app: arcticnewone-postgres
spec:
clusterIP: None
ports:
- name: postgres
port: 5432
targetPort: 5432
selector:
app: arcticnewone-postgres
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: arcticnewone-postgres
namespace: arcticnewone
labels:
app: arcticnewone-postgres
spec:
serviceName: arcticnewone-postgres
replicas: 1
selector:
matchLabels:
app: arcticnewone-postgres
template:
metadata:
labels:
app: arcticnewone-postgres
spec:
containers:
- name: postgres
image: docker.m.daocloud.io/library/postgres:16-alpine
ports:
- name: postgres
containerPort: 5432
env:
- name: POSTGRES_DB
value: "arcticnewone"
- name: POSTGRES_USER
value: "arcticnewone"
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: arcticnewone-secrets
key: postgres-password
volumeMounts:
- name: data
mountPath: /var/lib/postgresql/data
resources:
requests:
cpu: 100m
memory: 256Mi
limits:
cpu: 500m
memory: 1Gi
readinessProbe:
exec:
command: ["pg_isready", "-U", "arcticnewone", "-d", "arcticnewone"]
initialDelaySeconds: 5
periodSeconds: 10
livenessProbe:
exec:
command: ["pg_isready", "-U", "arcticnewone", "-d", "arcticnewone"]
initialDelaySeconds: 15
periodSeconds: 20
volumeClaimTemplates:
- metadata:
name: data
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 8Gi