

Rancher 系列文章-K3s Traefik MiddleWare 报错-Failed to create middleware keys -...
source link: https://www.cnblogs.com/east4ming/p/17256357.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Rancher 系列文章-K3s Traefik MiddleWare 报错-Failed to create middleware keys
书接上回:《Rancher 系列文章-K3S 集群升级》, 我们提到:通过一键脚本升级 K3S 集群有报错。
接下来开始进行 Traefik 报错的分析和修复, 问题是:
- 所有 Traefik 的
IngressRoute
访问报错 404
报错如下:
time="2022-05-05T09:51:21Z" level=error msg="Failed to create middleware keys: middleware kube-system/hsts-header is not in the IngressRoute namespace cert-manager" namespace=cert-manager providerName=kubernetescrd ingress=grafana
即无法跨 NameSpace 调用 Traefik MiddleWare.
首先根据官方文档说明:Kubernetes IngressRoute & Traefik CRD - Traefik
可以配置 allowCrossNamespace
参数,该参数默认为 false
, 如果该参数设置为true
, IngressRoutes 可以引用其他 NameSpace 中的资源。
基本上断定根因就是这个了。查看 K3s v1.22.5+k3s2 的 Traefik 配置,确实没有这个参数,如下:
...
containers:
- name: traefik
image: rancher/mirrored-library-traefik:2.5.0
args:
- '--entryPoints.metrics.address=:9100/tcp'
- '--entryPoints.traefik.address=:9000/tcp'
- '--entryPoints.web.address=:8000/tcp'
- '--entryPoints.websecure.address=:8443/tcp'
- '--api.dashboard=true'
- '--ping=true'
- '--metrics.prometheus=true'
- '--metrics.prometheus.entrypoint=metrics'
- '--providers.kubernetescrd'
- '--providers.kubernetesingress'
- >-
--providers.kubernetesingress.ingressendpoint.publishedservice=kube-system/traefik
- '--entrypoints.websecure.http.tls=true'
...
所以,刚开始就计划通过编辑 Helm 的文件把这个参数加上。
编辑 K3s 的 Manifests Helm 文件
📚️ Reference:
- 自动部署 manifests 和 Helm charts
在/var/lib/rancher/k3s/server/manifests
中找到的任何 Kubernetes 清单将以类似kubectl apply
的方式自动部署到 K3s。以这种方式部署的 manifests 是作为 AddOn 自定义资源来管理的,可以通过运行kubectl get addon -A
来查看。你会发现打包组件的 AddOns,如 CoreDNS、Local-Storage、Traefik 等。AddOns 是由部署控制器自动创建的,并根据它们在 manifests 目录下的文件名命名。
该文件位于:/var/lib/rancher/k3s/server/manifests/traefik.yaml
, 内容如下:
---
apiVersion: helm.cattle.io/v1
kind: HelmChart
metadata:
name: traefik-crd
namespace: kube-system
spec:
chart: https://%{KUBERNETES_API}%/static/charts/traefik-crd-10.3.001.tgz
---
apiVersion: helm.cattle.io/v1
kind: HelmChart
metadata:
name: traefik
namespace: kube-system
spec:
chart: https://%{KUBERNETES_API}%/static/charts/traefik-10.3.001.tgz
set:
global.systemDefaultRegistry: ""
valuesContent: |-
rbac:
enabled: true
ports:
websecure:
tls:
enabled: true
podAnnotations:
prometheus.io/port: "8082"
prometheus.io/scrape: "true"
providers:
kubernetesIngress:
publishedService:
enabled: true
priorityClassName: "system-cluster-critical"
image:
name: "rancher/mirrored-library-traefik"
tolerations:
- key: "CriticalAddonsOnly"
operator: "Exists"
- key: "node-role.kubernetes.io/control-plane"
operator: "Exists"
effect: "NoSchedule"
- key: "node-role.kubernetes.io/master"
operator: "Exists"
effect: "NoSchedule"
在上面的 yaml 中加入如下配置:
...
providers:
kubernetesCRD:
allowCrossNamespace: true
待其生效后, 确实可以恢复正常, 但是 K3s 会定期将 Manifests 重置为原有配置, 就会导致问题再次出现.
所以问题并没有最终解决.
使用 HelmChartConfig 自定义打包的组件
不过根据官方文档后续的内容, 我们可以通过 使用 HelmChartConfig 自定义打包的组件 的方式覆盖作为 HelmCharts(如 Traefik)部署的打包组件的值.
具体配置如下:
apiVersion: helm.cattle.io/v1
kind: HelmChartConfig
metadata:
name: traefik
namespace: kube-system
spec:
valuesContent: |-
globalArguments:
- "--providers.kubernetescrd.allowcrossnamespace=true"
生效后, 恢复正常, 并且没有发生回滚.
问题解决.
🎉🎉🎉
📚️ 参考文档
三人行, 必有我师; 知识共享, 天下为公. 本文由东风微鸣技术博客 EWhisper.cn 编写.
Recommend
-
40
Ingress的重要性不言而喻。简单地创建一个Ingress API资源是没有作用的,往往需要与Ingress Controller搭配使用。Ingress Controller之一,Traefik能够实现现代HTTP反向代理和负载均衡器的功能,从而简化微服务的部署。本文将详细介绍如何在K8S集群中部署Traefik I...
-
14
解决git clone出现“error: RPC failed; result= 18,HTTP code = 20018. 00 KiB/s”报错的五个网址(个人用) ...
-
6
kvm虚拟机开机之后报错Failed to mount |坐而言不如起而行! 二丫讲梵对于注定会优秀的人来说,他所需要的,只是时间!手懒得,必受贫穷,手勤的,必得富足----《圣经》帮助别人,成就自己。愿君在本站能真正有所收获!如果你在...
-
12
8 June 2021 / 开发笔记 Javascript解析JSON字符串报错:parse failed: SyntaxError: Unexpected token n in JSON 有个JavaScript对象obj,其中一...
-
6
如何使用 Rancher Desktop 访问 Traefik Proxy 仪表板Adrian Goins 最近举办了关于如何使用 K3s...
-
10
How to enforce TLS using Traefik Middleware Reading Time: 3 minutes
-
5
K3S 系列文章-5G IoT 网关设备 POD 访问报错 DNS 'i/o timeout'分析与解决 ...
-
13
Rancher 系列文章-在腾讯云的 K3S 上安装高可用 Rancher 集群 ...
-
6
最近在玩 Rancher, 先从最基本的功能玩起, 目前有几个已经搭建好的 K8S 集群, 需要批量导入, 发现官网已经有批量导入的文档了. 根据 Rancher v2.6 进行验证微...
-
3
一 基础信息 1.1 前提 本次安装的为 20220129 最新版:Rancher v2.6.3 VM 版本为 RHEL 7.8, 7.9 或 8.2, 8.3, 8.4(Rancher 官网要求) VM YUM 仓库:已配置对应版本的 RHEL 和 EPEL YUM 仓...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK