Your cart is currently empty!
Kubernetes: Traefik IngressRoute
IngressRoute is Traefik CustomResourceDefinition (CRD). It is used to manage access external access to the services. Same function as Ingress, just different implementations.
Middleware is also Traefik CustomResourceDefinition (CRD). It is used to “tweak” your request and/or response.
Using Ingress, we apply the Middleware by adding it as an annotations.
Using IngressRoute, we define the Middleware as part of the spec.
First we need to create the Middleware:
Note: Only one Middleware per resource!
YAML
x
9
1
apiVersion traefik.io/v1alpha1
2
kind Middleware
3
metadata
4
name example
5
namespace default
6
spec
7
stripPrefix
8
prefixes
9
"/nginx"
Then we apply it to Ingress:
The value format for the middleware annotation is <middleware-namespace>-<middleware-name>@kubernetescrd
.
YAML
1
6
1
apiVersion networking.k8s.io/v1
2
kind Ingress
3
metadata
4
name foo
5
annotations
6
traefik.ingress.kubernetes.io/router.middlewares default-example@kubernetescrd, default-example2@kubernetescrd
Now instead of creating Ingress, we also can achieve it with IngressRoute:
YAML
1
15
15
1
apiVersion traefik.io/v1alpha1
2
kind IngressRoute
3
metadata
4
name foo
5
spec
6
entryPoints
7
web
8
routes
9
kind Rule
10
..
11
middleware
12
name example
13
namespace default
14
name...
15
...
References:
- https://doc.traefik.io/traefik/routing/providers/kubernetes-crd/
- https://doc.traefik.io/traefik/routing/providers/kubernetes-ingress/#on-ingress
- https://doc.traefik.io/traefik/routing/routers/#rule
- https://doc.traefik.io/traefik/middlewares/http/overview/#available-http-middlewares
- https://doc.traefik.io/traefik/providers/overview/#supported-providers