Rancher Series Article - K3s Traefik MiddleWare Error - Failed to create middleware keys
This article was last updated on: July 24, 2024 am
overview
The book continues from the previous time:Rancher series - K3S Cluster UpgradeWe mentioned that upgrading the K3S cluster through a one-click script has an error.
Next, start the analysis and repair of Traefik errors, the problem is:
- All of Traefik’s
IngressRoute
Access error 404 is reported
Description of the problem
The error is reported as follows:
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
That is, you cannot call Traefik MiddleWare across NameSpace.
Resolution process
First according to the official documentation:Kubernetes IngressRoute & Traefik CRD - Traefik
Can be configured allowCrossNamespace
parameter, which defaults to false
if the parameter is set totrue
, IngressRoutes can reference resources in other NameSpaces.
Basically, this is the root cause. Looking at the Traefik configuration of K3s v1.22.5+k3s2, there is indeed no such parameter, as follows:
1 |
|
So, initially, it was planned to add this parameter by editing Helm’s files.
Edit the Manifests Helm file for K3s
📚️ Reference:
- Automatic deployment of manifests and Helm charts
at/var/lib/rancher/k3s/server/manifests
Any Kubernetes manifest found will look similarkubectl apply
to automatically deploy to K3s. Manifests deployed in this way are managed as AddOn custom resources and can be run throughkubectl get addon -A
to check it out. You’ll find AddOns for packaged components such as CoreDNS, Local-Storage, Traefik, etc. AddOns are automatically created by the deployment controller and named after their filenames in the manifests directory.
The file is located at:/var/lib/rancher/k3s/server/manifests/traefik.yaml
, which reads as follows:
1 |
|
1 |
|
Add the following configuration to the above yaml:
1 |
|
After it takes effect, it can indeed return to normal, but K3s will periodically reset the manifests to the original configuration, which will cause the problem to recur.
So the problem is not finally solved.
Use HelmChartConfig to customize packaged components
However, according to the official documentation, we can pass Use HelmChartConfig to customize packaged components way to override the value of packaged components deployed as HelmCharts (such as Traefik).
The specific configuration is as follows:
1 |
|
After taking effect, it returned to normal, and no rollback occurred.
Problem solving.
🎉🎉🎉