日常更新

This commit is contained in:
2026-03-29 09:08:01 +08:00
parent 31709425e2
commit befdefd222
224 changed files with 7240 additions and 3297 deletions

View File

@@ -0,0 +1,97 @@
# 03-03: Nginx + 工作节点 + IngressM3
# 路径 /demo-m3随机一台工作节点nodeSelector: node-role.kubernetes.io/worker
# ConfigMap首页 + default.confX-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 # 端口号