简体   繁体   中英

Traefik: Dynamic routing by subdomain

Problem,

I have multiple services that are deployed on Docker containers. Each set of our clients should be routed to a specific service. Example:

  • Client1 -> service1
  • Client2 -> service1
  • client3 -> service2

This should done using subdomain: client1= client1.example.com client2 = client2.example.com

Question:

I would like this config to be dynamic meaning that Traefik needs to get these routing rules dynamically from another service:

  • I can for example create a service that giving a hostname return the name of service that Traefik should route to.
  • Or maybe when a client is added I can push this rule to Traefik.

Details:

This feature is useful when I create a saas application.

Thank you very much.

One easy way to achieve this is to use regex for the defined routers for each of the services and update the regex once you onboarded a new client

For instance, add this label to the service 1

 - traefik.http.routers.app-backend.rule=HostRegexp(`{subdomain:(clinet1)}.example.com`)

and when you add another client that should be served by service 1, just update the label to be

 - traefik.http.routers.app-backend.rule=HostRegexp(`{subdomain:(clinet1|clientX)}.example.com`)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM