chore: 清理调试脚本并收敛到 Ansible 流程

移除已废弃的调试/验证脚本与空目录,统一文档与脚本说明到 ansible-playbook 的部署方式,避免失效引用和误用路径。

Made-with: Cursor
This commit is contained in:
2026-03-23 19:18:55 +08:00
parent 8a54cac61f
commit be97836e0d
92 changed files with 3463 additions and 4855 deletions

View File

@@ -1,4 +1,4 @@
# 01-08 HAProxy 配置
# 01-07 HAProxy 配置
## 核心目标
@@ -7,7 +7,7 @@
| 层次 | 含义 | 如何验证 |
|------|------|----------|
| **① 语法正确** | `haproxy -c -f <cfg>` 无致命错误 | 见下文「仅校验 cfg」或主验证脚本第 2 步 |
| **② 运行与后端** | 在 OpenWrt 上实际监听 18080/18443 时,经第三方主机 curl 可达 K3s/Traefik 后端 | `./scripts/01-08-verify-haproxy.sh`(完整流程,含 curl |
| **② 运行与后端** | 在 OpenWrt 上实际监听 18080/18443 时,经第三方主机 curl 可达 K3s/Traefik 后端 | `./scripts/01-07-verify-haproxy.sh`(完整流程,含 curl |
仓库内 **frontend 已统一为 `18080` / `18443`**(与 LuCI 的 80/443 分离backend 仍指向各节点 **80/443**Traefik 入口)。按环境修改 `192.168.2.61``192.168.2.64`
@@ -16,7 +16,7 @@
仅需确认 **① 语法**,在仓库根目录执行:
```bash
./scripts/01-08-verify-haproxy.sh --cfg-only
./scripts/01-07-verify-haproxy.sh --cfg-only
```
会将本目录全部 `*.cfg` 拷到 OpenWrt 的 `/tmp/haproxy-verify/`,对每台文件执行 `haproxy -c`(与 OpenWrt 上安装的 HAProxy 版本一致)。
@@ -25,7 +25,7 @@
## 文件一览
| 文件 | 说明(对应 `docs/01-08-openwrt-haproxy.md` |
| 文件 | 说明(对应 `docs/01-07-openwrt-haproxy.md` |
|------|-----------------------------------------------|
| `haproxy-no-check.cfg` | §2 最简§3.1 在其 `server` 行加 `check` |
| `haproxy-http.cfg` | §3.2 HTTP 健康检查(明文 80 后端) |
@@ -35,4 +35,4 @@
## 与 Ansible / OpenWrt
可与 Ansible 共用(复制到 OpenWrt 或通过 playbook 下发)。一键把 **uhttpd 80/443 + HAProxy 18080/18443** 落到路由器见 `scripts/01-08-deploy-openwrt-haproxy.sh`
可与 Ansible 共用(复制到 OpenWrt 或通过 playbook 下发)。一键把 **uhttpd 80/443 + HAProxy 18080/18443** 落到路由器见 `scripts/01-07-deploy-openwrt-haproxy.sh`

View File

@@ -1,6 +1,6 @@
# 01-08 HAProxy - 3.2 HTTP 健康检查80 明文)
# 01-07 HAProxy - 3.2 HTTP 健康检查80 明文)
# backend k3s_http 增加 option httpchk GET /
# 文档docs/01-08-openwrt-haproxy.md 第 3.2 节
# 文档docs/01-07-openwrt-haproxy.md 第 3.2 节
global
log /dev/log local0
maxconn 4096

View File

@@ -1,8 +1,8 @@
# 01-08 HAProxy - 3.4 HTTPS 健康检查443 应用层HAProxy 终结 TLS由 HAProxy 提供证书)
# 01-07 HAProxy - 3.4 HTTPS 健康检查443 应用层HAProxy 终结 TLS由 HAProxy 提供证书)
# frontend 需 bind *:443 sslbackend mode http 连 K3s:443 做 HTTP over TLS 检查
# 将 your-ingress.example.com 改为实际 Host将 /etc/ssl/haproxy.pem 改为实际证书路径
# 自签/内网 CA 用 verify none生产建议 ca-file
# 文档docs/01-08-openwrt-haproxy.md 第 3.4 节
# 文档docs/01-07-openwrt-haproxy.md 第 3.4 节
global
log /dev/log local0
maxconn 4096

View File

@@ -1,5 +1,5 @@
# 01-08 OpenWrt HAProxy 负载均衡 - 原生最简(无健康检查)
# 文档docs/01-08-openwrt-haproxy.md 第 2 节
# 01-07 OpenWrt HAProxy 负载均衡 - 原生最简(无健康检查)
# 文档docs/01-07-openwrt-haproxy.md 第 2 节
# 将 192.168.2.6164 按实际 K3s 节点 IP 修改
# 如需健康检查,见第 3 节对应 cfg
global

View File

@@ -1,6 +1,6 @@
# 01-08 HAProxy - 健康检查升级HTTP+TLS+ PROXY Protocol
# 01-07 HAProxy - 健康检查升级HTTP+TLS+ PROXY Protocol
# 组合k3s_http 用 option httpchkk3s_https 用 ssl-hello-chk均带 send-proxy-v2
# 文档docs/01-08-openwrt-haproxy.md 第 5 节「健康检查与 PROXY 组合」
# 文档docs/01-07-openwrt-haproxy.md 第 5 节「健康检查与 PROXY 组合」
global
log /dev/log local0
maxconn 4096

View File

@@ -1,6 +1,6 @@
# 01-08 HAProxy - 3.3 TLS 健康检查443 握手mode tcp
# 01-07 HAProxy - 3.3 TLS 健康检查443 握手mode tcp
# backend k3s_https 增加 option ssl-hello-chk
# 文档docs/01-08-openwrt-haproxy.md 第 3.3 节
# 文档docs/01-07-openwrt-haproxy.md 第 3.3 节
global
log /dev/log local0
maxconn 4096

View File

@@ -1,37 +1,37 @@
# docs/03-04-k3s-cloudflare-tunnel-配置接入.md — 替换 TUNNEL_TOKEN 后应用
apiVersion: v1
kind: Secret
metadata:
name: cloudflared-credentials
namespace: kube-system
type: Opaque
stringData:
TUNNEL_TOKEN: "<YOUR_TUNNEL_TOKEN>"
apiVersion: v1 # Secret 使用的 Kubernetes API 版本
kind: Secret # 资源类型Secret用于保存 Cloudflare Tunnel token
metadata: # 元信息(名称/命名空间等)
name: cloudflared-credentials # Secret 名称Deployment 中会引用)
namespace: kube-system # Secret 所在命名空间
type: Opaque # Secret 类型(普通自定义键值)
stringData: # 以字符串方式提供 Secret 数据(便于直接写明文)
TUNNEL_TOKEN: "<YOUR_TUNNEL_TOKEN>" # Cloudflare Tunnel Token用你真实的 token 替换)
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: cloudflared
namespace: kube-system
spec:
replicas: 1
selector:
matchLabels:
app: cloudflared
template:
metadata:
labels:
app: cloudflared
spec:
containers:
- name: cloudflared
image: cloudflare/cloudflared:latest
args:
- tunnel
- run
env:
- name: TUNNEL_TOKEN
valueFrom:
secretKeyRef:
name: cloudflared-credentials
key: TUNNEL_TOKEN
apiVersion: apps/v1 # Deployment 使用的 API 版本
kind: Deployment # 工作负载Deployment管理 Pod 副本)
metadata: # Deployment 元信息
name: cloudflared # Deployment 名称
namespace: kube-system # 部署到的命名空间
spec: # Deployment 期望状态
replicas: 1 # 副本数Tunnel 通常只跑一个副本即可)
selector: # Deployment 选择器:匹配 template 的 Pod
matchLabels: # 必须与 template.metadata.labels 对齐
app: cloudflared # 应用标签
template: # Pod 模板
metadata: # Pod 元信息
labels: # Pod 标签
app: cloudflared # 与 selector.matchLabels 相同
spec: # Pod 规范
containers: # 容器列表
- name: cloudflared # 容器名
image: cloudflare/cloudflared:latest # cloudflared 镜像
args: # 容器启动参数
- tunnel # 命令子参数tunnel
- run # 命令子参数run
env: # 环境变量
- name: TUNNEL_TOKEN # 容器内使用的环境变量名
valueFrom: # 从某个来源取值
secretKeyRef: # 从 Secret 的 key 取值
name: cloudflared-credentials # Secret 名称
key: TUNNEL_TOKEN # Secret 中的 key

View File

@@ -1,20 +1,20 @@
# docs/05-04-k3s-配置gitlab-cicd.md — 最小 .gitlab-ci.yml 示例
stages:
- lint
- deploy
stages: # CI 阶段定义(按顺序执行)
- lint # 代码/清单检查阶段
- deploy # 部署阶段
variables:
KUBECONFIG: "/builds/${CI_PROJECT_PATH}/kubeconfig"
variables: # 全局变量
KUBECONFIG: "/builds/${CI_PROJECT_PATH}/kubeconfig" # Runner 内 kubeconfig 输出路径
lint:
stage: lint
script:
- yamllint manifests || true
lint: # 任务名lint
stage: lint # 归属 lint 阶段
script: # 执行脚本
- yamllint manifests || true # 允许 lint 失败不中断(示例用途)
deploy:
stage: deploy
script:
- echo "$KUBE_CONFIG_CONTENT" > "$KUBECONFIG"
- kubectl --kubeconfig="$KUBECONFIG" apply -f manifests/
only:
- main
deploy: # 任务名deploy
stage: deploy # 归属 deploy 阶段
script: # 执行脚本
- echo "$KUBE_CONFIG_CONTENT" > "$KUBECONFIG" # 将 CI 变量写入 kubeconfig 文件
- kubectl --kubeconfig="$KUBECONFIG" apply -f manifests/ # 应用 manifests
only: # 触发条件(旧语法)
- main # 仅 main 分支触发

View File

@@ -1,14 +1,14 @@
# docs/05-04-k3s-配置gitlab-cicd.md — 多架构 Runner tags 示例
deploy_x86:
stage: deploy
tags: [x86]
script:
- echo "$KUBE_CONFIG_CONTENT" > "$KUBECONFIG"
- kubectl --kubeconfig="$KUBECONFIG" apply -f manifests/x86/
deploy_x86: # 任务名x86 架构部署
stage: deploy # 所属阶段
tags: [x86] # 仅匹配带 x86 tag 的 Runner
script: # 执行脚本
- echo "$KUBE_CONFIG_CONTENT" > "$KUBECONFIG" # 写入 kubeconfig
- kubectl --kubeconfig="$KUBECONFIG" apply -f manifests/x86/ # 部署 x86 清单
deploy_arm64:
stage: deploy
tags: [arm64]
script:
- echo "$KUBE_CONFIG_CONTENT" > "$KUBECONFIG"
- kubectl --kubeconfig="$KUBECONFIG" apply -f manifests/arm64/
deploy_arm64: # 任务名arm64 架构部署
stage: deploy # 所属阶段
tags: [arm64] # 仅匹配带 arm64 tag 的 Runner
script: # 执行脚本
- echo "$KUBE_CONFIG_CONTENT" > "$KUBECONFIG" # 写入 kubeconfig
- kubectl --kubeconfig="$KUBECONFIG" apply -f manifests/arm64/ # 部署 arm64 清单

View File

@@ -1,15 +1,15 @@
# docs/05-03-k3s-安装gitlab-含runner.md — Runner tag 与 job 对应示例
build_x86:
tags: [x86]
script:
- echo "build for x86"
build_x86: # 任务名x86 构建
tags: [x86] # 仅匹配 x86 Runner
script: # 执行脚本
- echo "build for x86" # 示例输出
build_arm64:
tags: [arm64]
script:
- echo "build for arm64"
build_arm64: # 任务名arm64 构建
tags: [arm64] # 仅匹配 arm64 Runner
script: # 执行脚本
- echo "build for arm64" # 示例输出
build_armv7:
tags: [armv7]
script:
- echo "build for armv7"
build_armv7: # 任务名armv7 构建
tags: [armv7] # 仅匹配 armv7 Runner
script: # 执行脚本
- echo "build for armv7" # 示例输出

View File

@@ -1,53 +1,53 @@
# docs/05-01-k3s-部署homer首页面板.md — 按需修改 host
apiVersion: apps/v1
kind: Deployment
metadata:
name: homer
namespace: homer
spec:
replicas: 1
selector:
matchLabels:
app: homer
template:
metadata:
labels:
app: homer
spec:
containers:
- name: homer
image: b4bz/homer:latest
ports:
- containerPort: 8080
apiVersion: apps/v1 # Deployment 使用的 API 版本
kind: Deployment # 工作负载Deployment管理 Pod 副本)
metadata: # 对该资源的标识信息
name: homer # Deployment 名称
namespace: homer # 所属命名空间Pod 也会在该 NS 内)
spec: # Deployment 期望状态
replicas: 1 # Pod 副本数:这里是 1单副本更容易配合本地存储等
selector: # Deployment 用于匹配管理 Pod 的条件
matchLabels: # 标签匹配:必须与 template.metadata.labels 一致
app: homer # 选择带有 app=homer 标签的 Pod
template: # Pod 模板Deployment 会根据该模板创建/更新 Pod
metadata: # Pod 的元信息
labels: # Pod 标签:用于 selector 匹配 Service/Deployment 等
app: homer # Pod 上的标签 app=homer
spec: # Pod 规范
containers: # 容器列表(本例只有一个容器)
- name: homer # 容器名称(日志/调试中会用到)
image: b4bz/homer:latest # homer 镜像
ports: # 容器端口声明(供探测/生成文档等使用)
- containerPort: 8080 # 容器监听端口homer 默认 8080
---
apiVersion: v1
kind: Service
metadata:
name: homer
namespace: homer
spec:
selector:
app: homer
ports:
- port: 80
targetPort: 8080
apiVersion: v1 # Service 使用的 API 版本
kind: Service # 网络抽象:把一组 Pod 暴露为稳定的访问入口
metadata: # Service 标识
name: homer # Service 名称Ingress/其他对象会引用)
namespace: homer # Service 所在命名空间
spec: # Service 期望状态
selector: # Service 通过标签选择要转发到的 Pod
app: homer # 选择 app=homer 的 Pod
ports: # Service 暴露端口列表
- port: 80 # Service 端口Ingress/集群访问时用它
targetPort: 8080 # 转发目标端口Pod 容器监听的端口
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: homer
namespace: homer
annotations:
traefik.ingress.kubernetes.io/router.entrypoints: web
spec:
rules:
- host: home.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: homer
port:
number: 80
apiVersion: networking.k8s.io/v1 # Ingress 使用的 API 版本
kind: Ingress # 入口资源:对外暴露 HTTP/HTTPS 路由
metadata: # Ingress 标识
name: homer # Ingress 名称
namespace: homer # Ingress 所在命名空间
annotations: # 注解:用于 Traefik 等 Ingress Controller 的额外配置
traefik.ingress.kubernetes.io/router.entrypoints: web # Traefik 路由使用的 entrypointHTTP
spec: # Ingress 规则
rules: # 主机/路径规则列表
- host: home.example.com # 要匹配的域名(按需修改)
http: # HTTP 路由规则
paths: # 路径匹配列表
- path: / # 匹配根路径及其子路径
pathType: Prefix # Prefix 表示前缀匹配
backend: # 匹配到后端目标
service: # 使用 Service 作为后端
name: homer # 后端 Service 名称
port: # 后端端口配置
number: 80 # 后端 Service 端口

View File

@@ -1,38 +1,39 @@
# docs/03-05-k3s-local-path-pvc.md
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: local-pvc-demo
namespace: default
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
apiVersion: v1 # PVCKubernetes 核心 API
kind: PersistentVolumeClaim # 持久卷声明(你“申请要用的存储”)
metadata: # PVC 的元信息(名称/命名空间/其它元数据)
name: local-pvc-demo # PVC 名称Deployment 里会引用)
namespace: default # PVC 所在命名空间
spec: # PVC 的期望状态(访问模式/存储类/容量请求)
accessModes: # 访问模式RWO 表示同一时刻只能被一个节点上的一个 Pod 以读写方式挂载
- ReadWriteOnce # 读写模式:单节点可读写
storageClassName: local-path # 指定存储类:使用 K3s 的 local-path-provisioner动态创建本地 PV
resources: # 资源请求(本例只关心 storage 容量)
requests: # 容量配额请求(与 requests.storage 对应)
storage: 1Gi # 申请容量大小K8s quantity常见后缀 Ki/Mi/Gi/Ti/…示例512Mi、1024Mi、1Gi、1G也可写字节值
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-local-pvc-demo
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: nginx-local-pvc-demo
template:
metadata:
labels:
app: nginx-local-pvc-demo
spec:
containers:
- name: nginx
image: nginx:alpine
volumeMounts:
- name: data
mountPath: /usr/share/nginx/html
volumes:
- name: data
persistentVolumeClaim:
claimName: local-pvc-demo
apiVersion: apps/v1 # Deploymentapps API
kind: Deployment # 部署器:管理 Pod 副本、滚动更新等
metadata: # Deployment 的元信息
name: nginx-local-pvc-demo # Deployment 名称
namespace: default # 部署到的命名空间Deployment 里引用 PVC 时也必须同 namespace
spec: # Deployment 的期望状态副本数、选择器、Pod 模板等)
replicas: 1 # Pod 副本数(用于验证持久化,保持单副本更直观)
selector: # Deployment 选择器:用于匹配/管理模板 Pod
matchLabels: # 标签匹配集合(必须与 template.metadata.labels 对上)
app: nginx-local-pvc-demo # Deployment 用该 label 选择/管理自己的 Pod
template: # Pod 模板Deployment 用它创建/更新 Pod
metadata: # Pod 元信息
labels: # Pod 标签:必须与 selector.matchLabels 对齐
app: nginx-local-pvc-demo # Pod 模板 label必须与 selector.matchLabels 对上
spec: # Pod 规范
containers: # 容器列表
- name: nginx # 容器名
image: nginx:alpine # nginx 镜像
volumeMounts: # 容器内挂载点(把卷挂到 mountPath
- name: data # 与下方 volumes[].name 对应:挂载哪个卷
mountPath: /usr/share/nginx/html # 挂载点:写入此目录会落到 PVC/PV 上
volumes: # Pod 内定义的卷列表
- name: data # Pod 内的卷名(给 volumeMounts 用)
persistentVolumeClaim: # 使用 PVC 作为卷来源
claimName: local-pvc-demo # 绑定到哪个 PVC必须与上面 PVC metadata.name 且同 namespace

View File

@@ -1,27 +1,27 @@
# docs/03-06-k3s-使用nfs存储.md — 按环境修改 server/path
apiVersion: v1
kind: PersistentVolume
metadata:
name: nfs-pv-demo
spec:
capacity:
storage: 20Gi
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Retain
nfs:
server: 192.168.2.22
path: /data/nfs
apiVersion: v1 # PV/PVC 使用的核心 API 版本
kind: PersistentVolume # 资源类型:持久卷(集群级)
metadata: # PV 元信息
name: nfs-pv-demo # PV 名称
spec: # PV 规格
capacity: # 容量声明
storage: 20Gi # PV 总容量
accessModes: # 访问模式列表
- ReadWriteMany # RWX多节点可读写
persistentVolumeReclaimPolicy: Retain # 回收策略:删除 PVC 后保留底层数据
nfs: # 存储后端NFS
server: 192.168.2.22 # NFS 服务器地址
path: /data/nfs # NFS 导出目录
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: nfs-pvc-demo
namespace: default
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 5Gi
volumeName: nfs-pv-demo
apiVersion: v1 # PVC 使用的核心 API 版本
kind: PersistentVolumeClaim # 资源类型:持久卷声明
metadata: # PVC 元信息
name: nfs-pvc-demo # PVC 名称
namespace: default # PVC 所在命名空间
spec: # PVC 规格
accessModes: # 访问模式要求
- ReadWriteMany # 申请 RWX 访问模式
resources: # 资源请求
requests: # 配额请求
storage: 5Gi # 申请容量
volumeName: nfs-pv-demo # 显式绑定到指定 PV

View File

@@ -1,115 +1,115 @@
# 03-02 TLS: M1 控制节点 + Ingress路径 /(根路径),域名 test01.jackadam.top
# ConfigMap首页 + default.conf单文件 subPath 挂载,与 M2M4 一致)
---
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-m1-html
namespace: default
data:
index.html: |
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: |
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
kind: Deployment
metadata:
name: nginx-m1
namespace: default
labels:
app: nginx-m1
matrix: "03-02-m1"
spec:
replicas: 1
selector:
matchLabels:
app: nginx-m1
template:
metadata:
labels:
app: nginx-m1
spec:
nodeSelector:
node-role.kubernetes.io/control-plane: ""
tolerations:
- key: node-role.kubernetes.io/control-plane
operator: Exists
effect: NoSchedule
volumes:
- name: html
configMap:
name: nginx-m1-html
containers:
- name: nginx
image: nginx:alpine
ports:
- containerPort: 80
volumeMounts:
- name: html
mountPath: /usr/share/nginx/html/index.html
subPath: index.html
readOnly: true
- name: html
mountPath: /etc/nginx/conf.d/default.conf
subPath: default.conf
readOnly: true
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
kind: Service
metadata:
name: nginx-m1
namespace: default
spec:
selector:
app: nginx-m1
ports:
- port: 80
targetPort: 80
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
kind: Ingress
metadata:
name: nginx-m1
namespace: default
annotations:
traefik.ingress.kubernetes.io/router.entrypoints: websecure
traefik.ingress.kubernetes.io/router.tls.certresolver: cloudflare
spec:
tls:
- hosts:
- test01.jackadam.top
rules:
- host: test01.jackadam.top
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: nginx-m1
port:
number: 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-onlyM1 路由(仅 web无 TLS与 nginx-m1 共用 Service
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: nginx-m1-http
namespace: default
annotations:
traefik.ingress.kubernetes.io/router.entrypoints: web
spec:
rules:
- host: test01.jackadam.top
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: nginx-m1
port:
number: 80
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 # 端口号

View File

@@ -1,98 +1,98 @@
# 03-02 TLS: M2 控制节点 + IngressRoute路径 /(根路径),域名 test02.jackadam.top
---
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-m2-html
namespace: default
data:
index.html: |
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: |
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
kind: Deployment
metadata:
name: nginx-m2
namespace: default
labels:
app: nginx-m2
matrix: "03-02-m2"
spec:
replicas: 1
selector:
matchLabels:
app: nginx-m2
template:
metadata:
labels:
app: nginx-m2
spec:
nodeSelector:
kubernetes.io/hostname: ylc61
volumes:
- name: html
configMap:
name: nginx-m2-html
containers:
- name: nginx
image: nginx:alpine
ports:
- containerPort: 80
volumeMounts:
- name: html
mountPath: /usr/share/nginx/html/index.html
subPath: index.html
readOnly: true
- name: html
mountPath: /etc/nginx/conf.d/default.conf
subPath: default.conf
readOnly: true
apiVersion: apps/v1 # Deployment 使用的 API 版本
kind: Deployment # 工作负载Deployment
metadata: # Deployment 标识信息
name: nginx-m2 # Deployment 名称
namespace: default # 部署命名空间
labels: # 标签
app: nginx-m2 # 应用标签
matrix: "03-02-m2" # 矩阵编号标签
spec: # Deployment 期望状态
replicas: 1 # 副本数
selector: # 选择器
matchLabels: # 标签匹配集合(用于选中模板 Pod
app: nginx-m2 # 必须与 template.labels 对齐
template: # Pod 模板
metadata: # Pod 元信息
labels: # Pod 标签
app: nginx-m2 # Pod 标签
spec: # Pod 规范
nodeSelector: # 固定到指定主机
kubernetes.io/hostname: ylc61 # 控制节点主机名
volumes: # 卷定义
- name: html # 卷名
configMap: # 卷来源
name: nginx-m2-html # ConfigMap 名称
containers: # 容器列表
- name: nginx # 容器名
image: nginx:alpine # nginx 镜像
ports: # 容器端口
- containerPort: 80 # 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
kind: Service
metadata:
name: nginx-m2
namespace: default
spec:
selector:
app: nginx-m2
ports:
- port: 80
targetPort: 80
apiVersion: v1 # Service 使用的 API 版本
kind: Service # 网络抽象:把 Pod 暴露为稳定入口
metadata: # Service 标识
name: nginx-m2 # Service 名称
namespace: default # 命名空间
spec: # Service 期望状态
selector: # Service 选择器
app: nginx-m2 # 选中后端 Pod
ports: # Service 端口
- port: 80 # Service 端口
targetPort: 80 # 转发端口
---
apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
name: nginx-m2
namespace: default
spec:
entryPoints:
- websecure
routes:
- match: Host(`test02.jackadam.top`)
kind: Rule
services:
- name: nginx-m2
port: 80
tls:
certResolver: cloudflare
apiVersion: traefik.io/v1alpha1 # IngressRoute API 版本
kind: IngressRoute # Traefik 路由 CRD
metadata: # IngressRoute 标识
name: nginx-m2 # 资源名称
namespace: default # 命名空间
spec: # 规则
entryPoints: # 入口点
- websecure # 使用 HTTPS entrypoint
routes: # 路由列表
- match: Host(`test02.jackadam.top`) # 域名匹配
kind: Rule # 规则类型
services: # 后端服务
- name: nginx-m2 # 后端 Service
port: 80 # 后端端口
tls: # TLS 配置
certResolver: cloudflare # 使用 cloudflare certResolver
---
# 03-02 HTTP-onlyM2 路由(仅 web无 TLS与 nginx-m2 共用 Service
apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
name: nginx-m2-http
namespace: default
spec:
entryPoints:
- web
routes:
- match: Host(`test02.jackadam.top`)
kind: Rule
services:
- name: nginx-m2
port: 80
apiVersion: traefik.io/v1alpha1 # IngressRoute API 版本
kind: IngressRoute # Traefik 路由资源
metadata: # 标识
name: nginx-m2-http # 名称
namespace: default # 命名空间
spec: # 规则
entryPoints: # 入口点列表
- web # 使用 HTTP entrypoint
routes: # 路由列表
- match: Host(`test02.jackadam.top`) # 域名匹配
kind: Rule # 规则类型
services: # 后端服务
- name: nginx-m2 # 后端 Service
port: 80 # 端口

View File

@@ -1,110 +1,110 @@
# 03-02 TLS: M3 工作节点 + Ingress路径 /(根路径),域名 test03.jackadam.top
---
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-m3-html
namespace: default
data:
index.html: |
apiVersion: v1 # ConfigMap 使用的 API 版本
kind: ConfigMap # 配置资源类型ConfigMap
metadata: # 资源标识
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: |
default.conf: | # nginx 配置:挂载到 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
kind: Deployment
metadata:
name: nginx-m3
namespace: default
labels:
app: nginx-m3
matrix: "03-02-m3"
spec:
replicas: 1
selector:
matchLabels:
app: nginx-m3
template:
metadata:
labels:
app: nginx-m3
spec:
nodeSelector:
node-role.kubernetes.io/worker: ""
volumes:
- name: html
configMap:
name: nginx-m3-html
containers:
- name: nginx
image: nginx:alpine
ports:
- containerPort: 80
volumeMounts:
- name: html
mountPath: /usr/share/nginx/html/index.html
subPath: index.html
readOnly: true
- name: html
mountPath: /etc/nginx/conf.d/default.conf
subPath: default.conf
readOnly: true
apiVersion: apps/v1 # Deployment 使用的 API 版本
kind: Deployment # 工作负载Deployment
metadata: # Deployment 标识
name: nginx-m3 # Deployment 名称
namespace: default # 部署命名空间
labels: # 标签(用于筛选/统计)
app: nginx-m3 # 应用标签
matrix: "03-02-m3" # 矩阵编号标签
spec: # Deployment 期望状态
replicas: 1 # 副本数
selector: # Deployment 选择器:匹配 Pod
matchLabels: # 标签匹配集合
app: nginx-m3 # 选中 app 标签为 nginx-m3 的 Pod
template: # Pod 模板
metadata: # Pod 元信息
labels: # Pod 标签
app: nginx-m3 # 与 selector.matchLabels 对齐
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 # 引用同一个卷
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
kind: Service
metadata:
name: nginx-m3
namespace: default
spec:
selector:
app: nginx-m3
ports:
- port: 80
targetPort: 80
apiVersion: v1 # Service 使用的 API 版本
kind: Service # Service 资源
metadata: # Service 标识
name: nginx-m3 # Service 名称
namespace: default # 命名空间
spec: # Service 期望状态
selector: # 通过标签选中后端 Pod
app: nginx-m3 # 选中 app 标签为 nginx-m3 的 Pod
ports: # 端口映射
- port: 80 # Service 暴露端口
targetPort: 80 # 转发到容器端口
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: nginx-m3
namespace: default
annotations:
traefik.ingress.kubernetes.io/router.entrypoints: websecure
traefik.ingress.kubernetes.io/router.tls.certresolver: cloudflare
spec:
tls:
- hosts:
- test03.jackadam.top
rules:
- host: test03.jackadam.top
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: nginx-m3
port:
number: 80
apiVersion: networking.k8s.io/v1 # Ingress 使用的 API 版本
kind: Ingress # Ingress 资源
metadata: # Ingress 标识
name: nginx-m3 # Ingress 名称
namespace: default # 命名空间
annotations: # Traefik 路由注解
traefik.ingress.kubernetes.io/router.entrypoints: websecure # 使用 HTTPS entrypoint
traefik.ingress.kubernetes.io/router.tls.certresolver: cloudflare # 证书解析器
spec: # Ingress 规则
tls: # TLS 配置
- hosts: # TLS 证书适用的域名列表
- test03.jackadam.top # 域名
rules: # HTTP/HTTPS 路由规则列表
- host: test03.jackadam.top # 匹配域名
http: # HTTP 规则
paths: # 路径匹配列表
- path: / # 根路径
pathType: Prefix # 前缀匹配
backend: # 后端目标
service: # 使用 Service
name: nginx-m3 # 后端 Service 名称
port: # 后端端口
number: 80 # 端口号
---
# 03-02 HTTP-onlyM3 路由(仅 web无 TLS与 nginx-m3 共用 Service
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: nginx-m3-http
namespace: default
annotations:
traefik.ingress.kubernetes.io/router.entrypoints: web
spec:
rules:
- host: test03.jackadam.top
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: nginx-m3
port:
number: 80
apiVersion: networking.k8s.io/v1 # Ingress 使用的 API 版本
kind: Ingress # Ingress 资源
metadata: # Ingress 标识
name: nginx-m3-http # HTTP-only Ingress 名称
namespace: default # 命名空间
annotations: # Traefik 路由注解
traefik.ingress.kubernetes.io/router.entrypoints: web # 使用 HTTP entrypoint
spec: # Ingress 规则
rules: # 规则列表
- host: test03.jackadam.top # 域名
http: # HTTP 规则
paths: # 路径列表
- path: / # 根路径
pathType: Prefix # 前缀匹配
backend: # 后端目标
service: # 后端 Service
name: nginx-m3 # 后端 Service 名称
port: # 后端端口
number: 80 # 端口号

View File

@@ -1,98 +1,98 @@
# 03-02 TLS: M4 工作节点 + IngressRoute路径 /(根路径),域名 test04.jackadam.top
---
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-m4-html
namespace: default
data:
index.html: |
apiVersion: v1 # ConfigMap 使用的 API 版本
kind: ConfigMap # 配置资源类型ConfigMap
metadata: # 标识信息
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: |
default.conf: | # nginx 配置:挂载到 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
kind: Deployment
metadata:
name: nginx-m4
namespace: default
labels:
app: nginx-m4
matrix: "03-02-m4"
spec:
replicas: 1
selector:
matchLabels:
app: nginx-m4
template:
metadata:
labels:
app: nginx-m4
spec:
nodeSelector:
kubernetes.io/hostname: ylc64
volumes:
- name: html
configMap:
name: nginx-m4-html
containers:
- name: nginx
image: nginx:alpine
ports:
- containerPort: 80
volumeMounts:
- name: html
mountPath: /usr/share/nginx/html/index.html
subPath: index.html
readOnly: true
- name: html
mountPath: /etc/nginx/conf.d/default.conf
subPath: default.conf
readOnly: true
apiVersion: apps/v1 # Deployment 使用的 API 版本
kind: Deployment # 工作负载Deployment
metadata: # Deployment 标识信息
name: nginx-m4 # Deployment 名称
namespace: default # 部署命名空间
labels: # 额外标签
app: nginx-m4 # 应用标签
matrix: "03-02-m4" # 矩阵编号标签
spec: # Deployment 期望状态
replicas: 1 # 副本数
selector: # Deployment 选择器
matchLabels: # 必须与 template.metadata.labels 对齐
app: nginx-m4 # 选中 app 标签为 nginx-m4 的 Pod
template: # Pod 模板
metadata: # Pod 元信息
labels: # Pod 标签
app: nginx-m4 # Pod 标签
spec: # Pod 规范
nodeSelector: # 固定跑到指定工作节点(按实际 ylc64/主机名)
kubernetes.io/hostname: ylc64 # 目标节点主机名
volumes: # 卷定义
- name: html # 卷名(给 volumeMounts 引用)
configMap: # 卷来源为 ConfigMap
name: nginx-m4-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
kind: Service
metadata:
name: nginx-m4
namespace: default
spec:
selector:
app: nginx-m4
ports:
- port: 80
targetPort: 80
apiVersion: v1 # Service 使用的 API 版本
kind: Service # 网络抽象:为 Pod 提供稳定访问入口
metadata: # Service 标识
name: nginx-m4 # Service 名称
namespace: default # 命名空间
spec: # Service 期望状态
selector: # Service 选择器
app: nginx-m4 # 选中 app 标签为 nginx-m4 的 Pod
ports: # 端口映射列表
- port: 80 # Service 暴露端口
targetPort: 80 # 转发到 Pod 容器端口
---
apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
name: nginx-m4
namespace: default
spec:
entryPoints:
- websecure
routes:
- match: Host(`test04.jackadam.top`)
kind: Rule
services:
- name: nginx-m4
port: 80
tls:
certResolver: cloudflare
apiVersion: traefik.io/v1alpha1 # IngressRoute API 版本
kind: IngressRoute # Traefik 路由资源类型
metadata: # 标识信息
name: nginx-m4 # IngressRoute 名称
namespace: default # 命名空间
spec: # 规则与 TLS
entryPoints: # Traefik entrypoints
- websecure # HTTPS entrypoint
routes: # 路由列表
- match: Host(`test04.jackadam.top`) # 域名匹配
kind: Rule # 规则类型
services: # 后端服务列表
- name: nginx-m4 # 后端 Service 名称
port: 80 # 后端端口
tls: # TLS 配置
certResolver: cloudflare # 使用 cloudflare 证书解析器
---
# 03-02 HTTP-onlyM4 路由(仅 web无 TLS与 nginx-m4 共用 Service
apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
name: nginx-m4-http
namespace: default
spec:
entryPoints:
- web
routes:
- match: Host(`test04.jackadam.top`)
kind: Rule
services:
- name: nginx-m4
port: 80
apiVersion: traefik.io/v1alpha1 # IngressRoute API 版本
kind: IngressRoute # Traefik 路由资源类型
metadata: # 标识信息
name: nginx-m4-http # HTTP-only 路由名
namespace: default # 命名空间
spec: # 规则
entryPoints: # HTTP entrypoint
- web # webHTTP
routes: # 路由列表
- match: Host(`test04.jackadam.top`) # 域名匹配
kind: Rule # 规则类型
services: # 后端服务
- name: nginx-m4 # 后端 Service 名称
port: 80 # 后端端口

View File

@@ -2,99 +2,99 @@
# 路径 /demo-m1随机一台控制节点nodeSelector + toleration控制节点常有 NoSchedule 污点)
# ConfigMap首页 + default.conf单文件 subPath 挂载,与 M2M4 一致,便于 nginx 后续扩展)
---
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-m1-html
namespace: default
data:
index.html: |
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: |
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
kind: Deployment
metadata:
name: nginx-m1
namespace: default
labels:
app: nginx-m1
matrix: "02-05-m1"
spec:
replicas: 1
selector:
matchLabels:
app: nginx-m1
template:
metadata:
labels:
app: nginx-m1
spec:
nodeSelector:
node-role.kubernetes.io/control-plane: ""
tolerations:
- key: node-role.kubernetes.io/control-plane
operator: Exists
effect: NoSchedule
volumes:
- name: html
configMap:
name: nginx-m1-html
containers:
- name: nginx
image: nginx:alpine
ports:
- containerPort: 80
volumeMounts:
- name: html
mountPath: /usr/share/nginx/html/index.html
subPath: index.html
readOnly: true
- name: html
mountPath: /etc/nginx/conf.d/default.conf
subPath: default.conf
readOnly: true
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
kind: Service
metadata:
name: nginx-m1
namespace: default
spec:
selector:
app: nginx-m1
ports:
- port: 80
targetPort: 80
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
kind: Middleware
metadata:
name: stripprefix-m1
namespace: default
spec:
stripPrefix:
prefixes:
- /demo-m1
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
kind: Ingress
metadata:
name: nginx-m1
namespace: default
annotations:
traefik.ingress.kubernetes.io/router.middlewares: default-stripprefix-m1@kubernetescrd
spec:
rules:
- http:
paths:
- path: /demo-m1
pathType: Prefix
backend:
service:
name: nginx-m1
port:
number: 80
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 # 端口号

View File

@@ -2,93 +2,93 @@
# 路径 /demo-m2指定一台控制节点按实际 FQDN 修改 kubernetes.io/hostname
# ConfigMap首页 + default.confX-Backend: M2 便于区分
---
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-m2-html
namespace: default
data:
index.html: |
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: |
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
kind: Deployment
metadata:
name: nginx-m2
namespace: default
labels:
app: nginx-m2
matrix: "02-05-m2"
spec:
replicas: 1
selector:
matchLabels:
app: nginx-m2
template:
metadata:
labels:
app: nginx-m2
spec:
nodeSelector:
kubernetes.io/hostname: ylc61
volumes:
- name: html
configMap:
name: nginx-m2-html
containers:
- name: nginx
image: nginx:alpine
ports:
- containerPort: 80
volumeMounts:
- name: html
mountPath: /usr/share/nginx/html/index.html
subPath: index.html
readOnly: true
- name: html
mountPath: /etc/nginx/conf.d/default.conf
subPath: default.conf
readOnly: true
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
kind: Service
metadata:
name: nginx-m2
namespace: default
spec:
selector:
app: nginx-m2
ports:
- port: 80
targetPort: 80
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
kind: Middleware
metadata:
name: stripprefix-m2
namespace: default
spec:
stripPrefix:
prefixes:
- /demo-m2
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
kind: IngressRoute
metadata:
name: nginx-m2
namespace: default
spec:
entryPoints:
- web
routes:
- match: PathPrefix(`/demo-m2`)
kind: Rule
middlewares:
- name: stripprefix-m2
services:
- name: nginx-m2
port: 80
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 端口

View File

@@ -2,95 +2,95 @@
# 路径 /demo-m3随机一台工作节点nodeSelector: node-role.kubernetes.io/worker
# ConfigMap首页 + default.confX-Backend: M3 便于区分
---
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-m3-html
namespace: default
data:
index.html: |
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: |
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
kind: Deployment
metadata:
name: nginx-m3
namespace: default
labels:
app: nginx-m3
matrix: "02-05-m3"
spec:
replicas: 1
selector:
matchLabels:
app: nginx-m3
template:
metadata:
labels:
app: nginx-m3
spec:
nodeSelector:
node-role.kubernetes.io/worker: ""
volumes:
- name: html
configMap:
name: nginx-m3-html
containers:
- name: nginx
image: nginx:alpine
ports:
- containerPort: 80
volumeMounts:
- name: html
mountPath: /usr/share/nginx/html/index.html
subPath: index.html
readOnly: true
- name: html
mountPath: /etc/nginx/conf.d/default.conf
subPath: default.conf
readOnly: true
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
kind: Service
metadata:
name: nginx-m3
namespace: default
spec:
selector:
app: nginx-m3
ports:
- port: 80
targetPort: 80
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
kind: Middleware
metadata:
name: stripprefix-m3
namespace: default
spec:
stripPrefix:
prefixes:
- /demo-m3
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
kind: Ingress
metadata:
name: nginx-m3
namespace: default
annotations:
traefik.ingress.kubernetes.io/router.middlewares: default-stripprefix-m3@kubernetescrd
spec:
rules:
- http:
paths:
- path: /demo-m3
pathType: Prefix
backend:
service:
name: nginx-m3
port:
number: 80
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 # 端口号

View File

@@ -2,93 +2,93 @@
# 路径 /demo-m4指定一台工作节点按实际 FQDN 修改 kubernetes.io/hostname
# ConfigMap首页 + default.confX-Backend: M4 便于区分
---
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-m4-html
namespace: default
data:
index.html: |
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: |
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
kind: Deployment
metadata:
name: nginx-m4
namespace: default
labels:
app: nginx-m4
matrix: "02-05-m4"
spec:
replicas: 1
selector:
matchLabels:
app: nginx-m4
template:
metadata:
labels:
app: nginx-m4
spec:
nodeSelector:
kubernetes.io/hostname: ylc64
volumes:
- name: html
configMap:
name: nginx-m4-html
containers:
- name: nginx
image: nginx:alpine
ports:
- containerPort: 80
volumeMounts:
- name: html
mountPath: /usr/share/nginx/html/index.html
subPath: index.html
readOnly: true
- name: html
mountPath: /etc/nginx/conf.d/default.conf
subPath: default.conf
readOnly: true
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
kind: Service
metadata:
name: nginx-m4
namespace: default
spec:
selector:
app: nginx-m4
ports:
- port: 80
targetPort: 80
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
kind: Middleware
metadata:
name: stripprefix-m4
namespace: default
spec:
stripPrefix:
prefixes:
- /demo-m4
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
kind: IngressRoute
metadata:
name: nginx-m4
namespace: default
spec:
entryPoints:
- web
routes:
- match: PathPrefix(`/demo-m4`)
kind: Rule
middlewares:
- name: stripprefix-m4
services:
- name: nginx-m4
port: 80
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 端口

View File

@@ -1,54 +1,54 @@
# 对应文档docs/04-01-k3s-nodejs-高级部署.md
# 累积基线Deployment + Service + Ingress
apiVersion: apps/v1
kind: Deployment
metadata:
name: nodejs-demo
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: nodejs-demo
template:
metadata:
labels:
app: nodejs-demo
spec:
containers:
- name: nodejs-demo
image: node:18-alpine
command: ["node", "-e", "require('http').createServer((req,res)=>res.end('Hello World from Node.js')).listen(3000)"]
ports:
- containerPort: 3000
apiVersion: apps/v1 # Deployment API 版本
kind: Deployment # 工作负载Deployment
metadata: # Deployment 元信息
name: nodejs-demo # Deployment 名称
namespace: default # 命名空间
spec: # Deployment 规格
replicas: 1 # 副本数
selector: # Deployment 选择器
matchLabels: # 标签匹配集合
app: nodejs-demo # 匹配 app=nodejs-demo 的 Pod
template: # Pod 模板
metadata: # Pod 元信息
labels: # Pod 标签
app: nodejs-demo # 与 selector.matchLabels 对齐
spec: # Pod 规格
containers: # 容器列表
- name: nodejs-demo # 容器名
image: node:18-alpine # Node.js 镜像
command: ["node", "-e", "require('http').createServer((req,res)=>res.end('Hello World from Node.js')).listen(3000)"] # 直接运行内联 Node.js HTTP 服务
ports: # 容器端口
- containerPort: 3000 # 应用监听端口
---
apiVersion: v1
kind: Service
metadata:
name: nodejs-demo
namespace: default
spec:
selector:
app: nodejs-demo
ports:
- port: 80
targetPort: 3000
apiVersion: v1 # Service API 版本
kind: Service # Service 资源
metadata: # Service 元信息
name: nodejs-demo # Service 名称
namespace: default # 命名空间
spec: # Service 规格
selector: # 选择后端 Pod
app: nodejs-demo # 选中 app=nodejs-demo
ports: # 端口映射
- port: 80 # Service 暴露端口
targetPort: 3000 # 转发到容器端口
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: nodejs-demo
namespace: default
annotations:
traefik.ingress.kubernetes.io/router.entrypoints: web
spec:
rules:
- http:
paths:
- path: /node
pathType: Prefix
backend:
service:
name: nodejs-demo
port:
number: 80
apiVersion: networking.k8s.io/v1 # Ingress API 版本
kind: Ingress # Ingress 资源
metadata: # Ingress 元信息
name: nodejs-demo # Ingress 名称
namespace: default # 命名空间
annotations: # Traefik 注解
traefik.ingress.kubernetes.io/router.entrypoints: web # 使用 web(HTTP) 入口
spec: # Ingress 规则
rules: # 规则列表
- http: # HTTP 路由
paths: # 路径列表
- path: /node # 匹配路径前缀
pathType: Prefix # 前缀匹配
backend: # 后端目标
service: # 后端 Service
name: nodejs-demo # Service 名称
port: # Service 端口
number: 80 # 端口号

View File

@@ -1,58 +1,58 @@
# 对应文档docs/04-02-nodejs-镜像与运行命令.md
# 累积04-01 + 固定镜像 tag、imagePullPolicy、command/args
apiVersion: apps/v1
kind: Deployment
metadata:
name: nodejs-demo
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: nodejs-demo
template:
metadata:
labels:
app: nodejs-demo
spec:
containers:
- name: nodejs-demo
image: node:18.20-alpine
imagePullPolicy: IfNotPresent
command: ["node"]
args:
- "-e"
- "require('http').createServer((req,res)=>res.end('Hello from pinned image')).listen(3000)"
ports:
- containerPort: 3000
apiVersion: apps/v1 # Deployment API 版本
kind: Deployment # 工作负载Deployment
metadata: # Deployment 元信息
name: nodejs-demo # Deployment 名称
namespace: default # 命名空间
spec: # Deployment 规格
replicas: 1 # 副本数
selector: # Deployment 选择器
matchLabels: # 标签匹配集合
app: nodejs-demo # 匹配 app=nodejs-demo 的 Pod
template: # Pod 模板
metadata: # Pod 元信息
labels: # Pod 标签
app: nodejs-demo # 与 selector.matchLabels 对齐
spec: # Pod 规格
containers: # 容器列表
- name: nodejs-demo # 容器名
image: node:18.20-alpine # 固定 tag 的 Node.js 镜像
imagePullPolicy: IfNotPresent # 拉取策略:本地有则不重复拉取
command: ["node"] # 主命令
args: # 命令参数
- "-e" # 执行内联脚本
- "require('http').createServer((req,res)=>res.end('Hello from pinned image')).listen(3000)" # Node.js 内联服务逻辑
ports: # 容器端口
- containerPort: 3000 # 应用监听端口
---
apiVersion: v1
kind: Service
metadata:
name: nodejs-demo
namespace: default
spec:
selector:
app: nodejs-demo
ports:
- port: 80
targetPort: 3000
apiVersion: v1 # Service API 版本
kind: Service # Service 资源
metadata: # Service 元信息
name: nodejs-demo # Service 名称
namespace: default # 命名空间
spec: # Service 规格
selector: # 选择后端 Pod
app: nodejs-demo # 选中 app=nodejs-demo
ports: # 端口映射
- port: 80 # Service 暴露端口
targetPort: 3000 # 转发到容器端口
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: nodejs-demo
namespace: default
annotations:
traefik.ingress.kubernetes.io/router.entrypoints: web
spec:
rules:
- http:
paths:
- path: /node
pathType: Prefix
backend:
service:
name: nodejs-demo
port:
number: 80
apiVersion: networking.k8s.io/v1 # Ingress API 版本
kind: Ingress # Ingress 资源
metadata: # Ingress 元信息
name: nodejs-demo # Ingress 名称
namespace: default # 命名空间
annotations: # Traefik 注解
traefik.ingress.kubernetes.io/router.entrypoints: web # 使用 web(HTTP) 入口
spec: # Ingress 规则
rules: # 规则列表
- http: # HTTP 路由
paths: # 路径列表
- path: /node # 匹配路径前缀
pathType: Prefix # 前缀匹配
backend: # 后端目标
service: # 后端 Service
name: nodejs-demo # Service 名称
port: # Service 端口
number: 80 # 端口号

View File

@@ -1,75 +1,75 @@
# 对应文档docs/04-03-nodejs-环境变量与配置注入.md
# 累积04-02 + ConfigMap + 通过 env 注入 APP_MSG镜像仍用 18.20-alpine 与 04-02 一致)
apiVersion: v1
kind: ConfigMap
metadata:
name: nodejs-demo-config
namespace: default
data:
APP_MSG: "Hello from ConfigMap"
apiVersion: v1 # ConfigMap API 版本
kind: ConfigMap # 配置资源ConfigMap
metadata: # ConfigMap 元信息
name: nodejs-demo-config # ConfigMap 名称
namespace: default # 命名空间
data: # 配置键值
APP_MSG: "Hello from ConfigMap" # 注入给应用的消息内容
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nodejs-demo
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: nodejs-demo
template:
metadata:
labels:
app: nodejs-demo
spec:
containers:
- name: nodejs-demo
image: node:18.20-alpine
imagePullPolicy: IfNotPresent
env:
- name: APP_MSG
valueFrom:
configMapKeyRef:
name: nodejs-demo-config
key: APP_MSG
command:
- node
- "-e"
- |
apiVersion: apps/v1 # Deployment API 版本
kind: Deployment # 工作负载Deployment
metadata: # Deployment 元信息
name: nodejs-demo # Deployment 名称
namespace: default # 命名空间
spec: # Deployment 规格
replicas: 1 # 副本数
selector: # Deployment 选择器
matchLabels: # 标签匹配集合
app: nodejs-demo # 匹配 app=nodejs-demo 的 Pod
template: # Pod 模板
metadata: # Pod 元信息
labels: # Pod 标签
app: nodejs-demo # 与 selector.matchLabels 对齐
spec: # Pod 规格
containers: # 容器列表
- name: nodejs-demo # 容器名
image: node:18.20-alpine # Node.js 镜像
imagePullPolicy: IfNotPresent # 拉取策略
env: # 环境变量注入
- name: APP_MSG # 环境变量名
valueFrom: # 从资源引用取值
configMapKeyRef: # 从 ConfigMap key 读取
name: nodejs-demo-config # ConfigMap 名称
key: APP_MSG # ConfigMap 键名
command: # 启动命令
- node # 运行 node
- "-e" # 执行内联脚本
- | # 多行 JS 脚本(内部内容不改动)
const http=require('http');
const msg=process.env.APP_MSG||'no env';
http.createServer((q,s)=>s.end(msg)).listen(3000);
ports:
- containerPort: 3000
ports: # 容器端口
- containerPort: 3000 # 应用监听端口
---
apiVersion: v1
kind: Service
metadata:
name: nodejs-demo
namespace: default
spec:
selector:
app: nodejs-demo
ports:
- port: 80
targetPort: 3000
apiVersion: v1 # Service API 版本
kind: Service # Service 资源
metadata: # Service 元信息
name: nodejs-demo # Service 名称
namespace: default # 命名空间
spec: # Service 规格
selector: # 选择后端 Pod
app: nodejs-demo # 选中 app=nodejs-demo
ports: # 端口映射
- port: 80 # Service 暴露端口
targetPort: 3000 # 转发到容器端口
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: nodejs-demo
namespace: default
annotations:
traefik.ingress.kubernetes.io/router.entrypoints: web
spec:
rules:
- http:
paths:
- path: /node
pathType: Prefix
backend:
service:
name: nodejs-demo
port:
number: 80
apiVersion: networking.k8s.io/v1 # Ingress API 版本
kind: Ingress # Ingress 资源
metadata: # Ingress 元信息
name: nodejs-demo # Ingress 名称
namespace: default # 命名空间
annotations: # Traefik 注解
traefik.ingress.kubernetes.io/router.entrypoints: web # 使用 web(HTTP) 入口
spec: # Ingress 规则
rules: # 规则列表
- http: # HTTP 路由
paths: # 路径列表
- path: /node # 匹配路径前缀
pathType: Prefix # 前缀匹配
backend: # 后端目标
service: # 后端 Service
name: nodejs-demo # Service 名称
port: # Service 端口
number: 80 # 端口号

View File

@@ -1,75 +1,75 @@
# 对应文档docs/04-04-nodejs-端口与Service.md
# 累积04-03 + 容器与进程改监听 8080Service targetPort 对齐
apiVersion: v1
kind: ConfigMap
metadata:
name: nodejs-demo-config
namespace: default
data:
APP_MSG: "Hello from ConfigMap"
apiVersion: v1 # ConfigMap API 版本
kind: ConfigMap # 配置资源ConfigMap
metadata: # ConfigMap 元信息
name: nodejs-demo-config # ConfigMap 名称
namespace: default # 命名空间
data: # 配置键值
APP_MSG: "Hello from ConfigMap" # 注入给应用的消息内容
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nodejs-demo
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: nodejs-demo
template:
metadata:
labels:
app: nodejs-demo
spec:
containers:
- name: nodejs-demo
image: node:18.20-alpine
imagePullPolicy: IfNotPresent
env:
- name: APP_MSG
valueFrom:
configMapKeyRef:
name: nodejs-demo-config
key: APP_MSG
command:
- node
- "-e"
- |
apiVersion: apps/v1 # Deployment API 版本
kind: Deployment # 工作负载Deployment
metadata: # Deployment 元信息
name: nodejs-demo # Deployment 名称
namespace: default # 命名空间
spec: # Deployment 规格
replicas: 1 # 副本数
selector: # Deployment 选择器
matchLabels: # 标签匹配集合
app: nodejs-demo # 匹配 app=nodejs-demo 的 Pod
template: # Pod 模板
metadata: # Pod 元信息
labels: # Pod 标签
app: nodejs-demo # 与 selector.matchLabels 对齐
spec: # Pod 规格
containers: # 容器列表
- name: nodejs-demo # 容器名
image: node:18.20-alpine # Node.js 镜像
imagePullPolicy: IfNotPresent # 拉取策略
env: # 环境变量注入
- name: APP_MSG # 环境变量名
valueFrom: # 从资源引用取值
configMapKeyRef: # 从 ConfigMap key 读取
name: nodejs-demo-config # ConfigMap 名称
key: APP_MSG # ConfigMap 键名
command: # 启动命令
- node # 运行 node
- "-e" # 执行内联脚本
- | # 多行 JS 脚本(内部内容不改动)
const http=require('http');
const msg=process.env.APP_MSG||'no env';
http.createServer((q,s)=>s.end(msg)).listen(8080);
ports:
- containerPort: 8080
ports: # 容器端口
- containerPort: 8080 # 应用监听端口
---
apiVersion: v1
kind: Service
metadata:
name: nodejs-demo
namespace: default
spec:
selector:
app: nodejs-demo
ports:
- port: 80
targetPort: 8080
apiVersion: v1 # Service API 版本
kind: Service # Service 资源
metadata: # Service 元信息
name: nodejs-demo # Service 名称
namespace: default # 命名空间
spec: # Service 规格
selector: # 选择后端 Pod
app: nodejs-demo # 选中 app=nodejs-demo
ports: # 端口映射
- port: 80 # Service 暴露端口
targetPort: 8080 # 转发到容器端口
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: nodejs-demo
namespace: default
annotations:
traefik.ingress.kubernetes.io/router.entrypoints: web
spec:
rules:
- http:
paths:
- path: /node
pathType: Prefix
backend:
service:
name: nodejs-demo
port:
number: 80
apiVersion: networking.k8s.io/v1 # Ingress API 版本
kind: Ingress # Ingress 资源
metadata: # Ingress 元信息
name: nodejs-demo # Ingress 名称
namespace: default # 命名空间
annotations: # Traefik 注解
traefik.ingress.kubernetes.io/router.entrypoints: web # 使用 web(HTTP) 入口
spec: # Ingress 规则
rules: # 规则列表
- http: # HTTP 路由
paths: # 路径列表
- path: /node # 匹配路径前缀
pathType: Prefix # 前缀匹配
backend: # 后端目标
service: # 后端 Service
name: nodejs-demo # Service 名称
port: # Service 端口
number: 80 # 端口号

View File

@@ -1,82 +1,82 @@
# 对应文档docs/04-05-nodejs-资源请求与限制.md
# 累积04-04 + resources.requests/limits
apiVersion: v1
kind: ConfigMap
metadata:
name: nodejs-demo-config
namespace: default
data:
APP_MSG: "Hello from ConfigMap"
apiVersion: v1 # ConfigMap API 版本
kind: ConfigMap # 配置资源ConfigMap
metadata: # ConfigMap 元信息
name: nodejs-demo-config # ConfigMap 名称
namespace: default # 命名空间
data: # 配置键值
APP_MSG: "Hello from ConfigMap" # 注入给应用的消息内容
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nodejs-demo
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: nodejs-demo
template:
metadata:
labels:
app: nodejs-demo
spec:
containers:
- name: nodejs-demo
image: node:18.20-alpine
imagePullPolicy: IfNotPresent
env:
- name: APP_MSG
valueFrom:
configMapKeyRef:
name: nodejs-demo-config
key: APP_MSG
command:
- node
- "-e"
- |
apiVersion: apps/v1 # Deployment API 版本
kind: Deployment # 工作负载Deployment
metadata: # Deployment 元信息
name: nodejs-demo # Deployment 名称
namespace: default # 命名空间
spec: # Deployment 规格
replicas: 1 # 副本数
selector: # Deployment 选择器
matchLabels: # 标签匹配集合
app: nodejs-demo # 匹配 app=nodejs-demo 的 Pod
template: # Pod 模板
metadata: # Pod 元信息
labels: # Pod 标签
app: nodejs-demo # 与 selector.matchLabels 对齐
spec: # Pod 规格
containers: # 容器列表
- name: nodejs-demo # 容器名
image: node:18.20-alpine # Node.js 镜像
imagePullPolicy: IfNotPresent # 拉取策略
env: # 环境变量注入
- name: APP_MSG # 环境变量名
valueFrom: # 从资源引用取值
configMapKeyRef: # 从 ConfigMap key 读取
name: nodejs-demo-config # ConfigMap 名称
key: APP_MSG # ConfigMap 键名
command: # 启动命令
- node # 运行 node
- "-e" # 执行内联脚本
- | # 多行 JS 脚本(内部内容不改动)
const http=require('http');
const msg=process.env.APP_MSG||'no env';
http.createServer((q,s)=>s.end(msg)).listen(8080);
ports:
- containerPort: 8080
resources:
requests:
cpu: "50m"
memory: "64Mi"
limits:
cpu: "500m"
memory: "256Mi"
ports: # 容器端口
- containerPort: 8080 # 应用监听端口
resources: # 资源请求与限制
requests: # 最小资源请求
cpu: "50m" # 请求 CPU
memory: "64Mi" # 请求内存
limits: # 资源上限
cpu: "500m" # CPU 限制
memory: "256Mi" # 内存限制
---
apiVersion: v1
kind: Service
metadata:
name: nodejs-demo
namespace: default
spec:
selector:
app: nodejs-demo
ports:
- port: 80
targetPort: 8080
apiVersion: v1 # Service API 版本
kind: Service # Service 资源
metadata: # Service 元信息
name: nodejs-demo # Service 名称
namespace: default # 命名空间
spec: # Service 规格
selector: # 选择后端 Pod
app: nodejs-demo # 选中 app=nodejs-demo
ports: # 端口映射
- port: 80 # Service 暴露端口
targetPort: 8080 # 转发到容器端口
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: nodejs-demo
namespace: default
annotations:
traefik.ingress.kubernetes.io/router.entrypoints: web
spec:
rules:
- http:
paths:
- path: /node
pathType: Prefix
backend:
service:
name: nodejs-demo
port:
number: 80
apiVersion: networking.k8s.io/v1 # Ingress API 版本
kind: Ingress # Ingress 资源
metadata: # Ingress 元信息
name: nodejs-demo # Ingress 名称
namespace: default # 命名空间
annotations: # Traefik 注解
traefik.ingress.kubernetes.io/router.entrypoints: web # 使用 web(HTTP) 入口
spec: # Ingress 规则
rules: # 规则列表
- http: # HTTP 路由
paths: # 路径列表
- path: /node # 匹配路径前缀
pathType: Prefix # 前缀匹配
backend: # 后端目标
service: # 后端 Service
name: nodejs-demo # Service 名称
port: # Service 端口
number: 80 # 端口号

View File

@@ -1,94 +1,94 @@
# 对应文档docs/04-06-nodejs-探针与健康检查.md
# 累积04-05 + livenessProbe/readinessProbe端口 8080路径 /
apiVersion: v1
kind: ConfigMap
metadata:
name: nodejs-demo-config
namespace: default
data:
APP_MSG: "Hello from ConfigMap"
apiVersion: v1 # ConfigMap API 版本
kind: ConfigMap # 配置资源ConfigMap
metadata: # ConfigMap 元信息
name: nodejs-demo-config # ConfigMap 名称
namespace: default # 命名空间
data: # 配置键值
APP_MSG: "Hello from ConfigMap" # 注入给应用的消息内容
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nodejs-demo
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: nodejs-demo
template:
metadata:
labels:
app: nodejs-demo
spec:
containers:
- name: nodejs-demo
image: node:18.20-alpine
imagePullPolicy: IfNotPresent
env:
- name: APP_MSG
valueFrom:
configMapKeyRef:
name: nodejs-demo-config
key: APP_MSG
command:
- node
- "-e"
- |
apiVersion: apps/v1 # Deployment API 版本
kind: Deployment # 工作负载Deployment
metadata: # Deployment 元信息
name: nodejs-demo # Deployment 名称
namespace: default # 命名空间
spec: # Deployment 规格
replicas: 1 # 副本数
selector: # Deployment 选择器
matchLabels: # 标签匹配集合
app: nodejs-demo # 匹配 app=nodejs-demo 的 Pod
template: # Pod 模板
metadata: # Pod 元信息
labels: # Pod 标签
app: nodejs-demo # 与 selector.matchLabels 对齐
spec: # Pod 规格
containers: # 容器列表
- name: nodejs-demo # 容器名
image: node:18.20-alpine # Node.js 镜像
imagePullPolicy: IfNotPresent # 拉取策略
env: # 环境变量注入
- name: APP_MSG # 环境变量名
valueFrom: # 从资源引用取值
configMapKeyRef: # 从 ConfigMap key 读取
name: nodejs-demo-config # ConfigMap 名称
key: APP_MSG # ConfigMap 键名
command: # 启动命令
- node # 运行 node
- "-e" # 执行内联脚本
- | # 多行 JS 脚本(内部内容不改动)
const http=require('http');
const msg=process.env.APP_MSG||'no env';
http.createServer((q,s)=>s.end(msg)).listen(8080);
ports:
- containerPort: 8080
resources:
requests:
cpu: "50m"
memory: "64Mi"
limits:
cpu: "500m"
memory: "256Mi"
livenessProbe:
httpGet:
path: /
port: 8080
initialDelaySeconds: 3
periodSeconds: 10
readinessProbe:
httpGet:
path: /
port: 8080
initialDelaySeconds: 2
periodSeconds: 5
ports: # 容器端口
- containerPort: 8080 # 应用监听端口
resources: # 资源请求与限制
requests: # 最小资源请求
cpu: "50m" # 请求 CPU
memory: "64Mi" # 请求内存
limits: # 资源上限
cpu: "500m" # CPU 限制
memory: "256Mi" # 内存限制
livenessProbe: # 存活探针(判断容器是否需要重启)
httpGet: # 通过 HTTP 探测
path: / # 探测路径
port: 8080 # 探测端口
initialDelaySeconds: 3 # 启动后首次探测延迟
periodSeconds: 10 # 探测周期
readinessProbe: # 就绪探针(判断是否接收流量)
httpGet: # 通过 HTTP 探测
path: / # 探测路径
port: 8080 # 探测端口
initialDelaySeconds: 2 # 启动后首次探测延迟
periodSeconds: 5 # 探测周期
---
apiVersion: v1
kind: Service
metadata:
name: nodejs-demo
namespace: default
spec:
selector:
app: nodejs-demo
ports:
- port: 80
targetPort: 8080
apiVersion: v1 # Service API 版本
kind: Service # Service 资源
metadata: # Service 元信息
name: nodejs-demo # Service 名称
namespace: default # 命名空间
spec: # Service 规格
selector: # 选择后端 Pod
app: nodejs-demo # 选中 app=nodejs-demo
ports: # 端口映射
- port: 80 # Service 暴露端口
targetPort: 8080 # 转发到容器端口
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: nodejs-demo
namespace: default
annotations:
traefik.ingress.kubernetes.io/router.entrypoints: web
spec:
rules:
- http:
paths:
- path: /node
pathType: Prefix
backend:
service:
name: nodejs-demo
port:
number: 80
apiVersion: networking.k8s.io/v1 # Ingress API 版本
kind: Ingress # Ingress 资源
metadata: # Ingress 元信息
name: nodejs-demo # Ingress 名称
namespace: default # 命名空间
annotations: # Traefik 注解
traefik.ingress.kubernetes.io/router.entrypoints: web # 使用 web(HTTP) 入口
spec: # Ingress 规则
rules: # 规则列表
- http: # HTTP 路由
paths: # 路径列表
- path: /node # 匹配路径前缀
pathType: Prefix # 前缀匹配
backend: # 后端目标
service: # 后端 Service
name: nodejs-demo # Service 名称
port: # Service 端口
number: 80 # 端口号

View File

@@ -1,96 +1,96 @@
# 对应文档docs/04-07-nodejs-调度与亲和.md
# 累积04-06 + nodeSelector默认 ylc62请改为本集群节点短主机名
apiVersion: v1
kind: ConfigMap
metadata:
name: nodejs-demo-config
namespace: default
data:
APP_MSG: "Hello from ConfigMap"
apiVersion: v1 # ConfigMap API 版本
kind: ConfigMap # 配置资源ConfigMap
metadata: # ConfigMap 元信息
name: nodejs-demo-config # ConfigMap 名称
namespace: default # 命名空间
data: # 配置键值
APP_MSG: "Hello from ConfigMap" # 注入给应用的消息内容
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nodejs-demo
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: nodejs-demo
template:
metadata:
labels:
app: nodejs-demo
spec:
nodeSelector:
kubernetes.io/hostname: ylc62
containers:
- name: nodejs-demo
image: node:18.20-alpine
imagePullPolicy: IfNotPresent
env:
- name: APP_MSG
valueFrom:
configMapKeyRef:
name: nodejs-demo-config
key: APP_MSG
command:
- node
- "-e"
- |
apiVersion: apps/v1 # Deployment API 版本
kind: Deployment # 工作负载Deployment
metadata: # Deployment 元信息
name: nodejs-demo # Deployment 名称
namespace: default # 命名空间
spec: # Deployment 规格
replicas: 1 # 副本数
selector: # Deployment 选择器
matchLabels: # 标签匹配集合
app: nodejs-demo # 匹配 app=nodejs-demo 的 Pod
template: # Pod 模板
metadata: # Pod 元信息
labels: # Pod 标签
app: nodejs-demo # 与 selector.matchLabels 对齐
spec: # Pod 规格
nodeSelector: # 调度到指定节点
kubernetes.io/hostname: ylc62 # 节点主机名(按实际修改)
containers: # 容器列表
- name: nodejs-demo # 容器名
image: node:18.20-alpine # Node.js 镜像
imagePullPolicy: IfNotPresent # 拉取策略
env: # 环境变量注入
- name: APP_MSG # 环境变量名
valueFrom: # 从资源引用取值
configMapKeyRef: # 从 ConfigMap key 读取
name: nodejs-demo-config # ConfigMap 名称
key: APP_MSG # ConfigMap 键名
command: # 启动命令
- node # 运行 node
- "-e" # 执行内联脚本
- | # 多行 JS 脚本(内部内容不改动)
const http=require('http');
const msg=process.env.APP_MSG||'no env';
http.createServer((q,s)=>s.end(msg)).listen(8080);
ports:
- containerPort: 8080
resources:
requests:
cpu: "50m"
memory: "64Mi"
limits:
cpu: "500m"
memory: "256Mi"
livenessProbe:
httpGet:
path: /
port: 8080
initialDelaySeconds: 3
periodSeconds: 10
readinessProbe:
httpGet:
path: /
port: 8080
initialDelaySeconds: 2
periodSeconds: 5
ports: # 容器端口
- containerPort: 8080 # 应用监听端口
resources: # 资源请求与限制
requests: # 最小资源请求
cpu: "50m" # 请求 CPU
memory: "64Mi" # 请求内存
limits: # 资源上限
cpu: "500m" # CPU 限制
memory: "256Mi" # 内存限制
livenessProbe: # 存活探针
httpGet: # HTTP 探测
path: / # 探测路径
port: 8080 # 探测端口
initialDelaySeconds: 3 # 启动后首次探测延迟
periodSeconds: 10 # 探测周期
readinessProbe: # 就绪探针
httpGet: # HTTP 探测
path: / # 探测路径
port: 8080 # 探测端口
initialDelaySeconds: 2 # 启动后首次探测延迟
periodSeconds: 5 # 探测周期
---
apiVersion: v1
kind: Service
metadata:
name: nodejs-demo
namespace: default
spec:
selector:
app: nodejs-demo
ports:
- port: 80
targetPort: 8080
apiVersion: v1 # Service API 版本
kind: Service # Service 资源
metadata: # Service 元信息
name: nodejs-demo # Service 名称
namespace: default # 命名空间
spec: # Service 规格
selector: # 选择后端 Pod
app: nodejs-demo # 选中 app=nodejs-demo
ports: # 端口映射
- port: 80 # Service 暴露端口
targetPort: 8080 # 转发到容器端口
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: nodejs-demo
namespace: default
annotations:
traefik.ingress.kubernetes.io/router.entrypoints: web
spec:
rules:
- http:
paths:
- path: /node
pathType: Prefix
backend:
service:
name: nodejs-demo
port:
number: 80
apiVersion: networking.k8s.io/v1 # Ingress API 版本
kind: Ingress # Ingress 资源
metadata: # Ingress 元信息
name: nodejs-demo # Ingress 名称
namespace: default # 命名空间
annotations: # Traefik 注解
traefik.ingress.kubernetes.io/router.entrypoints: web # 使用 web(HTTP) 入口
spec: # Ingress 规则
rules: # 规则列表
- http: # HTTP 路由
paths: # 路径列表
- path: /node # 匹配路径前缀
pathType: Prefix # 前缀匹配
backend: # 后端目标
service: # 后端 Service
name: nodejs-demo # Service 名称
port: # Service 端口
number: 80 # 端口号

View File

@@ -1,109 +1,109 @@
# 对应文档docs/04-08-nodejs-安全上下文.md
# 累积04-07 + pod securityContext.fsGroup、容器 securityContext、只读根、/tmp emptyDir
apiVersion: v1
kind: ConfigMap
metadata:
name: nodejs-demo-config
namespace: default
data:
APP_MSG: "Hello from ConfigMap"
apiVersion: v1 # ConfigMap API 版本
kind: ConfigMap # 配置资源ConfigMap
metadata: # ConfigMap 元信息
name: nodejs-demo-config # ConfigMap 名称
namespace: default # 命名空间
data: # 配置键值
APP_MSG: "Hello from ConfigMap" # 注入给应用的消息内容
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nodejs-demo
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: nodejs-demo
template:
metadata:
labels:
app: nodejs-demo
spec:
nodeSelector:
kubernetes.io/hostname: ylc62
securityContext:
fsGroup: 1000
containers:
- name: nodejs-demo
image: node:18.20-alpine
imagePullPolicy: IfNotPresent
securityContext:
allowPrivilegeEscalation: false
runAsNonRoot: true
runAsUser: 1000
readOnlyRootFilesystem: true
env:
- name: APP_MSG
valueFrom:
configMapKeyRef:
name: nodejs-demo-config
key: APP_MSG
command:
- node
- "-e"
- |
apiVersion: apps/v1 # Deployment API 版本
kind: Deployment # 工作负载Deployment
metadata: # Deployment 元信息
name: nodejs-demo # Deployment 名称
namespace: default # 命名空间
spec: # Deployment 规格
replicas: 1 # 副本数
selector: # Deployment 选择器
matchLabels: # 标签匹配集合
app: nodejs-demo # 匹配 app=nodejs-demo 的 Pod
template: # Pod 模板
metadata: # Pod 元信息
labels: # Pod 标签
app: nodejs-demo # 与 selector.matchLabels 对齐
spec: # Pod 规格
nodeSelector: # 调度到指定节点
kubernetes.io/hostname: ylc62 # 节点主机名(按实际修改)
securityContext: # Pod 级安全上下文
fsGroup: 1000 # 挂载卷文件组 ID
containers: # 容器列表
- name: nodejs-demo # 容器名
image: node:18.20-alpine # Node.js 镜像
imagePullPolicy: IfNotPresent # 拉取策略
securityContext: # 容器级安全上下文
allowPrivilegeEscalation: false # 禁止提权
runAsNonRoot: true # 强制非 root 运行
runAsUser: 1000 # 运行用户 UID
readOnlyRootFilesystem: true # 根文件系统只读
env: # 环境变量注入
- name: APP_MSG # 环境变量名
valueFrom: # 从资源引用取值
configMapKeyRef: # 从 ConfigMap key 读取
name: nodejs-demo-config # ConfigMap 名称
key: APP_MSG # ConfigMap 键名
command: # 启动命令
- node # 运行 node
- "-e" # 执行内联脚本
- | # 多行 JS 脚本(内部内容不改动)
const http=require('http');
const msg=process.env.APP_MSG||'no env';
http.createServer((q,s)=>s.end(msg)).listen(8080);
ports:
- containerPort: 8080
resources:
requests:
cpu: "50m"
memory: "64Mi"
limits:
cpu: "500m"
memory: "256Mi"
livenessProbe:
httpGet:
path: /
port: 8080
initialDelaySeconds: 3
periodSeconds: 10
readinessProbe:
httpGet:
path: /
port: 8080
initialDelaySeconds: 2
periodSeconds: 5
volumeMounts:
- name: tmp
mountPath: /tmp
volumes:
- name: tmp
emptyDir: {}
ports: # 容器端口
- containerPort: 8080 # 应用监听端口
resources: # 资源请求与限制
requests: # 最小资源请求
cpu: "50m" # 请求 CPU
memory: "64Mi" # 请求内存
limits: # 资源上限
cpu: "500m" # CPU 限制
memory: "256Mi" # 内存限制
livenessProbe: # 存活探针
httpGet: # HTTP 探测
path: / # 探测路径
port: 8080 # 探测端口
initialDelaySeconds: 3 # 启动后首次探测延迟
periodSeconds: 10 # 探测周期
readinessProbe: # 就绪探针
httpGet: # HTTP 探测
path: / # 探测路径
port: 8080 # 探测端口
initialDelaySeconds: 2 # 启动后首次探测延迟
periodSeconds: 5 # 探测周期
volumeMounts: # 卷挂载
- name: tmp # 引用临时卷
mountPath: /tmp # 容器内临时目录
volumes: # 卷定义
- name: tmp # 临时卷名称
emptyDir: {} # 空目录卷Pod 生命周期内)
---
apiVersion: v1
kind: Service
metadata:
name: nodejs-demo
namespace: default
spec:
selector:
app: nodejs-demo
ports:
- port: 80
targetPort: 8080
apiVersion: v1 # Service API 版本
kind: Service # Service 资源
metadata: # Service 元信息
name: nodejs-demo # Service 名称
namespace: default # 命名空间
spec: # Service 规格
selector: # 选择后端 Pod
app: nodejs-demo # 选中 app=nodejs-demo
ports: # 端口映射
- port: 80 # Service 暴露端口
targetPort: 8080 # 转发到容器端口
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: nodejs-demo
namespace: default
annotations:
traefik.ingress.kubernetes.io/router.entrypoints: web
spec:
rules:
- http:
paths:
- path: /node
pathType: Prefix
backend:
service:
name: nodejs-demo
port:
number: 80
apiVersion: networking.k8s.io/v1 # Ingress API 版本
kind: Ingress # Ingress 资源
metadata: # Ingress 元信息
name: nodejs-demo # Ingress 名称
namespace: default # 命名空间
annotations: # Traefik 注解
traefik.ingress.kubernetes.io/router.entrypoints: web # 使用 web(HTTP) 入口
spec: # Ingress 规则
rules: # 规则列表
- http: # HTTP 路由
paths: # 路径列表
- path: /node # 匹配路径前缀
pathType: Prefix # 前缀匹配
backend: # 后端目标
service: # 后端 Service
name: nodejs-demo # Service 名称
port: # Service 端口
number: 80 # 端口号

View File

@@ -1,127 +1,127 @@
# 对应文档docs/04-09-nodejs-存储与卷.md
# 累积04-08 + PVC nodejs-demo-data默认 storageClassName: local-path可按集群改为 longhorn 等)+ 挂载 /data
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: nodejs-demo-data
namespace: default
spec:
accessModes:
- ReadWriteOnce
storageClassName: local-path
resources:
requests:
storage: 1Gi
apiVersion: v1 # PVC API 版本
kind: PersistentVolumeClaim # 持久卷声明
metadata: # PVC 元信息
name: nodejs-demo-data # PVC 名称
namespace: default # 命名空间
spec: # PVC 规格
accessModes: # 访问模式
- ReadWriteOnce # RWO同一时间仅单节点挂载读写
storageClassName: local-path # 存储类(按集群可改)
resources: # 资源请求
requests: # 配额请求
storage: 1Gi # 申请容量
---
apiVersion: v1
kind: ConfigMap
metadata:
name: nodejs-demo-config
namespace: default
data:
APP_MSG: "Hello from ConfigMap"
apiVersion: v1 # ConfigMap API 版本
kind: ConfigMap # 配置资源
metadata: # ConfigMap 元信息
name: nodejs-demo-config # ConfigMap 名称
namespace: default # 命名空间
data: # 配置键值
APP_MSG: "Hello from ConfigMap" # 示例消息内容
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nodejs-demo
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: nodejs-demo
template:
metadata:
labels:
app: nodejs-demo
spec:
nodeSelector:
kubernetes.io/hostname: ylc62
securityContext:
fsGroup: 1000
containers:
- name: nodejs-demo
image: node:18.20-alpine
imagePullPolicy: IfNotPresent
securityContext:
allowPrivilegeEscalation: false
runAsNonRoot: true
runAsUser: 1000
readOnlyRootFilesystem: true
env:
- name: APP_MSG
valueFrom:
configMapKeyRef:
name: nodejs-demo-config
key: APP_MSG
command:
- node
- "-e"
- |
apiVersion: apps/v1 # Deployment API 版本
kind: Deployment # 工作负载Deployment
metadata: # Deployment 元信息
name: nodejs-demo # Deployment 名称
namespace: default # 命名空间
spec: # Deployment 规格
replicas: 1 # 副本数
selector: # Pod 选择器
matchLabels: # 标签匹配集合
app: nodejs-demo # 匹配 app=nodejs-demo 的 Pod
template: # Pod 模板
metadata: # Pod 元信息
labels: # Pod 标签
app: nodejs-demo # 与 selector.matchLabels 对齐
spec: # Pod 规格
nodeSelector: # 节点选择
kubernetes.io/hostname: ylc62 # 固定到指定节点(按实际修改)
securityContext: # Pod 级安全上下文
fsGroup: 1000 # 挂载卷文件组 ID
containers: # 容器列表
- name: nodejs-demo # 容器名
image: node:18.20-alpine # Node.js 镜像
imagePullPolicy: IfNotPresent # 拉取策略
securityContext: # 容器级安全上下文
allowPrivilegeEscalation: false # 禁止提权
runAsNonRoot: true # 非 root 运行
runAsUser: 1000 # 运行用户 UID
readOnlyRootFilesystem: true # 根文件系统只读
env: # 环境变量
- name: APP_MSG # 环境变量名
valueFrom: # 从引用源取值
configMapKeyRef: # 从 ConfigMap key 读取
name: nodejs-demo-config # ConfigMap 名称
key: APP_MSG # ConfigMap 键名
command: # 启动命令
- node # 执行 node
- "-e" # 执行内联脚本
- | # 多行 JS 脚本(内容保持原样)
const http=require('http');
const msg=process.env.APP_MSG||'no env';
http.createServer((q,s)=>s.end(msg)).listen(8080);
ports:
- containerPort: 8080
resources:
requests:
cpu: "50m"
memory: "64Mi"
limits:
cpu: "500m"
memory: "256Mi"
livenessProbe:
httpGet:
path: /
port: 8080
initialDelaySeconds: 3
periodSeconds: 10
readinessProbe:
httpGet:
path: /
port: 8080
initialDelaySeconds: 2
periodSeconds: 5
volumeMounts:
- name: tmp
mountPath: /tmp
- name: data
mountPath: /data
volumes:
- name: tmp
emptyDir: {}
- name: data
persistentVolumeClaim:
claimName: nodejs-demo-data
ports: # 容器端口
- containerPort: 8080 # 监听端口
resources: # 资源请求与限制
requests: # 最小资源请求
cpu: "50m" # 请求 CPU
memory: "64Mi" # 请求内存
limits: # 资源上限
cpu: "500m" # CPU 限制
memory: "256Mi" # 内存限制
livenessProbe: # 存活探针
httpGet: # HTTP 探测
path: / # 探测路径
port: 8080 # 探测端口
initialDelaySeconds: 3 # 初始延迟
periodSeconds: 10 # 探测周期
readinessProbe: # 就绪探针
httpGet: # HTTP 探测
path: / # 探测路径
port: 8080 # 探测端口
initialDelaySeconds: 2 # 初始延迟
periodSeconds: 5 # 探测周期
volumeMounts: # 卷挂载
- name: tmp # 临时卷名称
mountPath: /tmp # 容器内临时目录
- name: data # 数据卷名称
mountPath: /data # 容器内数据目录
volumes: # 卷定义
- name: tmp # 临时卷
emptyDir: {} # 空目录卷
- name: data # 数据卷
persistentVolumeClaim: # 卷来源为 PVC
claimName: nodejs-demo-data # 绑定 PVC 名称
---
apiVersion: v1
kind: Service
metadata:
name: nodejs-demo
namespace: default
spec:
selector:
app: nodejs-demo
ports:
- port: 80
targetPort: 8080
apiVersion: v1 # Service API 版本
kind: Service # Service 资源
metadata: # Service 元信息
name: nodejs-demo # Service 名称
namespace: default # 命名空间
spec: # Service 规格
selector: # 选择后端 Pod
app: nodejs-demo # 选中 app=nodejs-demo
ports: # 端口映射
- port: 80 # Service 暴露端口
targetPort: 8080 # 转发到容器端口
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: nodejs-demo
namespace: default
annotations:
traefik.ingress.kubernetes.io/router.entrypoints: web
spec:
rules:
- http:
paths:
- path: /node
pathType: Prefix
backend:
service:
name: nodejs-demo
port:
number: 80
apiVersion: networking.k8s.io/v1 # Ingress API 版本
kind: Ingress # Ingress 资源
metadata: # Ingress 元信息
name: nodejs-demo # Ingress 名称
namespace: default # 命名空间
annotations: # Traefik 注解
traefik.ingress.kubernetes.io/router.entrypoints: web # 使用 web(HTTP) 入口
spec: # Ingress 规则
rules: # 规则列表
- http: # HTTP 路由
paths: # 路径列表
- path: /node # 路径前缀
pathType: Prefix # 前缀匹配
backend: # 后端目标
service: # 后端 Service
name: nodejs-demo # Service 名称
port: # Service 端口
number: 80 # 端口号

View File

@@ -1,128 +1,128 @@
# 对应文档docs/04-10-nodejs-Ingress与Traefik.md
# 累积04-09 + Ingress 增加 host、path 改为 /api访问需 Host: app.example.local
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: nodejs-demo-data
namespace: default
spec:
accessModes:
- ReadWriteOnce
storageClassName: local-path
resources:
requests:
storage: 1Gi
apiVersion: v1 # PVC API 版本
kind: PersistentVolumeClaim # 持久卷声明
metadata: # PVC 元信息
name: nodejs-demo-data # PVC 名称
namespace: default # 命名空间
spec: # PVC 规格
accessModes: # 访问模式
- ReadWriteOnce # RWO同一时间仅单节点挂载读写
storageClassName: local-path # 存储类
resources: # 资源请求
requests: # 配额请求
storage: 1Gi # 申请容量
---
apiVersion: v1
kind: ConfigMap
metadata:
name: nodejs-demo-config
namespace: default
data:
APP_MSG: "Hello from ConfigMap"
apiVersion: v1 # ConfigMap API 版本
kind: ConfigMap # 配置资源
metadata: # ConfigMap 元信息
name: nodejs-demo-config # ConfigMap 名称
namespace: default # 命名空间
data: # 配置键值
APP_MSG: "Hello from ConfigMap" # 示例消息内容
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nodejs-demo
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: nodejs-demo
template:
metadata:
labels:
app: nodejs-demo
spec:
nodeSelector:
kubernetes.io/hostname: ylc62
securityContext:
fsGroup: 1000
containers:
- name: nodejs-demo
image: node:18.20-alpine
imagePullPolicy: IfNotPresent
securityContext:
allowPrivilegeEscalation: false
runAsNonRoot: true
runAsUser: 1000
readOnlyRootFilesystem: true
env:
- name: APP_MSG
valueFrom:
configMapKeyRef:
name: nodejs-demo-config
key: APP_MSG
command:
- node
- "-e"
- |
apiVersion: apps/v1 # Deployment API 版本
kind: Deployment # 工作负载Deployment
metadata: # Deployment 元信息
name: nodejs-demo # Deployment 名称
namespace: default # 命名空间
spec: # Deployment 规格
replicas: 1 # 副本数
selector: # Pod 选择器
matchLabels: # 标签匹配集合
app: nodejs-demo # 匹配 app=nodejs-demo 的 Pod
template: # Pod 模板
metadata: # Pod 元信息
labels: # Pod 标签
app: nodejs-demo # 与 selector.matchLabels 对齐
spec: # Pod 规格
nodeSelector: # 节点选择
kubernetes.io/hostname: ylc62 # 固定到指定节点(按实际修改)
securityContext: # Pod 级安全上下文
fsGroup: 1000 # 挂载卷文件组 ID
containers: # 容器列表
- name: nodejs-demo # 容器名
image: node:18.20-alpine # Node.js 镜像
imagePullPolicy: IfNotPresent # 拉取策略
securityContext: # 容器级安全上下文
allowPrivilegeEscalation: false # 禁止提权
runAsNonRoot: true # 非 root 运行
runAsUser: 1000 # 运行用户 UID
readOnlyRootFilesystem: true # 根文件系统只读
env: # 环境变量
- name: APP_MSG # 环境变量名
valueFrom: # 从引用源取值
configMapKeyRef: # 从 ConfigMap key 读取
name: nodejs-demo-config # ConfigMap 名称
key: APP_MSG # ConfigMap 键名
command: # 启动命令
- node # 执行 node
- "-e" # 执行内联脚本
- | # 多行 JS 脚本(内容保持原样)
const http=require('http');
const msg=process.env.APP_MSG||'no env';
http.createServer((q,s)=>s.end(msg)).listen(8080);
ports:
- containerPort: 8080
resources:
requests:
cpu: "50m"
memory: "64Mi"
limits:
cpu: "500m"
memory: "256Mi"
livenessProbe:
httpGet:
path: /
port: 8080
initialDelaySeconds: 3
periodSeconds: 10
readinessProbe:
httpGet:
path: /
port: 8080
initialDelaySeconds: 2
periodSeconds: 5
volumeMounts:
- name: tmp
mountPath: /tmp
- name: data
mountPath: /data
volumes:
- name: tmp
emptyDir: {}
- name: data
persistentVolumeClaim:
claimName: nodejs-demo-data
ports: # 容器端口
- containerPort: 8080 # 监听端口
resources: # 资源请求与限制
requests: # 最小资源请求
cpu: "50m" # 请求 CPU
memory: "64Mi" # 请求内存
limits: # 资源上限
cpu: "500m" # CPU 限制
memory: "256Mi" # 内存限制
livenessProbe: # 存活探针
httpGet: # HTTP 探测
path: / # 探测路径
port: 8080 # 探测端口
initialDelaySeconds: 3 # 初始延迟
periodSeconds: 10 # 探测周期
readinessProbe: # 就绪探针
httpGet: # HTTP 探测
path: / # 探测路径
port: 8080 # 探测端口
initialDelaySeconds: 2 # 初始延迟
periodSeconds: 5 # 探测周期
volumeMounts: # 卷挂载
- name: tmp # 临时卷名称
mountPath: /tmp # 容器内临时目录
- name: data # 数据卷名称
mountPath: /data # 容器内数据目录
volumes: # 卷定义
- name: tmp # 临时卷
emptyDir: {} # 空目录卷
- name: data # 数据卷
persistentVolumeClaim: # 卷来源为 PVC
claimName: nodejs-demo-data # 绑定 PVC 名称
---
apiVersion: v1
kind: Service
metadata:
name: nodejs-demo
namespace: default
spec:
selector:
app: nodejs-demo
ports:
- port: 80
targetPort: 8080
apiVersion: v1 # Service API 版本
kind: Service # Service 资源
metadata: # Service 元信息
name: nodejs-demo # Service 名称
namespace: default # 命名空间
spec: # Service 规格
selector: # 选择后端 Pod
app: nodejs-demo # 选中 app=nodejs-demo
ports: # 端口映射
- port: 80 # Service 暴露端口
targetPort: 8080 # 转发到容器端口
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: nodejs-demo
namespace: default
annotations:
traefik.ingress.kubernetes.io/router.entrypoints: web
spec:
rules:
- host: app.example.local
http:
paths:
- path: /api
pathType: Prefix
backend:
service:
name: nodejs-demo
port:
number: 80
apiVersion: networking.k8s.io/v1 # Ingress API 版本
kind: Ingress # Ingress 资源
metadata: # Ingress 元信息
name: nodejs-demo # Ingress 名称
namespace: default # 命名空间
annotations: # Traefik 注解
traefik.ingress.kubernetes.io/router.entrypoints: web # 使用 web(HTTP) 入口
spec: # Ingress 规则
rules: # 规则列表
- host: app.example.local # 主机名匹配
http: # HTTP 路由
paths: # 路径列表
- path: /api # 匹配 API 路径前缀
pathType: Prefix # 前缀匹配
backend: # 后端目标
service: # 后端 Service
name: nodejs-demo # Service 名称
port: # Service 端口
number: 80 # 端口号

View File

@@ -1,133 +1,133 @@
# 对应文档docs/04-11-nodejs-副本与滚动发布.md
# 累积04-10 + replicas: 3 + RollingUpdatemaxSurge:1 maxUnavailable:0
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: nodejs-demo-data
namespace: default
spec:
accessModes:
- ReadWriteOnce
storageClassName: local-path
resources:
requests:
storage: 1Gi
apiVersion: v1 # PVC API 版本
kind: PersistentVolumeClaim # 持久卷声明
metadata: # PVC 元信息
name: nodejs-demo-data # PVC 名称
namespace: default # 命名空间
spec: # PVC 规格
accessModes: # 访问模式
- ReadWriteOnce # RWO同一时间仅单节点挂载读写
storageClassName: local-path # 存储类
resources: # 资源请求
requests: # 配额请求
storage: 1Gi # 申请容量
---
apiVersion: v1
kind: ConfigMap
metadata:
name: nodejs-demo-config
namespace: default
data:
APP_MSG: "Hello from ConfigMap"
apiVersion: v1 # ConfigMap API 版本
kind: ConfigMap # 配置资源
metadata: # ConfigMap 元信息
name: nodejs-demo-config # ConfigMap 名称
namespace: default # 命名空间
data: # 配置键值
APP_MSG: "Hello from ConfigMap" # 示例消息内容
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nodejs-demo
namespace: default
spec:
replicas: 3
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
selector:
matchLabels:
app: nodejs-demo
template:
metadata:
labels:
app: nodejs-demo
spec:
nodeSelector:
kubernetes.io/hostname: ylc62
securityContext:
fsGroup: 1000
containers:
- name: nodejs-demo
image: node:18.20-alpine
imagePullPolicy: IfNotPresent
securityContext:
allowPrivilegeEscalation: false
runAsNonRoot: true
runAsUser: 1000
readOnlyRootFilesystem: true
env:
- name: APP_MSG
valueFrom:
configMapKeyRef:
name: nodejs-demo-config
key: APP_MSG
command:
- node
- "-e"
- |
apiVersion: apps/v1 # Deployment API 版本
kind: Deployment # 工作负载Deployment
metadata: # Deployment 元信息
name: nodejs-demo # Deployment 名称
namespace: default # 命名空间
spec: # Deployment 规格
replicas: 3 # 副本数(高可用)
strategy: # 更新策略
type: RollingUpdate # 滚动更新
rollingUpdate: # 滚动更新参数
maxSurge: 1 # 更新时最多额外增加 1 个 Pod
maxUnavailable: 0 # 更新时不可用 Pod 数为 0
selector: # Pod 选择器
matchLabels: # 标签匹配集合
app: nodejs-demo # 匹配 app=nodejs-demo 的 Pod
template: # Pod 模板
metadata: # Pod 元信息
labels: # Pod 标签
app: nodejs-demo # 与 selector.matchLabels 对齐
spec: # Pod 规格
nodeSelector: # 节点选择
kubernetes.io/hostname: ylc62 # 固定到指定节点(按实际修改)
securityContext: # Pod 级安全上下文
fsGroup: 1000 # 挂载卷文件组 ID
containers: # 容器列表
- name: nodejs-demo # 容器名
image: node:18.20-alpine # Node.js 镜像
imagePullPolicy: IfNotPresent # 拉取策略
securityContext: # 容器级安全上下文
allowPrivilegeEscalation: false # 禁止提权
runAsNonRoot: true # 非 root 运行
runAsUser: 1000 # 运行用户 UID
readOnlyRootFilesystem: true # 根文件系统只读
env: # 环境变量
- name: APP_MSG # 环境变量名
valueFrom: # 从引用源取值
configMapKeyRef: # 从 ConfigMap key 读取
name: nodejs-demo-config # ConfigMap 名称
key: APP_MSG # ConfigMap 键名
command: # 启动命令
- node # 执行 node
- "-e" # 执行内联脚本
- | # 多行 JS 脚本(内容保持原样)
const http=require('http');
const msg=process.env.APP_MSG||'no env';
http.createServer((q,s)=>s.end(msg)).listen(8080);
ports:
- containerPort: 8080
resources:
requests:
cpu: "50m"
memory: "64Mi"
limits:
cpu: "500m"
memory: "256Mi"
livenessProbe:
httpGet:
path: /
port: 8080
initialDelaySeconds: 3
periodSeconds: 10
readinessProbe:
httpGet:
path: /
port: 8080
initialDelaySeconds: 2
periodSeconds: 5
volumeMounts:
- name: tmp
mountPath: /tmp
- name: data
mountPath: /data
volumes:
- name: tmp
emptyDir: {}
- name: data
persistentVolumeClaim:
claimName: nodejs-demo-data
ports: # 容器端口
- containerPort: 8080 # 监听端口
resources: # 资源请求与限制
requests: # 最小资源请求
cpu: "50m" # 请求 CPU
memory: "64Mi" # 请求内存
limits: # 资源上限
cpu: "500m" # CPU 限制
memory: "256Mi" # 内存限制
livenessProbe: # 存活探针
httpGet: # HTTP 探测
path: / # 探测路径
port: 8080 # 探测端口
initialDelaySeconds: 3 # 初始延迟
periodSeconds: 10 # 探测周期
readinessProbe: # 就绪探针
httpGet: # HTTP 探测
path: / # 探测路径
port: 8080 # 探测端口
initialDelaySeconds: 2 # 初始延迟
periodSeconds: 5 # 探测周期
volumeMounts: # 卷挂载
- name: tmp # 临时卷名称
mountPath: /tmp # 容器内临时目录
- name: data # 数据卷名称
mountPath: /data # 容器内数据目录
volumes: # 卷定义
- name: tmp # 临时卷
emptyDir: {} # 空目录卷
- name: data # 数据卷
persistentVolumeClaim: # 卷来源为 PVC
claimName: nodejs-demo-data # 绑定 PVC 名称
---
apiVersion: v1
kind: Service
metadata:
name: nodejs-demo
namespace: default
spec:
selector:
app: nodejs-demo
ports:
- port: 80
targetPort: 8080
apiVersion: v1 # Service API 版本
kind: Service # Service 资源
metadata: # Service 元信息
name: nodejs-demo # Service 名称
namespace: default # 命名空间
spec: # Service 规格
selector: # 选择后端 Pod
app: nodejs-demo # 选中 app=nodejs-demo
ports: # 端口映射
- port: 80 # Service 暴露端口
targetPort: 8080 # 转发到容器端口
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: nodejs-demo
namespace: default
annotations:
traefik.ingress.kubernetes.io/router.entrypoints: web
spec:
rules:
- host: app.example.local
http:
paths:
- path: /api
pathType: Prefix
backend:
service:
name: nodejs-demo
port:
number: 80
apiVersion: networking.k8s.io/v1 # Ingress API 版本
kind: Ingress # Ingress 资源
metadata: # Ingress 元信息
name: nodejs-demo # Ingress 名称
namespace: default # 命名空间
annotations: # Traefik 注解
traefik.ingress.kubernetes.io/router.entrypoints: web # 使用 web(HTTP) 入口
spec: # Ingress 规则
rules: # 规则列表
- host: app.example.local # 主机名匹配
http: # HTTP 路由
paths: # 路径列表
- path: /api # 匹配 API 路径前缀
pathType: Prefix # 前缀匹配
backend: # 后端目标
service: # 后端 Service
name: nodejs-demo # Service 名称
port: # Service 端口
number: 80 # 端口号

View File

@@ -3,138 +3,138 @@
# 应用前请先创建 TLS Secret例如
# kubectl create secret tls nodejs-demo-tls --cert=fullchain.pem --key=privkey.pem -n default
# 证书 SAN 须覆盖 app.example.local与 rules.host / tls.hosts 一致)
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: nodejs-demo-data
namespace: default
spec:
accessModes:
- ReadWriteOnce
storageClassName: local-path
resources:
requests:
storage: 1Gi
apiVersion: v1 # PVC API 版本
kind: PersistentVolumeClaim # 持久卷声明
metadata: # PVC 元信息
name: nodejs-demo-data # PVC 名称
namespace: default # 命名空间
spec: # PVC 规格
accessModes: # 访问模式
- ReadWriteOnce # RWO同一时间仅单节点挂载读写
storageClassName: local-path # 存储类
resources: # 资源请求
requests: # 配额请求
storage: 1Gi # 申请容量
---
apiVersion: v1
kind: ConfigMap
metadata:
name: nodejs-demo-config
namespace: default
data:
APP_MSG: "Hello from ConfigMap"
apiVersion: v1 # ConfigMap API 版本
kind: ConfigMap # 配置资源
metadata: # ConfigMap 元信息
name: nodejs-demo-config # ConfigMap 名称
namespace: default # 命名空间
data: # 配置键值
APP_MSG: "Hello from ConfigMap" # 示例消息内容
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nodejs-demo
namespace: default
spec:
replicas: 3
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
selector:
matchLabels:
app: nodejs-demo
template:
metadata:
labels:
app: nodejs-demo
spec:
nodeSelector:
kubernetes.io/hostname: ylc62
securityContext:
fsGroup: 1000
containers:
- name: nodejs-demo
image: node:18.20-alpine
imagePullPolicy: IfNotPresent
securityContext:
allowPrivilegeEscalation: false
runAsNonRoot: true
runAsUser: 1000
readOnlyRootFilesystem: true
env:
- name: APP_MSG
valueFrom:
configMapKeyRef:
name: nodejs-demo-config
key: APP_MSG
command:
- node
- "-e"
- |
apiVersion: apps/v1 # Deployment API 版本
kind: Deployment # 工作负载Deployment
metadata: # Deployment 元信息
name: nodejs-demo # Deployment 名称
namespace: default # 命名空间
spec: # Deployment 规格
replicas: 3 # 副本数
strategy: # 更新策略
type: RollingUpdate # 滚动更新
rollingUpdate: # 滚动更新参数
maxSurge: 1 # 更新时最多额外增加 1 个 Pod
maxUnavailable: 0 # 更新时不可用 Pod 数为 0
selector: # Pod 选择器
matchLabels: # 标签匹配集合
app: nodejs-demo # 匹配 app=nodejs-demo 的 Pod
template: # Pod 模板
metadata: # Pod 元信息
labels: # Pod 标签
app: nodejs-demo # 与 selector.matchLabels 对齐
spec: # Pod 规格
nodeSelector: # 节点选择
kubernetes.io/hostname: ylc62 # 固定到指定节点(按实际修改)
securityContext: # Pod 级安全上下文
fsGroup: 1000 # 挂载卷文件组 ID
containers: # 容器列表
- name: nodejs-demo # 容器名
image: node:18.20-alpine # Node.js 镜像
imagePullPolicy: IfNotPresent # 拉取策略
securityContext: # 容器级安全上下文
allowPrivilegeEscalation: false # 禁止提权
runAsNonRoot: true # 非 root 运行
runAsUser: 1000 # 运行用户 UID
readOnlyRootFilesystem: true # 根文件系统只读
env: # 环境变量
- name: APP_MSG # 环境变量名
valueFrom: # 从引用源取值
configMapKeyRef: # 从 ConfigMap key 读取
name: nodejs-demo-config # ConfigMap 名称
key: APP_MSG # ConfigMap 键名
command: # 启动命令
- node # 执行 node
- "-e" # 执行内联脚本
- | # 多行 JS 脚本(内容保持原样)
const http=require('http');
const msg=process.env.APP_MSG||'no env';
http.createServer((q,s)=>s.end(msg)).listen(8080);
ports:
- containerPort: 8080
resources:
requests:
cpu: "50m"
memory: "64Mi"
limits:
cpu: "500m"
memory: "256Mi"
livenessProbe:
httpGet:
path: /
port: 8080
initialDelaySeconds: 3
periodSeconds: 10
readinessProbe:
httpGet:
path: /
port: 8080
initialDelaySeconds: 2
periodSeconds: 5
volumeMounts:
- name: tmp
mountPath: /tmp
- name: data
mountPath: /data
volumes:
- name: tmp
emptyDir: {}
- name: data
persistentVolumeClaim:
claimName: nodejs-demo-data
ports: # 容器端口
- containerPort: 8080 # 监听端口
resources: # 资源请求与限制
requests: # 最小资源请求
cpu: "50m" # 请求 CPU
memory: "64Mi" # 请求内存
limits: # 资源上限
cpu: "500m" # CPU 限制
memory: "256Mi" # 内存限制
livenessProbe: # 存活探针
httpGet: # HTTP 探测
path: / # 探测路径
port: 8080 # 探测端口
initialDelaySeconds: 3 # 初始延迟
periodSeconds: 10 # 探测周期
readinessProbe: # 就绪探针
httpGet: # HTTP 探测
path: / # 探测路径
port: 8080 # 探测端口
initialDelaySeconds: 2 # 初始延迟
periodSeconds: 5 # 探测周期
volumeMounts: # 卷挂载
- name: tmp # 临时卷名称
mountPath: /tmp # 容器内临时目录
- name: data # 数据卷名称
mountPath: /data # 容器内数据目录
volumes: # 卷定义
- name: tmp # 临时卷
emptyDir: {} # 空目录卷
- name: data # 数据卷
persistentVolumeClaim: # 卷来源为 PVC
claimName: nodejs-demo-data # 绑定 PVC 名称
---
apiVersion: v1
kind: Service
metadata:
name: nodejs-demo
namespace: default
spec:
selector:
app: nodejs-demo
ports:
- port: 80
targetPort: 8080
apiVersion: v1 # Service API 版本
kind: Service # Service 资源
metadata: # Service 元信息
name: nodejs-demo # Service 名称
namespace: default # 命名空间
spec: # Service 规格
selector: # 选择后端 Pod
app: nodejs-demo # 选中 app=nodejs-demo
ports: # 端口映射
- port: 80 # Service 暴露端口
targetPort: 8080 # 转发到容器端口
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: nodejs-demo
namespace: default
annotations:
traefik.ingress.kubernetes.io/router.entrypoints: websecure
spec:
tls:
- hosts:
- app.example.local
secretName: nodejs-demo-tls
rules:
- host: app.example.local
http:
paths:
- path: /api
pathType: Prefix
backend:
service:
name: nodejs-demo
port:
number: 80
apiVersion: networking.k8s.io/v1 # Ingress API 版本
kind: Ingress # Ingress 资源
metadata: # Ingress 元信息
name: nodejs-demo # Ingress 名称
namespace: default # 命名空间
annotations: # Traefik 注解
traefik.ingress.kubernetes.io/router.entrypoints: websecure # 使用 websecure(HTTPS) 入口
spec: # Ingress 规则
tls: # TLS 配置
- hosts: # 证书覆盖域名
- app.example.local # 域名
secretName: nodejs-demo-tls # 引用的 TLS Secret 名称
rules: # 路由规则列表
- host: app.example.local # 主机名匹配
http: # HTTP 路由
paths: # 路径列表
- path: /api # 匹配 API 路径前缀
pathType: Prefix # 前缀匹配
backend: # 后端目标
service: # 后端 Service
name: nodejs-demo # Service 名称
port: # Service 端口
number: 80 # 端口号

View File

@@ -1,157 +1,157 @@
# 对应文档docs/04-13-nodejs-HPA.md
# 累积04-12 + HorizontalPodAutoscalerCPU 50%min 1 max 5
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: nodejs-demo-data
namespace: default
spec:
accessModes:
- ReadWriteOnce
storageClassName: local-path
resources:
requests:
storage: 1Gi
apiVersion: v1 # PVC API 版本
kind: PersistentVolumeClaim # 持久卷声明
metadata: # PVC 元信息
name: nodejs-demo-data # PVC 名称
namespace: default # 命名空间
spec: # PVC 规格
accessModes: # 访问模式
- ReadWriteOnce # RWO同一时间仅单节点挂载读写
storageClassName: local-path # 存储类
resources: # 资源请求
requests: # 配额请求
storage: 1Gi # 申请容量
---
apiVersion: v1
kind: ConfigMap
metadata:
name: nodejs-demo-config
namespace: default
data:
APP_MSG: "Hello from ConfigMap"
apiVersion: v1 # ConfigMap API 版本
kind: ConfigMap # 配置资源
metadata: # ConfigMap 元信息
name: nodejs-demo-config # ConfigMap 名称
namespace: default # 命名空间
data: # 配置键值
APP_MSG: "Hello from ConfigMap" # 示例消息内容
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nodejs-demo
namespace: default
spec:
replicas: 3
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
selector:
matchLabels:
app: nodejs-demo
template:
metadata:
labels:
app: nodejs-demo
spec:
nodeSelector:
kubernetes.io/hostname: ylc62
securityContext:
fsGroup: 1000
containers:
- name: nodejs-demo
image: node:18.20-alpine
imagePullPolicy: IfNotPresent
securityContext:
allowPrivilegeEscalation: false
runAsNonRoot: true
runAsUser: 1000
readOnlyRootFilesystem: true
env:
- name: APP_MSG
valueFrom:
configMapKeyRef:
name: nodejs-demo-config
key: APP_MSG
command:
- node
- "-e"
- |
apiVersion: apps/v1 # Deployment API 版本
kind: Deployment # 工作负载Deployment
metadata: # Deployment 元信息
name: nodejs-demo # Deployment 名称
namespace: default # 命名空间
spec: # Deployment 规格
replicas: 3 # 副本数
strategy: # 更新策略
type: RollingUpdate # 滚动更新
rollingUpdate: # 滚动更新参数
maxSurge: 1 # 更新时最多额外增加 1 个 Pod
maxUnavailable: 0 # 更新时不可用 Pod 数为 0
selector: # Pod 选择器
matchLabels: # 标签匹配集合
app: nodejs-demo # 匹配 app=nodejs-demo 的 Pod
template: # Pod 模板
metadata: # Pod 元信息
labels: # Pod 标签
app: nodejs-demo # 与 selector.matchLabels 对齐
spec: # Pod 规格
nodeSelector: # 节点选择
kubernetes.io/hostname: ylc62 # 固定到指定节点(按实际修改)
securityContext: # Pod 级安全上下文
fsGroup: 1000 # 挂载卷文件组 ID
containers: # 容器列表
- name: nodejs-demo # 容器名
image: node:18.20-alpine # Node.js 镜像
imagePullPolicy: IfNotPresent # 拉取策略
securityContext: # 容器级安全上下文
allowPrivilegeEscalation: false # 禁止提权
runAsNonRoot: true # 非 root 运行
runAsUser: 1000 # 运行用户 UID
readOnlyRootFilesystem: true # 根文件系统只读
env: # 环境变量
- name: APP_MSG # 环境变量名
valueFrom: # 从引用源取值
configMapKeyRef: # 从 ConfigMap key 读取
name: nodejs-demo-config # ConfigMap 名称
key: APP_MSG # ConfigMap 键名
command: # 启动命令
- node # 执行 node
- "-e" # 执行内联脚本
- | # 多行 JS 脚本(内容保持原样)
const http=require('http');
const msg=process.env.APP_MSG||'no env';
http.createServer((q,s)=>s.end(msg)).listen(8080);
ports:
- containerPort: 8080
resources:
requests:
cpu: "50m"
memory: "64Mi"
limits:
cpu: "500m"
memory: "256Mi"
livenessProbe:
httpGet:
path: /
port: 8080
initialDelaySeconds: 3
periodSeconds: 10
readinessProbe:
httpGet:
path: /
port: 8080
initialDelaySeconds: 2
periodSeconds: 5
volumeMounts:
- name: tmp
mountPath: /tmp
- name: data
mountPath: /data
volumes:
- name: tmp
emptyDir: {}
- name: data
persistentVolumeClaim:
claimName: nodejs-demo-data
ports: # 容器端口
- containerPort: 8080 # 监听端口
resources: # 资源请求与限制
requests: # 最小资源请求
cpu: "50m" # 请求 CPU
memory: "64Mi" # 请求内存
limits: # 资源上限
cpu: "500m" # CPU 限制
memory: "256Mi" # 内存限制
livenessProbe: # 存活探针
httpGet: # HTTP 探测
path: / # 探测路径
port: 8080 # 探测端口
initialDelaySeconds: 3 # 初始延迟
periodSeconds: 10 # 探测周期
readinessProbe: # 就绪探针
httpGet: # HTTP 探测
path: / # 探测路径
port: 8080 # 探测端口
initialDelaySeconds: 2 # 初始延迟
periodSeconds: 5 # 探测周期
volumeMounts: # 卷挂载
- name: tmp # 临时卷名称
mountPath: /tmp # 容器内临时目录
- name: data # 数据卷名称
mountPath: /data # 容器内数据目录
volumes: # 卷定义
- name: tmp # 临时卷
emptyDir: {} # 空目录卷
- name: data # 数据卷
persistentVolumeClaim: # 卷来源为 PVC
claimName: nodejs-demo-data # 绑定 PVC 名称
---
apiVersion: v1
kind: Service
metadata:
name: nodejs-demo
namespace: default
spec:
selector:
app: nodejs-demo
ports:
- port: 80
targetPort: 8080
apiVersion: v1 # Service API 版本
kind: Service # Service 资源
metadata: # Service 元信息
name: nodejs-demo # Service 名称
namespace: default # 命名空间
spec: # Service 规格
selector: # 选择后端 Pod
app: nodejs-demo # 选中 app=nodejs-demo
ports: # 端口映射
- port: 80 # Service 暴露端口
targetPort: 8080 # 转发到容器端口
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: nodejs-demo
namespace: default
annotations:
traefik.ingress.kubernetes.io/router.entrypoints: websecure
spec:
tls:
- hosts:
- app.example.local
secretName: nodejs-demo-tls
rules:
- host: app.example.local
http:
paths:
- path: /api
pathType: Prefix
backend:
service:
name: nodejs-demo
port:
number: 80
apiVersion: networking.k8s.io/v1 # Ingress API 版本
kind: Ingress # Ingress 资源
metadata: # Ingress 元信息
name: nodejs-demo # Ingress 名称
namespace: default # 命名空间
annotations: # Traefik 注解
traefik.ingress.kubernetes.io/router.entrypoints: websecure # 使用 websecure(HTTPS) 入口
spec: # Ingress 规则
tls: # TLS 配置
- hosts: # 证书覆盖域名
- app.example.local # 域名
secretName: nodejs-demo-tls # 引用的 TLS Secret 名称
rules: # 路由规则列表
- host: app.example.local # 主机名匹配
http: # HTTP 路由
paths: # 路径列表
- path: /api # 匹配 API 路径前缀
pathType: Prefix # 前缀匹配
backend: # 后端目标
service: # 后端 Service
name: nodejs-demo # Service 名称
port: # Service 端口
number: 80 # 端口号
---
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: nodejs-demo
namespace: default
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: nodejs-demo
minReplicas: 1
maxReplicas: 5
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 50
apiVersion: autoscaling/v2 # HPA API 版本
kind: HorizontalPodAutoscaler # 水平自动扩缩容资源
metadata: # HPA 元信息
name: nodejs-demo # HPA 名称
namespace: default # 命名空间
spec: # HPA 规格
scaleTargetRef: # 伸缩目标引用
apiVersion: apps/v1 # 目标 API 版本
kind: Deployment # 目标资源类型
name: nodejs-demo # 目标 Deployment 名称
minReplicas: 1 # 最小副本数
maxReplicas: 5 # 最大副本数
metrics: # 伸缩指标
- type: Resource # 资源指标类型
resource: # 资源指标配置
name: cpu # 指标资源CPU
target: # 目标值
type: Utilization # 目标类型:利用率
averageUtilization: 50 # 目标平均 CPU 利用率(%

View File

@@ -1,8 +1,8 @@
# 示例:勿将真实密钥提交到公开仓库。对应 docs/04-03 Secret 示意。
apiVersion: v1
kind: Secret
metadata:
name: nodejs-demo-secret
namespace: default
stringData:
API_TOKEN: "replace-me"
apiVersion: v1 # Secret API 版本
kind: Secret # 密钥资源
metadata: # Secret 元信息
name: nodejs-demo-secret # Secret 名称
namespace: default # 命名空间
stringData: # 明文键值(创建时会转换为 data
API_TOKEN: "replace-me" # 示例 token请替换勿提交真实密钥

View File

@@ -1,43 +1,43 @@
# docs/05-02-onenav首页面板.md — 修改 Endpoints IP 与 Ingress host
apiVersion: v1
kind: Service
metadata:
name: onenav-external
namespace: default
spec:
ports:
- name: http
port: 80
targetPort: 7070
apiVersion: v1 # Service/Endpoints 使用的核心 API 版本
kind: Service # 资源类型Service为外部后端提供集群内服务名
metadata: # Service 元信息
name: onenav-external # Service 名称(与 Endpoints 同名以进行绑定)
namespace: default # 命名空间
spec: # Service 规格
ports: # 端口映射列表
- name: http # 端口名称
port: 80 # Service 对内暴露端口
targetPort: 7070 # 目标端口(与 Endpoints 端口对应)
---
apiVersion: v1
kind: Endpoints
metadata:
name: onenav-external
namespace: default
subsets:
- addresses:
- ip: 192.168.2.22
ports:
- port: 7070
name: http
apiVersion: v1 # Endpoints 使用的核心 API 版本
kind: Endpoints # 资源类型:手工定义后端地址
metadata: # Endpoints 元信息
name: onenav-external # 必须与 Service 同名Service 才会路由到这些地址
namespace: default # 命名空间
subsets: # 后端地址与端口集合
- addresses: # 地址列表
- ip: 192.168.2.22 # 实际后端主机 IP按环境修改
ports: # 端口列表
- port: 7070 # 后端服务真实端口
name: http # 端口名称(与 Service 端口名保持一致更清晰)
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: onenav
namespace: default
annotations:
traefik.ingress.kubernetes.io/router.entrypoints: web
spec:
rules:
- host: onenav.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: onenav-external
port:
number: 80
apiVersion: networking.k8s.io/v1 # Ingress API 版本
kind: Ingress # 资源类型:入口路由
metadata: # Ingress 元信息
name: onenav # Ingress 名称
namespace: default # 命名空间
annotations: # 控制器注解
traefik.ingress.kubernetes.io/router.entrypoints: web # 使用 Traefik 的 web(HTTP) 入口
spec: # Ingress 规则
rules: # 规则列表
- host: onenav.example.com # 访问域名(按环境修改)
http: # HTTP 规则
paths: # 路径列表
- path: / # 匹配根路径
pathType: Prefix # 前缀匹配
backend: # 后端目标
service: # 转发到 Service
name: onenav-external # 后端 Service 名称
port: # 后端端口
number: 80 # Service 端口

View File

@@ -1,74 +1,74 @@
# docs/05-08-openclaw-k3s-实验部署.md — 实验用;替换镜像与域名
apiVersion: v1
kind: Namespace
metadata:
name: openclaw
apiVersion: v1 # Namespace 使用的核心 API 版本
kind: Namespace # 资源类型:命名空间
metadata: # Namespace 元信息
name: openclaw # 命名空间名称
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: openclaw-gateway
namespace: openclaw
spec:
replicas: 1
selector:
matchLabels:
app: openclaw-gateway
template:
metadata:
labels:
app: openclaw-gateway
spec:
containers:
- name: openclaw-gateway
image: registry.local/openclaw:local
imagePullPolicy: IfNotPresent
env:
- name: OPENCLAW_GATEWAY_MODE
value: "local"
ports:
- containerPort: 18789
volumeMounts:
- name: config
mountPath: /home/node/.openclaw
- name: workspace
mountPath: /home/node/.openclaw/workspace
volumes:
- name: config
emptyDir: {}
- name: workspace
emptyDir: {}
apiVersion: apps/v1 # Deployment 使用的 API 版本
kind: Deployment # 工作负载Deployment
metadata: # Deployment 元信息
name: openclaw-gateway # Deployment 名称
namespace: openclaw # 所在命名空间
spec: # Deployment 规格
replicas: 1 # 副本数
selector: # 选择器
matchLabels: # 标签匹配
app: openclaw-gateway # 匹配标签 app=openclaw-gateway
template: # Pod 模板
metadata: # Pod 元信息
labels: # Pod 标签
app: openclaw-gateway # 与 selector 匹配
spec: # Pod 规格
containers: # 容器列表
- name: openclaw-gateway # 容器名
image: registry.local/openclaw:local # 容器镜像(按环境替换)
imagePullPolicy: IfNotPresent # 拉取策略:本地有镜像则不重复拉取
env: # 环境变量
- name: OPENCLAW_GATEWAY_MODE # 运行模式变量名
value: "local" # 运行模式值
ports: # 容器端口
- containerPort: 18789 # 网关监听端口
volumeMounts: # 卷挂载
- name: config # 配置卷
mountPath: /home/node/.openclaw # 配置目录挂载点
- name: workspace # 工作目录卷
mountPath: /home/node/.openclaw/workspace # 工作目录挂载点
volumes: # 卷定义
- name: config # 配置卷名
emptyDir: {} # 临时卷Pod 生命周期内)
- name: workspace # 工作目录卷名
emptyDir: {} # 临时卷Pod 生命周期内)
---
apiVersion: v1
kind: Service
metadata:
name: openclaw-gateway
namespace: openclaw
spec:
selector:
app: openclaw-gateway
ports:
- port: 18789
targetPort: 18789
protocol: TCP
name: http
apiVersion: v1 # Service 使用的核心 API 版本
kind: Service # Service 资源
metadata: # Service 元信息
name: openclaw-gateway # Service 名称
namespace: openclaw # 命名空间
spec: # Service 规格
selector: # 后端 Pod 选择器
app: openclaw-gateway # 选择 app=openclaw-gateway 的 Pod
ports: # 端口映射列表
- port: 18789 # Service 暴露端口
targetPort: 18789 # 转发到容器端口
protocol: TCP # 协议
name: http # 端口名
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: openclaw-gateway
namespace: openclaw
annotations:
traefik.ingress.kubernetes.io/router.entrypoints: web
spec:
rules:
- host: openclaw-k3s.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: openclaw-gateway
port:
number: 18789
apiVersion: networking.k8s.io/v1 # Ingress API 版本
kind: Ingress # 入口路由资源
metadata: # Ingress 元信息
name: openclaw-gateway # Ingress 名称
namespace: openclaw # 命名空间
annotations: # 控制器注解
traefik.ingress.kubernetes.io/router.entrypoints: web # 使用 Traefik web(HTTP) 入口
spec: # Ingress 规则
rules: # 规则列表
- host: openclaw-k3s.example.com # 访问域名(按环境修改)
http: # HTTP 规则
paths: # 路径列表
- path: / # 根路径
pathType: Prefix # 前缀匹配
backend: # 后端目标
service: # 后端 Service
name: openclaw-gateway # Service 名称
port: # Service 端口
number: 18789 # 端口号

View File

@@ -1,43 +1,43 @@
# docs/05-07-openclaw应用部署.md — 修改 IP / host
apiVersion: v1
kind: Service
metadata:
name: openclaw-external
namespace: default
spec:
ports:
- name: http
port: 80
targetPort: 18789
apiVersion: v1 # Service/Endpoints 使用的核心 API 版本
kind: Service # 资源类型Service对外部后端提供集群内服务名
metadata: # Service 元信息
name: openclaw-external # Service 名称(需与 Endpoints 同名)
namespace: default # 命名空间
spec: # Service 规格
ports: # 端口映射列表
- name: http # 端口名称
port: 80 # Service 暴露端口
targetPort: 18789 # 目标端口(与 Endpoints 端口对应)
---
apiVersion: v1
kind: Endpoints
metadata:
name: openclaw-external
namespace: default
subsets:
- addresses:
- ip: 192.168.2.70
ports:
- port: 18789
name: http
apiVersion: v1 # Endpoints 使用的核心 API 版本
kind: Endpoints # 资源类型:手工定义后端地址
metadata: # Endpoints 元信息
name: openclaw-external # 必须与 Service 同名才能绑定
namespace: default # 命名空间
subsets: # 后端地址与端口集合
- addresses: # 地址列表
- ip: 192.168.2.70 # 外部后端 IP按环境修改
ports: # 端口列表
- port: 18789 # 外部后端真实端口
name: http # 端口名
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: openclaw
namespace: default
annotations:
traefik.ingress.kubernetes.io/router.entrypoints: web
spec:
rules:
- host: openclaw.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: openclaw-external
port:
number: 80
apiVersion: networking.k8s.io/v1 # Ingress API 版本
kind: Ingress # 入口资源:域名/路径转发
metadata: # Ingress 元信息
name: openclaw # Ingress 名称
namespace: default # 命名空间
annotations: # Traefik 注解
traefik.ingress.kubernetes.io/router.entrypoints: web # 使用 web(HTTP) 入口
spec: # Ingress 规则
rules: # 规则列表
- host: openclaw.example.com # 访问域名(按环境修改)
http: # HTTP 规则
paths: # 路径列表
- path: / # 根路径
pathType: Prefix # 前缀匹配
backend: # 后端目标
service: # 后端 Service
name: openclaw-external # Service 名称
port: # Service 端口
number: 80 # 端口号

View File

@@ -1,27 +1,27 @@
# docs/06-03-k3s-自动备份与恢复-openlist-webdav.md — 替换镜像、hostPath、远端名
apiVersion: batch/v1
kind: CronJob
metadata:
name: app-data-backup
namespace: default
spec:
schedule: "0 3 * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: app-data-backup
image: your-registry/app-backup:latest
args:
- /bin/sh
- -c
- rclone sync /data openlist-webdav:backups/app-data
volumeMounts:
- name: app-data
mountPath: /data
volumes:
- name: app-data
hostPath:
path: /data/app
restartPolicy: OnFailure
apiVersion: batch/v1 # CronJob API 版本
kind: CronJob # 定时任务资源
metadata: # CronJob 元信息
name: app-data-backup # CronJob 名称
namespace: default # 命名空间
spec: # CronJob 规格
schedule: "0 3 * * *" # 执行计划:每天 03:00
jobTemplate: # 每次触发创建的 Job 模板
spec: # Job 规格
template: # Pod 模板
spec: # Pod 规格
containers: # 容器列表
- name: app-data-backup # 容器名
image: your-registry/app-backup:latest # 备份镜像(按环境替换)
args: # 启动参数
- /bin/sh # 使用 shell 执行
- -c # shell 执行模式
- rclone sync /data openlist-webdav:backups/app-data # 同步本地目录到远端备份
volumeMounts: # 卷挂载
- name: app-data # 引用卷名
mountPath: /data # 容器内数据目录
volumes: # 卷定义
- name: app-data # 卷名
hostPath: # 使用宿主机路径
path: /data/app # 宿主机实际目录(按环境修改)
restartPolicy: OnFailure # 失败时重启

View File

@@ -1,24 +1,24 @@
# docs/06-03-k3s-自动备份与恢复-openlist-webdav.md — 一次性恢复 Job
apiVersion: batch/v1
kind: Job
metadata:
name: app-data-restore
namespace: default
spec:
template:
spec:
containers:
- name: app-data-restore
image: your-registry/app-backup:latest
args:
- /bin/sh
- -c
- rclone sync openlist-webdav:backups/app-data /data
volumeMounts:
- name: app-data
mountPath: /data
volumes:
- name: app-data
hostPath:
path: /data/app
restartPolicy: OnFailure
apiVersion: batch/v1 # Job 使用的 API 版本
kind: Job # 一次性任务资源
metadata: # Job 元信息
name: app-data-restore # Job 名称
namespace: default # 命名空间
spec: # Job 规格
template: # Pod 模板
spec: # Pod 规格
containers: # 容器列表
- name: app-data-restore # 容器名
image: your-registry/app-backup:latest # 恢复镜像(按环境替换)
args: # 启动参数
- /bin/sh # 使用 shell 运行命令
- -c # shell 执行模式
- rclone sync openlist-webdav:backups/app-data /data # 从远端同步备份到本地目录
volumeMounts: # 卷挂载
- name: app-data # 引用 volumes[].name
mountPath: /data # 容器内恢复目标路径
volumes: # 卷定义
- name: app-data # 卷名
hostPath: # 使用宿主机目录作为存储
path: /data/app # 节点上的真实数据目录(按实际修改)
restartPolicy: OnFailure # 失败时重启,成功后结束

View File

@@ -1,27 +1,27 @@
# docs/05-06-openlist挂载网盘与自动备份.md — 替换镜像与 PVC 名
apiVersion: batch/v1
kind: CronJob
metadata:
name: openlist-backup
namespace: default
spec:
schedule: "0 3 * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: openlist-backup
image: your-registry/openlist-backup:latest
args:
- /bin/sh
- -c
- /backup.sh
volumeMounts:
- name: backup-target
mountPath: /backup
volumes:
- name: backup-target
persistentVolumeClaim:
claimName: openlist-backup-pvc
restartPolicy: OnFailure
apiVersion: batch/v1 # CronJob 所属 APIbatch/v1
kind: CronJob # 定时任务CronJob
metadata: # 资源元信息
name: openlist-backup # CronJob 名称
namespace: default # CronJob 所在命名空间
spec: # CronJob 期望状态
schedule: "0 3 * * *" # 任务调度:每天 03:00cron 格式)
jobTemplate: # 每次触发生成的 Job 模板
spec: # Job spec
template: # Job Pod 模板
spec: # Pod spec
containers: # 容器列表
- name: openlist-backup # 容器名
image: your-registry/openlist-backup:latest # 镜像(需替换为你的镜像)
args: # 容器启动命令参数
- /bin/sh # 使用 shell
- -c # shell 执行模式
- /backup.sh # 运行脚本
volumeMounts: # 挂载卷
- name: backup-target # 引用 volumes[].name
mountPath: /backup # 容器内挂载目录
volumes: # 卷列表
- name: backup-target # 卷名(与 volumeMounts 对齐)
persistentVolumeClaim: # 使用 PVC 作为存储来源
claimName: openlist-backup-pvc # 绑定的 PVC 名称(需保证存在)
restartPolicy: OnFailure # Pod 失败后重启策略:仅失败时重启

View File

@@ -2,37 +2,39 @@
# 含ACMECloudflare DNS-01、ping 健康检查websecure、PROXY protocol trustedIPs
# 使用前:替换 <YOUR_REAL_EMAIL>,创建 cloudflare-api-token Secret按实际修改 nodeSelector/trustedIPs
# 部署kubectl apply -f traefik-acme.yaml或复制到 K3s manifests 目录)
#
# 推荐Dashboard + ACME + local-path 一份清单):见 ../traefik-dashboard-acme/traefik-dashboard-acme.yaml
---
apiVersion: helm.cattle.io/v1
kind: HelmChartConfig
metadata:
name: traefik
namespace: kube-system
spec:
valuesContent: |-
additionalArguments:
- "--log.level=INFO"
- "--certificatesresolvers.cloudflare.acme.dnschallenge.resolvers=1.1.1.1:53,1.0.0.1:53"
- "--certificatesresolvers.cloudflare.acme.email=<YOUR_REAL_EMAIL>"
- "--certificatesresolvers.cloudflare.acme.storage=/data/acme.json"
apiVersion: helm.cattle.io/v1 # HelmChartConfig 所在的 API 版本
kind: HelmChartConfig # HelmChartConfig给 K3s 自带 Helm chart 注入 values 的资源
metadata: # 该对象的标识信息
name: traefik # chart 对应的对象名称(通常与 Traefik chart name 一致)
namespace: kube-system # HelmChartConfig 的命名空间Traefik 默认在 kube-system
spec: # chart 注入配置的具体内容
valuesContent: |- # 以“字符串形式的 YAML”注入到 Helm chart values由 chart 解析)
additionalArguments: # 追加给 Traefik 的额外启动参数列表
- "--log.level=INFO" # 日志级别INFO
- "--certificatesresolvers.cloudflare.acme.dnschallenge.resolvers=1.1.1.1:53,1.0.0.1:53" # DNS resolver 列表
- "--certificatesresolvers.cloudflare.acme.email=<YOUR_REAL_EMAIL>" # ACME 注册邮箱
- "--certificatesresolvers.cloudflare.acme.storage=/data/acme.json" # ACME 存储(容器内路径)
# - "--certificatesresolvers.cloudflare.acme.caserver=https://acme-staging-v02.api.letsencrypt.org/directory" # 测试用,上线前删除
- "--certificatesresolvers.cloudflare.acme.dnschallenge.provider=cloudflare"
- "--certificatesresolvers.cloudflare.acme.dnschallenge.propagation.delayBeforeChecks=600"
- "--certificatesresolvers.cloudflare.acme.dnschallenge.provider=cloudflare" # 使用 Cloudflare 作为 DNS-01 provider
- "--certificatesresolvers.cloudflare.acme.dnschallenge.propagation.delayBeforeChecks=600" # DNS propagation 等待时间(秒)
# 健康检查GET /ping 在 443(HTTPS) 返回 200供 HAProxy 对 443 做 option httpchk + ssl
- "--ping=true"
- "--ping.entryPoint=websecure"
- "--ping=true" # 开启 ping healthcheck
- "--ping.entryPoint=websecure" # ping 走 websecure(HTTPS) entrypoint
# PROXY protocoltrustedIPs 需包含 HAProxy 所在 IP/网段
- "--entrypoints.web.proxyProtocol.trustedIPs=192.168.2.0/24"
- "--entrypoints.websecure.proxyProtocol.trustedIPs=192.168.2.0/24"
- "--entrypoints.web.proxyProtocol.trustedIPs=192.168.2.0/24" # HTTP entrypoint 信任的代理网段
- "--entrypoints.websecure.proxyProtocol.trustedIPs=192.168.2.0/24" # HTTPS entrypoint 信任的代理网段
env:
- name: CF_DNS_API_TOKEN
valueFrom:
secretKeyRef:
name: cloudflare-api-token
key: api-token
env: # 环境变量注入(给 Traefik chart
- name: CF_DNS_API_TOKEN # Cloudflare API Token 环境变量名
valueFrom: # 从 Secret 中读取环境变量值
secretKeyRef: # Secret 引用方式:按 key 取值
name: cloudflare-api-token # Secret 名称(你创建的 Cloudflare Token Secret
key: api-token # Secret 内对应的 key 名
nodeSelector:
kubernetes.io/hostname: ylc61
nodeSelector: # 把 Traefik Pod 固定到指定节点(配合 RWO 本地存储更安全)
kubernetes.io/hostname: ylc61 # 固定节点主机名(按你的实际节点修改)

View File

@@ -1,25 +1,25 @@
---
apiVersion: helm.cattle.io/v1
kind: HelmChartConfig
metadata:
name: traefik
namespace: kube-system
spec:
valuesContent: |-
ports:
web:
expose: true
websecure:
expose: true
apiVersion: helm.cattle.io/v1 # HelmChartConfig 所在的 API 版本
kind: HelmChartConfig # HelmChartConfig用于给 Traefik chart 注入 values
metadata: # 资源标识
name: traefik # chart 对应的 name通常与 Traefik chart 一致)
namespace: kube-system # Traefik chart 运行的命名空间
spec: # 注入 Helm chart 的具体配置
valuesContent: |- # “字符串形式的 YAML”注入到 Helm values由 chart 解析)
ports: # Traefik entrypoints/端口暴露配置
web: # 内置 HTTP entrypoint
expose: true # 启用 web entrypoint 暴露
websecure: # 内置 HTTPS entrypoint
expose: true # 启用 websecure entrypoint 暴露
# 自定义 HTTP 入口(示例 18080
web18080:
port: 18080
expose:
default: true
exposedPort: 18080
web18080: # 自定义 HTTP entrypoint 名称(示例)
port: 18080 # entrypoint 监听端口(容器端)
expose: # 对外暴露配置
default: true # 默认启用暴露
exposedPort: 18080 # 对外映射端口
# 自定义 HTTPS 入口(示例 18443
websecure18443:
port: 18443
expose:
default: true
exposedPort: 18443
websecure18443: # 自定义 HTTPS entrypoint 名称(示例)
port: 18443 # entrypoint 监听端口(容器端)
expose: # 对外暴露配置
default: true # 默认启用暴露
exposedPort: 18443 # 对外映射端口

View File

@@ -1,94 +1,94 @@
# docs/03-03 第 5 节Tomcat + test05.jackadam.top 验证 HTTPS请按需改域名
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: tomcat-test05
namespace: default
labels:
app: tomcat-test05
spec:
replicas: 1
selector:
matchLabels:
app: tomcat-test05
template:
metadata:
labels:
app: tomcat-test05
spec:
containers:
- name: tomcat
image: tomcat:9.0
apiVersion: apps/v1 # Deployment API 版本
kind: Deployment # 工作负载Deployment
metadata: # Deployment 元信息
name: tomcat-test05 # Deployment 名称
namespace: default # 命名空间
labels: # 标签
app: tomcat-test05 # 应用标签
spec: # Deployment 规格
replicas: 1 # 副本数
selector: # Deployment 选择器
matchLabels: # 标签匹配集合
app: tomcat-test05 # 与模板标签对齐
template: # Pod 模板
metadata: # Pod 元信息
labels: # Pod 标签
app: tomcat-test05 # 与 selector.matchLabels 对齐
spec: # Pod 规格
containers: # 容器列表
- name: tomcat # 容器名
image: tomcat:9.0 # Tomcat 镜像版本
# 官方镜像默认 webapps 在 webapps.dist整目录复制到 webapps与 Docker Compose cp -a webapps.dist/* webapps 等价)
command:
- sh
- -c
- |
command: # 启动命令(覆盖默认 ENTRYPOINT/CMD
- sh # 使用 shell
- -c # shell 执行模式
- | # 多行脚本(内部内容保持原样)
set -e
CATALINA_HOME=/usr/local/tomcat
mkdir -p "${CATALINA_HOME}/webapps"
cp -a "${CATALINA_HOME}/webapps.dist/." "${CATALINA_HOME}/webapps/"
exec "${CATALINA_HOME}/bin/catalina.sh" run
ports:
- containerPort: 8080
ports: # 容器端口
- containerPort: 8080 # Tomcat HTTP 端口
---
apiVersion: v1
kind: Service
metadata:
name: tomcat-test05
namespace: default
spec:
selector:
app: tomcat-test05
ports:
- port: 8080
targetPort: 8080
apiVersion: v1 # Service API 版本
kind: Service # Service 资源
metadata: # Service 元信息
name: tomcat-test05 # Service 名称
namespace: default # 命名空间
spec: # Service 规格
selector: # 后端 Pod 选择器
app: tomcat-test05 # 选中 app=tomcat-test05 的 Pod
ports: # 端口映射
- port: 8080 # Service 暴露端口
targetPort: 8080 # 转发到容器端口
---
# HTTPSwebsecure
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: tomcat-test05-acme
namespace: default
annotations:
traefik.ingress.kubernetes.io/router.entrypoints: websecure
traefik.ingress.kubernetes.io/router.tls.certresolver: cloudflare
spec:
ingressClassName: traefik
tls:
- hosts:
- test05.jackadam.top
rules:
- host: test05.jackadam.top
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: tomcat-test05
port:
number: 8080
apiVersion: networking.k8s.io/v1 # Ingress API 版本
kind: Ingress # Ingress 资源HTTPS
metadata: # Ingress 元信息
name: tomcat-test05-acme # HTTPS Ingress 名称
namespace: default # 命名空间
annotations: # Traefik 注解
traefik.ingress.kubernetes.io/router.entrypoints: websecure # 使用 HTTPS 入口
traefik.ingress.kubernetes.io/router.tls.certresolver: cloudflare # 使用 Cloudflare certresolver
spec: # Ingress 规则
ingressClassName: traefik # 指定 IngressClass
tls: # TLS 配置
- hosts: # 证书覆盖域名
- test05.jackadam.top # 域名
rules: # 路由规则
- host: test05.jackadam.top # 主机匹配
http: # HTTP 路由定义
paths: # 路径列表
- path: / # 根路径
pathType: Prefix # 前缀匹配
backend: # 后端目标
service: # 后端 Service
name: tomcat-test05 # Service 名称
port: # Service 端口
number: 8080 # 端口号
---
# HTTPweb与 03-02 nginx-matrix-tls 一致:拆成两个 Ingress
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: tomcat-test05-http
namespace: default
annotations:
traefik.ingress.kubernetes.io/router.entrypoints: web
spec:
ingressClassName: traefik
rules:
- host: test05.jackadam.top
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: tomcat-test05
port:
number: 8080
apiVersion: networking.k8s.io/v1 # Ingress API 版本
kind: Ingress # Ingress 资源HTTP
metadata: # Ingress 元信息
name: tomcat-test05-http # HTTP Ingress 名称
namespace: default # 命名空间
annotations: # Traefik 注解
traefik.ingress.kubernetes.io/router.entrypoints: web # 使用 HTTP 入口
spec: # Ingress 规则
ingressClassName: traefik # 指定 IngressClass
rules: # 路由规则
- host: test05.jackadam.top # 主机匹配
http: # HTTP 路由定义
paths: # 路径列表
- path: / # 根路径
pathType: Prefix # 前缀匹配
backend: # 后端目标
service: # 后端 Service
name: tomcat-test05 # Service 名称
port: # Service 端口
number: 8080 # 端口号

View File

@@ -1,62 +1,83 @@
# 03-03 Traefik Dashboard + ACME 合并配置HelmChartConfig
# Dashboard、ACMECloudflare DNS-01、ping、PROXY protocol与 03-02 一致)
# 使用前:替换 <YOUR_REAL_EMAIL>,创建 cloudflare-api-token Secret按实际修改 nodeSelector/trustedIPs
# 部署kubectl apply -f traefik-dashboard-acme.yaml
# 03-03 Traefik Dashboard + ACME(唯一清单,推荐
# =============================================================================
# HelmChartConfiglocal-path 持久化 /data + ACME Cloudflare DNS-01 + Dashboard
# + IngressRoute/dashboard、/api
# acme.json 与 chart persistence 均落在 /dataPod 重建后证书仍在nodeSelector 须固定单节点RWO
#
# 部署kubectl apply -f ansible/files/traefik-dashboard-acme/traefik-dashboard-acme.yaml
# 使用前:替换 <YOUR_REAL_EMAIL>、nodeSelector 主机名Secret cloudflare-api-token 已存在(见 03-02
# 全集群只能有一份 HelmChartConfig metadata.name=traefik
#
# --- 不要 Dashboard 时 ---
# 删除文末 IngressRoute 整段;并在 valuesContent 中删掉 ports可选、--api.dashboard、--api.insecure
#
# --- 临时不用持久化(不推荐)---
# 将 persistence.enabled 改为 false 并删掉 persistence 下其余字段(证书可能随 Pod 丢失)
# =============================================================================
---
apiVersion: helm.cattle.io/v1
kind: HelmChartConfig
metadata:
name: traefik
namespace: kube-system
spec:
valuesContent: |-
ports:
web:
expose: true
websecure:
expose: true
apiVersion: helm.cattle.io/v1 # HelmChartConfig 所在的 API 版本
kind: HelmChartConfig # HelmChartConfig给 K3s/Helm 注入 values 的资源
metadata: # 资源标识信息
name: traefik # chart 对应的 name需要与 Traefik chart/约定一致)
namespace: kube-system # Traefik 通常运行在 kube-system
spec: # 该资源要注入 chart 的配置
valuesContent: |- # 以“字符串形式的 YAML”注入到 Helm chart values由 chart 解析)
ports: # 暴露 entrypoints 给集群入口
web: # HTTP entrypoint
expose: true # 允许暴露 web
websecure: # HTTPS entrypoint
expose: true # 允许暴露 websecure
additionalArguments:
- "--api.dashboard=true"
- "--api.insecure=true"
persistence: # chart 持久化配置:为 /data 挂载 PVC
enabled: true # 开启持久卷
name: data # chart 创建/引用的卷名PVC 等)
accessMode: ReadWriteOnce # RWO同一时间只能在一个节点挂载
size: 512Mi # 请求容量local-path 会据此创建本地卷)
storageClass: local-path # 使用 K3s 的 local-path-provisioner
path: /data # 容器内挂载目录(与 acme.storage 一致)
- "--log.level=INFO"
- "--certificatesresolvers.cloudflare.acme.dnschallenge.resolvers=1.1.1.1:53,1.0.0.1:53"
- "--certificatesresolvers.cloudflare.acme.email=<YOUR_REAL_EMAIL>"
- "--certificatesresolvers.cloudflare.acme.storage=/data/acme.json"
additionalArguments: # 额外传给 Traefik 的 CLI 参数
- "--api.dashboard=true" # 打开 dashboard 功能
- "--api.insecure=true" # k8s允许 dashboard 在入口可用(注意安全)
- "--log.level=INFO" # 日志级别
- "--certificatesresolvers.cloudflare.acme.dnschallenge.resolvers=1.1.1.1:53,1.0.0.1:53" # DNS 解析器列表(用于 DNS-01
- "--certificatesresolvers.cloudflare.acme.email=<YOUR_REAL_EMAIL>" # ACME 注册邮箱
- "--certificatesresolvers.cloudflare.acme.storage=/data/acme.json" # 证书与账户存储(容器内 /data
# - "--certificatesresolvers.cloudflare.acme.caserver=https://acme-staging-v02.api.letsencrypt.org/directory" # 测试用,上线前删除
- "--certificatesresolvers.cloudflare.acme.dnschallenge.provider=cloudflare"
- "--certificatesresolvers.cloudflare.acme.dnschallenge.propagation.delayBeforeChecks=600"
- "--certificatesresolvers.cloudflare.acme.dnschallenge.provider=cloudflare" # DNS-01 providercloudflare
- "--certificatesresolvers.cloudflare.acme.dnschallenge.propagation.delayBeforeChecks=600" # DNS-01 propagation 等待秒数
- "--ping=true"
- "--ping.entryPoint=websecure"
- "--ping=true" # 开启 ping healthcheck
- "--ping.entryPoint=websecure" # ping 使用 websecure(HTTPS) entrypoint
- "--entrypoints.web.proxyProtocol.trustedIPs=192.168.2.0/24"
- "--entrypoints.websecure.proxyProtocol.trustedIPs=192.168.2.0/24"
- "--entrypoints.web.proxyProtocol.trustedIPs=192.168.2.0/24" # web entrypoint 信任的代理网段
- "--entrypoints.websecure.proxyProtocol.trustedIPs=192.168.2.0/24" # websecure entrypoint 信任的代理网段
env:
- name: CF_DNS_API_TOKEN
valueFrom:
secretKeyRef:
name: cloudflare-api-token
key: api-token
env: # 环境变量注入
- name: CF_DNS_API_TOKEN # 供 Traefik 使用的 Cloudflare Token 环境变量名
valueFrom: # 从 Secret 挂载
secretKeyRef: # Secret 引用方式
name: cloudflare-api-token # Secret 名
key: api-token # Secret 内 key
nodeSelector:
kubernetes.io/hostname: ylc61
nodeSelector: # 将 Traefik Pod 固定到指定节点(避免 local-path RWO 迁移导致丢数据)
kubernetes.io/hostname: ylc61 # 目标节点主机名
---
# 显式 IngressRoute与 03-01 一致,确保 /dashboard 可达; Helm ingressRoute.dashboard 在 K3s chart 中未必生效)
apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
name: traefik-dashboard
namespace: kube-system
spec:
entryPoints:
- web
routes:
- match: PathPrefix(`/dashboard`) || PathPrefix(`/api`)
kind: Rule
services:
- name: api@internal
kind: TraefikService
apiVersion: traefik.io/v1alpha1 # IngressRoute API 版本
kind: IngressRoute # Traefik 路由 CRD
metadata: # IngressRoute 元信息
name: traefik-dashboard # 路由名称
namespace: kube-system # 命名空间
spec: # IngressRoute 规则
entryPoints: # 入口点列表
- web # 使用 web(HTTP) 入口
routes: # 路由规则列表
- match: PathPrefix(`/dashboard`) || PathPrefix(`/api`) # 匹配 Dashboard/API 路径前缀
kind: Rule # 规则类型
services: # 后端服务
- name: api@internal # Traefik 内置 API 服务
kind: TraefikService # 服务类型

View File

@@ -1,37 +1,37 @@
# 03-01 Traefik DashboardHelmChartConfig + IngressRoute
# 部署kubectl apply -f traefik-dashboard.yaml或复制到 K3s server/manifests/
---
apiVersion: helm.cattle.io/v1
kind: HelmChartConfig
metadata:
name: traefik
namespace: kube-system
spec:
valuesContent: |-
ports:
web:
expose: true
websecure:
expose: true
traefik:
expose: true
apiVersion: helm.cattle.io/v1 # HelmChartConfig 所在的 API 版本
kind: HelmChartConfig # HelmChartConfig给 K3s/Traefik chart 注入 values
metadata: # 该资源标识
name: traefik # chart 对应的对象名
namespace: kube-system # HelmChartConfig 所在命名空间
spec: # Helm 注入配置
valuesContent: |- # 以“字符串形式的 YAML”注入到 chart values由 chart 解析)
ports: # entrypoint/端口暴露相关配置
web: # HTTP entrypoint
expose: true # 启用 web 暴露
websecure: # HTTPS entrypoint
expose: true # 启用 websecure 暴露
traefik: #chart 内部traefik dashboard/管理端口暴露(按 chart 约定)
expose: true # 启用 traefik 管理端口暴露
additionalArguments:
- "--api.dashboard=true"
- "--api.insecure=true"
additionalArguments: # 额外传给 Traefik 的 CLI 参数
- "--api.dashboard=true" # 开启 dashboard 功能
- "--api.insecure=true" # 允许 dashboard 在入口可用(不建议在公网直接放行)
---
apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
name: traefik-dashboard
namespace: kube-system
spec:
entryPoints:
- web
routes:
- match: PathPrefix(`/dashboard`) || PathPrefix(`/api`)
kind: Rule
services:
- name: api@internal
kind: TraefikService
apiVersion: traefik.io/v1alpha1 # IngressRoute 的 API 版本
kind: IngressRoute # Traefik 的路由 CRD
metadata: # IngressRoute 标识
name: traefik-dashboard # 资源名
namespace: kube-system # IngressRoute 所在命名空间
spec: # 路由规则
entryPoints: # 进入的 entrypoint
- web # 使用 webHTTP入口
routes: # 路由列表
- match: PathPrefix(`/dashboard`) || PathPrefix(`/api`) # 匹配 /dashboard 或 /api 前缀
kind: Rule # 匹配规则类型Rule
services: # 匹配到后转发给的服务列表
- name: api@internal # Traefik 内置 API 服务
kind: TraefikService # 该服务的 CRD 类型