82 lines
3.1 KiB
Markdown
82 lines
3.1 KiB
Markdown
# Arcticnewone 生产部署配置
|
||
|
||
本目录存放 Arcticnewone 个人网站的 Kubernetes 生产部署配置(华为云 SWR 镜像 + Traefik Ingress)。所有资源统一部署在 `arcticnewone` 命名空间中。
|
||
|
||
## 文件说明
|
||
|
||
| 文件 | 说明 |
|
||
| --- | --- |
|
||
| `namespace.yaml` | Namespace:项目专属命名空间 `arcticnewone` |
|
||
| `deployment.yaml` | Deployment:SWR 镜像、副本数 1、私有镜像拉取 secrets |
|
||
| `service.yaml` | Service:ClusterIP,80 端口转发到容器 3000 端口 |
|
||
| `ingress.yaml` | Ingress:域名 `personal.virtheart.com`,Traefik + cert-manager 自动签发证书 |
|
||
|
||
`namespace.yaml` 负责创建 `arcticnewone` 命名空间;deployment/service/ingress 三个 YAML 的 `metadata` 均已指定 `namespace: arcticnewone`。
|
||
|
||
## 镜像构建与推送
|
||
|
||
镜像由项目根目录的 `build-and-push.sh` 构建并推送到华为云 SWR(单架构 `linux/amd64`,tag 统一为 `latest`):
|
||
|
||
```bash
|
||
# 1. 设置环境变量(凭据绝不写入仓库)
|
||
export SWR_REGISTRY="swr.cn-north-4.myhuaweicloud.com"
|
||
export SWR_NAMESPACE="virtheart"
|
||
export SWR_USERNAME="<用户名>"
|
||
export SWR_PASSWORD="<密码>"
|
||
|
||
# 2. 执行构建与推送
|
||
./build-and-push.sh
|
||
```
|
||
|
||
推送完成后镜像地址:`swr.cn-north-4.myhuaweicloud.com/virtheart/arcticnewone:latest`。
|
||
|
||
说明:SWR 不支持 buildx 多架构推送的 OCI manifest 格式,脚本改为 `docker build` + `docker push` 分步执行,并禁用 provenance(`--provenance=false`),保证镜像可被 SWR 正常解析。
|
||
|
||
## 部署前置条件
|
||
|
||
1. 镜像已构建并推送到华为云 SWR(通过项目根目录 `./build-and-push.sh` 执行,见上方「镜像构建与推送」)
|
||
2. 集群已安装 Traefik Ingress 与 cert-manager(ClusterIssuer 名称为 `lets-encrypt`)
|
||
3. 域名 `personal.virtheart.com` 的 DNS 已解析到集群入口
|
||
4. 创建私有镜像拉取 Secret(凭据从环境变量读取,绝不写入仓库;命名空间由 `namespace.yaml` 创建):
|
||
|
||
```bash
|
||
kubectl create secret docker-registry huawei-swr-secret -n arcticnewone \
|
||
--docker-server="$SWR_REGISTRY" \
|
||
--docker-username="$SWR_USERNAME" \
|
||
--docker-password="$SWR_PASSWORD" \
|
||
--dry-run=client -o yaml | kubectl apply -f -
|
||
```
|
||
|
||
## 部署步骤
|
||
|
||
```bash
|
||
kubectl apply -f deploy/namespace.yaml
|
||
kubectl apply -f deploy/deployment.yaml
|
||
kubectl apply -f deploy/service.yaml
|
||
kubectl apply -f deploy/ingress.yaml
|
||
```
|
||
|
||
`namespace.yaml` 需最先应用;其余三个 YAML 自带 `namespace: arcticnewone`,`kubectl apply` 时无需额外指定。
|
||
|
||
部署后验证:
|
||
|
||
```bash
|
||
kubectl get deploy,svc,ingress -n arcticnewone
|
||
kubectl rollout status deployment/arcticnewone -n arcticnewone
|
||
curl -I https://personal.virtheart.com
|
||
```
|
||
|
||
## 回滚方案
|
||
|
||
镜像 tag 固定为 `latest`,回滚前先确认 SWR 上 `latest` 对应可回滚的版本(或先推送目标版本镜像),再执行:
|
||
|
||
```bash
|
||
# 回滚到上一版本镜像
|
||
kubectl rollout undo deployment/arcticnewone -n arcticnewone
|
||
|
||
# 或整体移除本次部署的资源
|
||
kubectl delete -f deploy/ingress.yaml -n arcticnewone
|
||
kubectl delete -f deploy/service.yaml -n arcticnewone
|
||
kubectl delete -f deploy/deployment.yaml -n arcticnewone
|
||
```
|