Here is the yaml file for traefik ingress and middleware. I want to add a basic auth middleware to a service, but once I added this annotation traefik.ingress.kubernetes.io/router.middlewares: default-testauth@kubernetescrd
, it will show a "middleware not found" error in dashboard. I think this is the correct way to use middlewares in traefik ingress, but why does this error come up always?
I also can see this middleware under Custome Resources section of Lens as it shows below.
traefik version 2.9.4
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
name: testauth
namespace: default
spec:
basicAuth:
secret: basicauth
removeHeader: true
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: k3s-test
namespace: default
annotations:
traefik.ingress.kubernetes.io/service.passhostheader: "true"
traefik.ingress.kubernetes.io/router.entrypoints: web
traefik.ingress.kubernetes.io/router.middlewares: default-testauth@kubernetescrd
spec:
ingressClassName: traefik
rules:
- host: dash.local
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: k3s-demo
port:
number: 80