# docs/05-01-k3s-部署homer首页面板.md — 按需修改 host 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 # 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 # 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 路由使用的 entrypoint(HTTP) spec: # Ingress 规则 rules: # 主机/路径规则列表 - host: home.example.com # 要匹配的域名(按需修改) http: # HTTP 路由规则 paths: # 路径匹配列表 - path: / # 匹配根路径及其子路径 pathType: Prefix # Prefix 表示前缀匹配 backend: # 匹配到后端目标 service: # 使用 Service 作为后端 name: homer # 后端 Service 名称 port: # 后端端口配置 number: 80 # 后端 Service 端口