更改 BUILD_env 为 NAME_SPACES

This commit is contained in:
dxin
2025-10-30 15:00:58 +08:00
parent 275d01d858
commit b9f7ef980b
11 changed files with 411 additions and 12 deletions

View File

@@ -2,4 +2,11 @@
kubectl logs --tail=10 test-flymoon-admin-deployment-964fb6b74-ns4br -n test-lessie
# 查看指定命名空间的 Pod 和节点信息
kubectl get pods -n test-lessie -o wide
kubectl get pods -n test-lessie -o wide
# 基本删除命令
kubectl delete deployment test-lessie-sourcing-api-deployment -n <namespace>
kubectl delete -f test-lessie-go-api.yaml

View File

@@ -0,0 +1,44 @@
apiVersion: v1
data:
default.conf: |-
server {
listen 80;
server_name _;
# 前端静态文件
location / {
root /usr/share/nginx/html;
index index.html;
try_files $uri $uri/ /index.html;
}
# 精确匹配 index.html禁用缓存
location = /index.html {
root /usr/share/nginx/html;
add_header Cache-Control "no-cache, no-store, must-revalidate";
}
# 静态资源开启长缓存(带 hash
location ~* \.(js|css|woff2|json|svg|png|jpg|jpeg|gif|ico|ttf|otf|eot|mp4|webm|webp)$ {
root /usr/share/nginx/html;
add_header Cache-Control "public, max-age=31536000, immutable";
access_log off;
}
}
kind: ConfigMap
metadata:
creationTimestamp: "2025-10-30T06:21:32Z"
managedFields:
- apiVersion: v1
fieldsType: FieldsV1
fieldsV1:
f:data:
.: {}
f:default.conf: {}
manager: tke-platform-api
operation: Update
time: "2025-10-30T06:21:32Z"
name: test-default-conf
namespace: test-lessie
resourceVersion: "1846361542"
uid: 9361cebf-903c-4312-bc84-b6056cb054c7

View File

@@ -0,0 +1,24 @@
server {
listen 80;
server_name _;
# 前端静态文件
location / {
root /usr/share/nginx/html;
index index.html;
try_files $uri $uri/ /index.html;
}
# 精确匹配 index.html禁用缓存
location = /index.html {
root /usr/share/nginx/html;
add_header Cache-Control "no-cache, no-store, must-revalidate";
}
# 静态资源开启长缓存(带 hash
location ~* \.(js|css|woff2|json|svg|png|jpg|jpeg|gif|ico|ttf|otf|eot|mp4|webm|webp)$ {
root /usr/share/nginx/html;
add_header Cache-Control "public, max-age=31536000, immutable";
access_log off;
}
}

View File

@@ -0,0 +1,111 @@
# 架构变化
```
用户访问域名
腾讯云 CLB负载均衡
Ingress ControllerIngress Pod
前端 Nginx Pod静态资源
后端服务 Pod
```
## 原架构:前后端一体反代
- 拓扑:
DNS -> Nginx域名证书 + 静态资源 + 反向代理) -> 后端服务
- 特点:
- 域名证书与反向代理配置在同一 Nginx 配置文件中
- Nginx 承担两种职责:
- 提供前端静态资源HTML / JS / CSS
- 反向代理接口到后端服务
## Kubernetes 化后的角色拆分
| 原功能 | Kubernetes 中的角色 | 描述 |
|---|---|---|
| SSL 终止 / 域名路由 | Ingress Controller如 NGINX Ingress、Traefik | 负责 HTTPS 证书管理、域名路由与转发 |
| 提供静态资源 | 前端 PodNginx 容器) | 仅负责静态文件服务,不再负责后端代理 |
| 应用后端 | 后端 PodDeployment + Service | 提供 API 服务,由 Ingress 转发调用 |
## 前端 Pod 的 Docker 镜像
- 仅提供静态资源,不负责代理:
- 静态文件目录:`/usr/share/nginx/html/`,放编译好的前端静态文件
- Nginx 配置:`/etc/nginx/conf.d/default.conf`,为简化版,仅用于静态服务
- 示例 `default.conf`
```nginx
server {
listen 80;
server_name _;
root /usr/share/nginx/html;
index index.html;
location / {
try_files $uri /index.html;
}
}
```
- 该配置可放入 ConfigMap或直接 bake 到镜像中。无需 `upstream` / `proxy_pass`,反代由 Ingress 处理。
## Ingress 取代原 nginx.conf 的“反向代理部分”
- 示例 Ingress由 Ingress Controller 生成对应的 Nginx 配置):
```yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: jennie-frontend
namespace: jennie
annotations:
kubernetes.io/ingress.class: nginx
cert-manager.io/cluster-issuer: letsencrypt-prod
spec:
tls:
- hosts:
- s1.jennie.im
secretName: jennie-im-tls
rules:
- host: s1.jennie.im
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: jennie-frontend
port:
number: 80
- path: /api/
pathType: Prefix
backend:
service:
name: jennie-backend
port:
number: 8100
- path: /sit-api/
pathType: Prefix
backend:
service:
name: sit-api
port:
number: 8070
```
- SSL 证书通过 Secret 提供,例如:
`kubectl create secret tls jennie-im-tls --cert=... --key=...`
- Ingress 的路由规则等同于原 `nginx.conf` 中的多个 `location`Ingress Controller 自动生成底层配置。
## 请求流向对比
- 旧:客户端 -> Nginx (SSL + 反代 + 静态资源) -> 后端
- 新:客户端 -> Ingress Controller Pod (SSL 终止 + 路由) -> 前端 Pod 或 后端 Pod
- 静态资源(/)由 Ingress 转发到前端 Pod
- API 请求(/api/*)由 Ingress 转发到后端 Pod
- 转发逻辑在 Ingress不在前端 Pod 内
## ConfigMap、证书文件放置
| 项目 | 放置位置 | 说明 |
|---|---|---|
| 前端 `nginx.conf` | ConfigMap 或镜像内 | 若使用 Nginx 提供静态资源,可 bake 进镜像或挂载 ConfigMap |
| SSL 证书 | Secret | `type: kubernetes.io/tls` |
| Ingress 路由规则 | Ingress YAML | 替代原 `server` / `location` 的路由/反代配置 |