Files
2026-03-27 16:58:41 +08:00

96 lines
3.9 KiB
YAML
Raw Permalink 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.
# 03-04: Nginx + 工作节点 + IngressRouteM4
# 路径 /demo-m4指定一台工作节点按实际 FQDN 修改 kubernetes.io/hostname
# ConfigMap首页 + default.confX-Backend: M4 便于区分
---
apiVersion: v1 # ConfigMap 使用的 API 版本
kind: ConfigMap # 配置资源类型ConfigMap
metadata: # ConfigMap 标识信息
name: nginx-m4-html # ConfigMap 名称
namespace: default # 命名空间
data: # ConfigMap 数据区
index.html: | # HTML 内容:挂载到 nginx 网页目录(内部内容行不改动)
<!DOCTYPE html>
<html><head><meta charset="utf-8"><title>M4</title></head>
<body><h1>M4</h1><p>工作节点 + IngressRoute</p></body></html>
default.conf: | # nginx 配置:通过 subPath 挂载到 conf.d/default.conf内部内容行不改动
server { listen 80; server_name localhost; root /usr/share/nginx/html; index index.html; location / { add_header X-Backend "M4"; try_files $uri $uri/ /index.html; } }
---
apiVersion: apps/v1 # Deployment 使用的 API 版本
kind: Deployment # 工作负载Deployment
metadata: # Deployment 标识信息
name: nginx-m4 # Deployment 名称
namespace: default # 部署命名空间
labels: # 应用标签/矩阵标签
app: nginx-m4 # 应用标签
matrix: "02-05-m4" # 矩阵编号
spec: # Deployment 期望状态
replicas: 1 # 副本数
selector: # Deployment 选择器
matchLabels: # 标签匹配集合(用于选中模板 Pod
app: nginx-m4 # 必须与 template.metadata.labels 对上
template: # Pod 模板
metadata: # Pod 元信息
labels: # Pod 标签
app: nginx-m4 # Pod 标签
spec: # Pod 规范
nodeSelector: # 固定运行的工作节点
kubernetes.io/hostname: ylc64 # worker 节点主机名
volumes: # 卷定义
- name: html # 卷名
configMap: # 卷来源
name: nginx-m4-html # 引用的 ConfigMap 名称
containers: # 容器列表
- name: nginx # 容器名
image: nginx:alpine # nginx 镜像
ports: # 容器端口
- containerPort: 80 # HTTP 端口
volumeMounts: # 容器内挂载
- name: html # 引用 volumes[].name
mountPath: /usr/share/nginx/html/index.html # 挂到首页文件
subPath: index.html # 取 ConfigMap 的 index.html key
readOnly: true # 只读
- name: html # 仍复用同一个卷
mountPath: /etc/nginx/conf.d/default.conf # 挂到 nginx 配置文件
subPath: default.conf # 取 ConfigMap 的 default.conf key
readOnly: true # 只读
---
apiVersion: v1 # Service 使用的 API 版本
kind: Service # 网络抽象:把 Pod 暴露为稳定入口
metadata: # Service 标识
name: nginx-m4 # Service 名称
namespace: default # 命名空间
spec: # Service 期望状态
selector: # Service 选择器
app: nginx-m4 # 选中后端 Pod
ports: # 端口映射列表
- port: 80 # Service 端口
targetPort: 80 # 转发到 Pod 容器端口
---
apiVersion: traefik.io/v1alpha1 # Traefik Middleware API 版本
kind: Middleware # 中间件stripPrefix
metadata: # Middleware 标识
name: stripprefix-m4 # 名称
namespace: default # 命名空间
spec: # 中间件配置
stripPrefix: # 去除路径前缀
prefixes: # 前缀列表
- /demo-m4 # 本矩阵路径前缀
---
apiVersion: traefik.io/v1alpha1 # IngressRoute API 版本
kind: IngressRoute # Traefik 路由 CRD
metadata: # IngressRoute 标识
name: nginx-m4 # 路由名称
namespace: default # 命名空间
spec: # IngressRoute 规则
entryPoints: # 入口点列表
- web # webHTTP
routes: # 路由列表
- match: PathPrefix(`/demo-m4`) # 匹配 /demo-m4 前缀
kind: Rule # 规则类型
middlewares: # 绑定中间件
- name: stripprefix-m4 # 需要去前缀
services: # 后端服务列表
- name: nginx-m4 # Service 名称
port: 80 # Service 端口