对齐文件规范
This commit is contained in:
101
ansible/files/02-05/01-control-ingress.yaml
Normal file
101
ansible/files/02-05/01-control-ingress.yaml
Normal file
@@ -0,0 +1,101 @@
|
||||
# 02-05: Nginx + 控制节点 + Ingress(M1)
|
||||
# 路径 /demo-m1,随机一台控制节点(nodeSelector + toleration,控制节点常有 NoSchedule 污点)
|
||||
# ConfigMap:首页 + default.conf(单文件 subPath 挂载,与 M2~M4 一致,便于 nginx 后续扩展)
|
||||
---
|
||||
apiVersion: v1 # ConfigMap 使用的 API 版本
|
||||
kind: ConfigMap # 配置资源类型:ConfigMap
|
||||
metadata: # 对该 ConfigMap 的标识信息
|
||||
name: nginx-m1-html # ConfigMap 名称
|
||||
namespace: default # 命名空间
|
||||
data: # ConfigMap 数据键值区
|
||||
index.html: | # HTML 内容:会挂载到 nginx 的网页目录
|
||||
<!DOCTYPE html>
|
||||
<html><head><meta charset="utf-8"><title>M1</title></head>
|
||||
<body><h1>M1</h1><p>控制节点 + Ingress</p><p><strong>Backend: M1</strong></p></body></html>
|
||||
default.conf: | # nginx 配置:通过 subPath 单文件挂载到 conf.d/default.conf
|
||||
server { listen 80 default_server; server_name _; root /usr/share/nginx/html; index index.html; location / { add_header X-Backend "M1"; try_files $uri $uri/ /index.html; } }
|
||||
---
|
||||
apiVersion: apps/v1 # Deployment 使用的 API 版本
|
||||
kind: Deployment # 工作负载:Deployment
|
||||
metadata: # Deployment 标识信息
|
||||
name: nginx-m1 # Deployment 名称
|
||||
namespace: default # 部署命名空间
|
||||
labels: # 额外标签(用于检索/筛选)
|
||||
app: nginx-m1 # 应用标签
|
||||
matrix: "02-05-m1" # 矩阵编号标签(用于你后续调试/统计)
|
||||
spec: # Deployment 期望状态
|
||||
replicas: 1 # 副本数:本例为 1(便于对应路径验证)
|
||||
selector: # Deployment 用于选择 Pod 的条件
|
||||
matchLabels: # 标签匹配集合(用于选中模板 Pod)
|
||||
app: nginx-m1 # 必须与 template.metadata.labels 对上
|
||||
template: # Pod 模板
|
||||
metadata: # Pod 的元信息
|
||||
labels: # Pod 标签
|
||||
app: nginx-m1 # Pod 标签
|
||||
spec: # Pod 规范
|
||||
nodeSelector: # 节点选择:固定跑在 control-plane 上
|
||||
node-role.kubernetes.io/control-plane: "" # 选择带 control-plane 角色标签的节点
|
||||
tolerations: # 容忍污点:让 Pod 能调度到 control-plane
|
||||
- key: node-role.kubernetes.io/control-plane # 污点 key
|
||||
operator: Exists # 存在即匹配
|
||||
effect: NoSchedule # 匹配 NoSchedule 污点效果
|
||||
volumes: # Pod 内卷定义
|
||||
- name: html # 卷名:给 volumeMounts 引用
|
||||
configMap: # 卷来源:ConfigMap
|
||||
name: nginx-m1-html # 引用的 ConfigMap 名称
|
||||
containers: # 容器列表
|
||||
- name: nginx # 容器名
|
||||
image: nginx:alpine # nginx 镜像
|
||||
ports: # 容器端口列表
|
||||
- containerPort: 80 # nginx HTTP 端口
|
||||
volumeMounts: # 容器内挂载点列表
|
||||
- name: html # 对应 volumes[].name
|
||||
mountPath: /usr/share/nginx/html/index.html # 挂载到网页文件路径
|
||||
subPath: index.html # 从 ConfigMap 里选取单个 key
|
||||
readOnly: true # 只读挂载(配置文件更安全)
|
||||
- name: html # 第二处也使用同一个卷
|
||||
mountPath: /etc/nginx/conf.d/default.conf # nginx 配置文件路径
|
||||
subPath: default.conf # 从 ConfigMap 里选取对应 key
|
||||
readOnly: true # 只读挂载
|
||||
---
|
||||
apiVersion: v1 # Service 使用的 API 版本
|
||||
kind: Service # 网络抽象:把 Pod 暴露成稳定访问入口
|
||||
metadata: # Service 标识
|
||||
name: nginx-m1 # Service 名称
|
||||
namespace: default # Service 所在命名空间
|
||||
spec: # Service 期望状态
|
||||
selector: # Service 按标签选择后端 Pod
|
||||
app: nginx-m1 # 选择 nginx-m1 Pod
|
||||
ports: # Service 端口映射
|
||||
- port: 80 # Service 端口
|
||||
targetPort: 80 # 转发到 Pod 的端口
|
||||
---
|
||||
apiVersion: traefik.io/v1alpha1 # Traefik Middleware 使用的 API 版本
|
||||
kind: Middleware # 路由中间件:stripPrefix
|
||||
metadata: # Middleware 标识
|
||||
name: stripprefix-m1 # Middleware 名称
|
||||
namespace: default # 命名空间
|
||||
spec: # Middleware 配置
|
||||
stripPrefix: # 去掉前缀
|
||||
prefixes: # 要剔除的前缀列表
|
||||
- /demo-m1 # 本矩阵的路径前缀
|
||||
---
|
||||
apiVersion: networking.k8s.io/v1 # Ingress 使用的 API 版本
|
||||
kind: Ingress # 入口资源:把路径转发到 Service
|
||||
metadata: # Ingress 标识
|
||||
name: nginx-m1 # Ingress 名称
|
||||
namespace: default # 命名空间
|
||||
annotations: # Ingress 注解:Traefik 用来绑定中间件
|
||||
traefik.ingress.kubernetes.io/router.middlewares: default-stripprefix-m1@kubernetescrd # 绑定 stripprefix-m1
|
||||
spec: # Ingress 规则
|
||||
rules: # 规则列表
|
||||
- http: # HTTP 规则
|
||||
paths: # 路径匹配列表
|
||||
- path: /demo-m1 # 匹配路径
|
||||
pathType: Prefix # 前缀匹配类型
|
||||
backend: # 后端目标
|
||||
service: # 后端 Service
|
||||
name: nginx-m1 # Service 名
|
||||
port: # Service 端口
|
||||
number: 80 # 端口号
|
||||
|
||||
95
ansible/files/02-05/02-control-ingressroute.yaml
Normal file
95
ansible/files/02-05/02-control-ingressroute.yaml
Normal file
@@ -0,0 +1,95 @@
|
||||
# 03-02: Nginx + 控制节点 + IngressRoute(M2)
|
||||
# 路径 /demo-m2,指定一台控制节点(按实际 FQDN 修改 kubernetes.io/hostname)
|
||||
# ConfigMap:首页 + default.conf,X-Backend: M2 便于区分
|
||||
---
|
||||
apiVersion: v1 # ConfigMap 使用的 API 版本
|
||||
kind: ConfigMap # 配置资源类型:ConfigMap
|
||||
metadata: # ConfigMap 标识信息
|
||||
name: nginx-m2-html # ConfigMap 名称
|
||||
namespace: default # 命名空间
|
||||
data: # ConfigMap 数据区
|
||||
index.html: | # HTML 内容:会挂载到 nginx 的网页目录
|
||||
<!DOCTYPE html>
|
||||
<html><head><meta charset="utf-8"><title>M2</title></head>
|
||||
<body><h1>M2</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 "M2"; try_files $uri $uri/ /index.html; } }
|
||||
---
|
||||
apiVersion: apps/v1 # Deployment 使用的 API 版本
|
||||
kind: Deployment # 工作负载:Deployment
|
||||
metadata: # Deployment 标识信息
|
||||
name: nginx-m2 # Deployment 名称
|
||||
namespace: default # 部署命名空间
|
||||
labels: # 标签集合
|
||||
app: nginx-m2 # 应用标签
|
||||
matrix: "02-05-m2" # 矩阵编号标签
|
||||
spec: # Deployment 期望状态
|
||||
replicas: 1 # 副本数:单副本便于验证
|
||||
selector: # Deployment 选择 Pod
|
||||
matchLabels: # 标签匹配集合(用于选中模板 Pod)
|
||||
app: nginx-m2 # 必须与 template.metadata.labels 对上
|
||||
template: # Pod 模板
|
||||
metadata: # Pod 元信息
|
||||
labels: # Pod 标签
|
||||
app: nginx-m2 # Pod 标签
|
||||
spec: # Pod 规范
|
||||
nodeSelector: # 固定调度节点(按实际修改)
|
||||
kubernetes.io/hostname: ylc61 # 目标节点主机名
|
||||
volumes: # 卷定义
|
||||
- name: html # 卷名
|
||||
configMap: # 卷来源为 ConfigMap
|
||||
name: nginx-m2-html # 引用的 ConfigMap 名称
|
||||
containers: # 容器列表
|
||||
- name: nginx # 容器名
|
||||
image: nginx:alpine # nginx 镜像
|
||||
ports: # 容器端口声明
|
||||
- containerPort: 80 # nginx 监听端口
|
||||
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-m2 # Service 名称
|
||||
namespace: default # 命名空间
|
||||
spec: # Service 期望状态
|
||||
selector: # 通过标签选择后端 Pod
|
||||
app: nginx-m2 # 选择 app 标签为 nginx-m2 的 Pod
|
||||
ports: # Service 端口映射
|
||||
- port: 80 # Service 暴露端口
|
||||
targetPort: 80 # 转发到 Pod 容器端口
|
||||
---
|
||||
apiVersion: traefik.io/v1alpha1 # Traefik Middleware 使用的 API 版本
|
||||
kind: Middleware # 中间件类型:stripPrefix
|
||||
metadata: # Middleware 标识
|
||||
name: stripprefix-m2 # Middleware 名称
|
||||
namespace: default # 命名空间
|
||||
spec: # 中间件配置
|
||||
stripPrefix: # 去掉路径前缀
|
||||
prefixes: # 需要剔除的前缀列表
|
||||
- /demo-m2 # 本矩阵的路径前缀
|
||||
---
|
||||
apiVersion: traefik.io/v1alpha1 # IngressRoute 的 API 版本
|
||||
kind: IngressRoute # 路由资源类型
|
||||
metadata: # IngressRoute 标识
|
||||
name: nginx-m2 # 路由名称
|
||||
namespace: default # 命名空间
|
||||
spec: # 路由规则
|
||||
entryPoints: # Traefik 入口点列表
|
||||
- web # 使用 web entrypoint
|
||||
routes: # 路由列表
|
||||
- match: PathPrefix(`/demo-m2`) # 匹配 /demo-m2 前缀
|
||||
kind: Rule # 规则类型:Rule
|
||||
middlewares: # 绑定中间件(去前缀)
|
||||
- name: stripprefix-m2 # 使用 stripprefix-m2
|
||||
services: # 匹配后转发的服务
|
||||
- name: nginx-m2 # 后端 Service 名称
|
||||
port: 80 # 后端 Service 端口
|
||||
|
||||
97
ansible/files/02-05/03-worker-ingress.yaml
Normal file
97
ansible/files/02-05/03-worker-ingress.yaml
Normal file
@@ -0,0 +1,97 @@
|
||||
# 03-03: Nginx + 工作节点 + Ingress(M3)
|
||||
# 路径 /demo-m3,随机一台工作节点(nodeSelector: node-role.kubernetes.io/worker)
|
||||
# ConfigMap:首页 + default.conf,X-Backend: M3 便于区分
|
||||
---
|
||||
apiVersion: v1 # ConfigMap 使用的 API 版本
|
||||
kind: ConfigMap # 配置资源类型:ConfigMap
|
||||
metadata: # 对该 ConfigMap 的标识信息
|
||||
name: nginx-m3-html # ConfigMap 名称
|
||||
namespace: default # 命名空间
|
||||
data: # ConfigMap 数据键值区
|
||||
index.html: | # HTML 内容:会挂载到 nginx 网页目录(内部内容行不改动)
|
||||
<!DOCTYPE html>
|
||||
<html><head><meta charset="utf-8"><title>M3</title></head>
|
||||
<body><h1>M3</h1><p>工作节点 + Ingress</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 "M3"; try_files $uri $uri/ /index.html; } }
|
||||
---
|
||||
apiVersion: apps/v1 # Deployment 使用的 API 版本
|
||||
kind: Deployment # 工作负载:Deployment
|
||||
metadata: # Deployment 标识信息
|
||||
name: nginx-m3 # Deployment 名称
|
||||
namespace: default # 部署命名空间
|
||||
labels: # 额外标签(用于筛选/统计)
|
||||
app: nginx-m3 # 应用标签
|
||||
matrix: "02-05-m3" # 矩阵编号标签
|
||||
spec: # Deployment 期望状态
|
||||
replicas: 1 # 副本数:这里为 1
|
||||
selector: # Deployment 用于选择 Pod 的条件
|
||||
matchLabels: # 标签匹配集合(用于选中模板 Pod)
|
||||
app: nginx-m3 # 必须与 template.metadata.labels 对上
|
||||
template: # Pod 模板
|
||||
metadata: # Pod 元信息
|
||||
labels: # Pod 标签
|
||||
app: nginx-m3 # Pod 标签
|
||||
spec: # Pod 规范
|
||||
nodeSelector: # 固定跑到 worker 节点
|
||||
node-role.kubernetes.io/worker: "" # worker 节点 selector
|
||||
volumes: # 卷定义
|
||||
- name: html # 卷名(供 volumeMounts 引用)
|
||||
configMap: # 卷来源:ConfigMap
|
||||
name: nginx-m3-html # 引用的 ConfigMap 名称
|
||||
containers: # 容器列表
|
||||
- name: nginx # 容器名
|
||||
image: nginx:alpine # nginx 镜像
|
||||
ports: # 容器端口声明
|
||||
- containerPort: 80 # nginx HTTP 端口
|
||||
volumeMounts: # 容器内挂载点
|
||||
- name: html # 对应 volumes[].name
|
||||
mountPath: /usr/share/nginx/html/index.html # 挂到网页首页
|
||||
subPath: index.html # 从 ConfigMap 取该 key
|
||||
readOnly: true # 配置只读
|
||||
- name: html # 第二处仍引用同一个卷
|
||||
mountPath: /etc/nginx/conf.d/default.conf # 挂到 nginx 配置文件路径
|
||||
subPath: default.conf # 从 ConfigMap 取该 key
|
||||
readOnly: true # 配置只读
|
||||
---
|
||||
apiVersion: v1 # Service 使用的 API 版本
|
||||
kind: Service # 网络抽象:把 Pod 暴露成稳定访问入口
|
||||
metadata: # Service 标识
|
||||
name: nginx-m3 # Service 名称
|
||||
namespace: default # 命名空间
|
||||
spec: # Service 期望状态
|
||||
selector: # Service 通过标签选中后端 Pod
|
||||
app: nginx-m3 # 选择 app 标签
|
||||
ports: # Service 端口映射列表
|
||||
- port: 80 # Service 暴露端口
|
||||
targetPort: 80 # 转发到 Pod 的容器端口
|
||||
---
|
||||
apiVersion: traefik.io/v1alpha1 # Traefik Middleware API 版本
|
||||
kind: Middleware # 中间件类型:stripPrefix
|
||||
metadata: # Middleware 标识
|
||||
name: stripprefix-m3 # 名称
|
||||
namespace: default # 命名空间
|
||||
spec: # 中间件配置
|
||||
stripPrefix: # 去掉指定路径前缀
|
||||
prefixes: # 前缀列表
|
||||
- /demo-m3 # 本矩阵路径前缀
|
||||
---
|
||||
apiVersion: networking.k8s.io/v1 # Ingress 使用的 API 版本
|
||||
kind: Ingress # 入口资源:把路径转发到 Service
|
||||
metadata: # Ingress 标识
|
||||
name: nginx-m3 # Ingress 名称
|
||||
namespace: default # 命名空间
|
||||
annotations: # Traefik 注解:绑定中间件
|
||||
traefik.ingress.kubernetes.io/router.middlewares: default-stripprefix-m3@kubernetescrd # 绑定 stripprefix-m3 中间件
|
||||
spec: # Ingress 规则
|
||||
rules: # 规则列表
|
||||
- http: # HTTP 规则
|
||||
paths: # 路径匹配列表
|
||||
- path: /demo-m3 # 匹配路径
|
||||
pathType: Prefix # 前缀匹配类型
|
||||
backend: # 后端目标
|
||||
service: # 后端是 Service
|
||||
name: nginx-m3 # Service 名称
|
||||
port: # 后端端口
|
||||
number: 80 # 端口号
|
||||
|
||||
95
ansible/files/02-05/04-worker-ingressroute.yaml
Normal file
95
ansible/files/02-05/04-worker-ingressroute.yaml
Normal file
@@ -0,0 +1,95 @@
|
||||
# 03-04: Nginx + 工作节点 + IngressRoute(M4)
|
||||
# 路径 /demo-m4,指定一台工作节点(按实际 FQDN 修改 kubernetes.io/hostname)
|
||||
# ConfigMap:首页 + default.conf,X-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 # web(HTTP)
|
||||
routes: # 路由列表
|
||||
- match: PathPrefix(`/demo-m4`) # 匹配 /demo-m4 前缀
|
||||
kind: Rule # 规则类型
|
||||
middlewares: # 绑定中间件
|
||||
- name: stripprefix-m4 # 需要去前缀
|
||||
services: # 后端服务列表
|
||||
- name: nginx-m4 # Service 名称
|
||||
port: 80 # Service 端口
|
||||
|
||||
Reference in New Issue
Block a user