Routing
A router is in charge of connecting incoming requests to the services that can handle them. In the process, routers may use pieces of middleware to update the request, or act before forwarding the request to the service.
Configuration Examples
- Check on the Host using a Regular Expression
- Check on the Host, add a priority
- Check on the Path, the Method and the Header
apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
name: my-app
namespace: apps
spec:
entryPoints:
- websecure
routes:
# Match requests with Host set to either example.com or example.org.
# To match domains case-insensitively, use the (?i) option.
- match: HostRegexp(`(?i)^example\.(com|org)$`)
kind: Rule
services:
- name: whoami
port: 80
apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
name: my-app
namespace: apps
spec:
entryPoints:
- websecure
routes:
# Match requests with Host set to whoami.example.com.
- match: Host(`whoami.example.com`)
kind: Rule
# The bigger the number, the higher the priority
priority: 10000
services:
- name: whoami
port: 80
apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
name: my-app
namespace: apps
spec:
entryPoints:
- websecure
routes:
# Match requests with a Content-Type header set to either application/json or application/yaml
# And a path set to /products but neither /products/shoes nor /products/
# AND only the HTTP Methods GET, POST and PUT
- match: Path(`/products`) && HeaderRegexp(`Content-Type`, `^application/(json|yaml)$`) && (Method(`GET`) || Method(`POST`) || Method(`PUT`))
kind: Rule
services:
- name: whoami
port: 80
Configuring UDP Routers
The character @
is not allowed in the router name
General
Similarly to TCP, as UDP is the transport layer, there is no concept of a request, so there is no notion of an URL path prefix to match an incoming UDP packet with. Furthermore, as there is no good TLS support at the moment for multiple hosts, there is no Host SNI notion to match against either. Therefore, there is no criterion that could be used as a rule to match incoming packets in order to route them. So UDP routers at this time are pretty much only load-balancers in one form or another.
Even though UDP is connectionless (and because of that),
the implementation of an UDP router in Traefik relies on what we (and a couple of other implementations) call a session
.
It means that some state is kept about an ongoing communication between a client and a backend,
notably so that the proxy knows where to forward a response packet from a backend.
As expected, a timeout
is associated to each of these sessions,
so that they get cleaned out if they go through a period of inactivity longer than a given duration.
EntryPoints
If not specified, UDP routers will accept packets from all defined UDP EntryPoints.
If one wants to limit the router scope to a set of EntryPoints, one should set the entryPoints
option.
udp:
routers:
Router-1:
# By default, routers listen to all UDP entrypoints
# i.e. "other", and "streaming".
service: "service-1"
## Dynamic configuration
udp:
routers:
Router-1:
# does not listen on "other" entry point
entryPoints:
- "streaming"
service: "service-1"
Services
There must be one (and only one) UDP service referenced per UDP router. Services are the target for the router.
UDP routers can only target UDP services (and not HTTP or TCP services).