Files
Deploy-Laboratory/docs/03-10-k3s-traefik-custom-ports.md
jack 8c43761962 feat: 按 doc_id 重组 ansible/files 与验证框架
- ansible/files 改为与文档 XX-YY 对齐的目录结构,更新相关 playbook 路径
- 新增 scripts/verify.sh 与 ansible/playbooks/verify/*.yml,移除单体 verify-matrix.yml
- 补充 docs/00-02 矩阵状态、00-05 验证框架与流程、00-04 环境与 ylc65 工作机说明
- 增加 k3s 存储准备、Longhorn、local-path 等 playbook 与辅助脚本

Made-with: Cursor
2026-03-26 07:01:14 +08:00

54 lines
2.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 03-10-k3s-traefik-custom-ports
> 为 K3s 内置 Traefik 增加 **自定义 entrypoints**(额外暴露端口),用于多入口/旁路调试/特定设备转发等场景。
## 前置条件
- 已完成 `01-01-k3s-控制节点含traefik.md`,集群内 `kube-system` 命名空间的 Traefik 正常运行。
- 了解 Traefik 的 entrypoints 概念(`web`/`websecure`)。
## 清单路径(唯一真源)
| 项 | 路径 |
|----|------|
| Traefik 自定义端口HelmChartConfig | [`ansible/files/03-10-traefik-custom-ports/traefik-custom-ports.yaml`](../ansible/files/03-10-traefik-custom-ports/traefik-custom-ports.yaml) |
| 应用 | `kubectl apply -f ansible/files/03-10-traefik-custom-ports/traefik-custom-ports.yaml` |
| 删除 | `kubectl delete -f ansible/files/03-10-traefik-custom-ports/traefik-custom-ports.yaml` |
## 做了什么
该清单通过 `HelmChartConfig` 给 K3s 内置 Traefik 注入 values新增两个示例入口
- `web18080`HTTP 端口 `18080`
- `websecure18443`HTTPS 端口 `18443`
你可以按需要改 entrypoint 名称与端口号。
## 部署与验证
```bash
kubectl apply -f ansible/files/03-10-traefik-custom-ports/traefik-custom-ports.yaml
# 等待 Traefik 重载(可能触发 rollout
kubectl -n kube-system rollout status deploy/traefik --timeout=180s
# 验证 Service 端口是否暴露(不同版本/安装方式字段略有差异,以输出为准)
kubectl -n kube-system get svc traefik -o wide
kubectl -n kube-system describe svc traefik | sed -n '/Ports:/,/Selector:/p'
```
预期:`traefik` Service 出现新增端口(如 `18080/TCP``18443/TCP`)或对应的暴露配置生效;若节点/上游负载均衡允许访问,则可在对应端口访问路由(路由规则仍由 Ingress/IngressRoute 决定)。
## 失败排查
- **端口没有出现**:确认清单应用在 `kube-system`,并且 `metadata.name: traefik` 匹配 K3s 内置 chart 名称;查看 Traefik Pod 日志与 Deployment 是否滚动更新。
- **端口出现但访问不通**:检查节点防火墙/上游转发(如 OpenWrt/HAProxy、以及 Traefik Service 类型ClusterIP/NodePort/LoadBalancer对外可达性。
- **回滚**:执行删除命令后等待 Traefik rollout 结束。
## 相关文档
- `03-01-k3s-traefik-dashboard.md`
- `03-02-k3s-traefik-acme.md`
- `01-07-openwrt-haproxy.md`