Make Traefik route HTTP BAN requests to different service or port than regular HTTP requests

11/21/2019

we use Traefik 1.7 as the Ingress-controller on our GKE Kubernetes clusters. Each application has an Ingress that routes incoming HTTP requests to a Varnish service, which either serves the response from cache or routes the request to some nginx/PHP backend applications.

The Varnish pods consist of a Varnish container which listens on port 80 for incoming requests and an app on port 6083 that takes care of mirroring BAN requests to all Varnish replicas in order to purge cache objects from all Varnish replicas. Most BAN requests will come from the internal PHP apps but we also have BAN requests coming from GitLab CI tasks that run externally to that cluster.

We would like to route incoming HTTP requests that have the BAN verb (as opposed to GET, POST, etc.) to port 6083 on the Varnish service, while letting GET, HEAD, POST traffic hit port 80 like normal.

I can't figure out a way to have Traefik route to a different service or port based on the HTTP Verb. Any ideas?

-- Martijn Heemels
kubernetes
traefik
traefik-ingress

1 Answer

11/21/2019

You can use the Method() rule in routing expressions. See https://docs.traefik.io/routing/routers/#rule for more details but from a quick check of the code in Traefik and Mux I see no reason that Method(\"BAN\") shouldn't work.

-- coderanger
Source: StackOverflow