# 03-02 TLS: M1 控制节点 + Ingress,路径 /(根路径),域名 test01.jackadam.top # ConfigMap:首页 + default.conf(单文件 subPath 挂载,与 M2~M4 一致) --- apiVersion: v1 # ConfigMap 使用的 API 版本 kind: ConfigMap # 配置资源类型:ConfigMap metadata: # ConfigMap 标识信息 name: nginx-m1-html # ConfigMap 名称 namespace: default # 命名空间 data: # ConfigMap 数据区 index.html: | # HTML 内容:挂载到 nginx 网页目录(内部内容行不改动) M1

M1

控制节点 + Ingress

Backend: M1

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: "03-02-m1" # 矩阵编号标签 spec: # Deployment 期望状态 replicas: 1 # 副本数:单副本 selector: # 选择器 matchLabels: # 标签匹配集合(用于选中模板 Pod) app: nginx-m1 # 与 template.labels 对齐 template: # Pod 模板 metadata: # Pod 元信息 labels: # Pod 标签 app: nginx-m1 # Pod 标签 spec: # Pod 规范 nodeSelector: # 固定到 control-plane 节点 node-role.kubernetes.io/control-plane: "" # 控制节点 selector tolerations: # 容忍 NoSchedule 污点 - key: node-role.kubernetes.io/control-plane # 污点 key operator: Exists # 匹配存在 effect: NoSchedule # 影响效果 volumes: # 卷定义 - name: html # 卷名 configMap: # 来自 ConfigMap name: nginx-m1-html # ConfigMap 名称 containers: # 容器列表 - name: nginx # 容器名 image: nginx:alpine # 镜像 ports: # 容器端口 - containerPort: 80 # nginx HTTP 端口 volumeMounts: # 挂载点 - name: html # 引用卷 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 # 命名空间 spec: # Service 期望状态 selector: # Service 选择器 app: nginx-m1 # 选中后端 Pod ports: # 端口映射 - port: 80 # Service 端口 targetPort: 80 # 转发目标端口 --- apiVersion: networking.k8s.io/v1 # Ingress 使用的 API 版本 kind: Ingress # 入口资源 metadata: # Ingress 标识 name: nginx-m1 # 名称 namespace: default # 命名空间 annotations: # Traefik 注解 traefik.ingress.kubernetes.io/router.entrypoints: websecure # 使用 HTTPS entrypoint traefik.ingress.kubernetes.io/router.tls.certresolver: cloudflare # ACME certresolver spec: # Ingress 规则 tls: # TLS 配置 - hosts: # TLS hosts - test01.jackadam.top # 域名 rules: # HTTP 路由规则 - host: test01.jackadam.top # 域名匹配 http: # HTTP 路由 paths: # 路径列表 - path: / # 匹配根路径 pathType: Prefix # 前缀匹配 backend: # 后端目标 service: # 后端是 Service name: nginx-m1 # Service 名称 port: # 后端端口 number: 80 # 端口号 --- # 03-02 HTTP-only:M1 路由(仅 web,无 TLS),与 nginx-m1 共用 Service apiVersion: networking.k8s.io/v1 # Ingress API 版本 kind: Ingress # Ingress 资源 metadata: # Ingress 标识 name: nginx-m1-http # HTTP-only Ingress 名称 namespace: default # 命名空间 annotations: # Traefik 注解 traefik.ingress.kubernetes.io/router.entrypoints: web # 使用 HTTP entrypoint spec: # Ingress 规则 rules: # 规则列表 - host: test01.jackadam.top # 域名 http: # HTTP 路由 paths: # 路径列表 - path: / # 根路径 pathType: Prefix # 前缀匹配 backend: # 后端目标 service: # 后端是 Service name: nginx-m1 # 共用 Service port: # 后端端口 number: 80 # 端口号