I'm using k3s to host a few local services, which are exposed using
IngressRoutes
like this:
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
name: grafana
spec:
entryPoints:
- web
routes:
- match: Host(`monitoring.internal`) && PathPrefix(`/grafana`)
kind: Rule
services:
- name: grafana
port: 3000
This works just fine. The difficulty I have is that requests for
http://monitoring.internal/
result in a 404 error. I'd like to
redirect those requests to /grafana/
. I tried creating a middleware
like this:
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
name: redirect-to-grafana
spec:
redirectRegex:
regex: ^https?://monitoring.internal/?$
replacement: http://monitoring.internal/grafana/
And an ingressroute like this:
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
name: default
spec:
entryPoints:
- web
routes:
- match: Host(`monitoring.internal`) && PathPrefix(`/`)
kind: Rule
middlewares:
- redirect-to-grafana
But this seems to result in an error; looking at the traefik logs I
see:
E0806 01:53:55.303813 1 reflector.go:138]
pkg/mod/k8s.io/client-go@v0.20.2/tools/cache/reflector.go:167: Failed
to watch *v1alpha1.IngressRoute: failed to list
*v1alpha1.IngressRoute: v1alpha1.IngressRouteList.Items:
[]v1alpha1.IngressRoute: v1alpha1.IngressRoute.Spec:
v1alpha1.IngressRouteSpec.Routes: []v1alpha1.Route:
v1alpha1.Route.Middlewares: []v1alpha1.MiddlewareRef: readObjectStart:
expect { or n, but found ", error found in #10 byte of
...|ewares":["redirect-t|..., bigger context ...|l`) \u0026\u0026
PathPrefix(`/`)","middlewares":["redirect-to-grafana"]}]}}],"kind":"IngressRouteLis|...
What's the correct way of doing this?
Thanks!