Traefik: Frontend rules based on dynamic environments/domains/zones

Created on 23 Feb 2018  路  3Comments  路  Source: traefik/traefik

Do you want to request a feature or report a bug?

feature

What is your environment & configuration (arguments, toml, provider, platform, ...)?

logLevel = "INFO"
debug = false
defaultEntryPoints = ["http"]

[traefikLog]
filePath = "/logs/traefik.log"

[accessLog]
filePath = "/logs/access.log"

[api]
entryPoint = "traefik"
dashboard = true
debug = false

[rest]
entryPoint = "traefik"

[ping]
entryPoint = "traefik"

[docker]
exposedbydefault = false
watch = true
domain = "dev.domain.tld"
swarmmode = true

[entryPoints]
  [entryPoints.http]
  address = ":80"

  [entryPoints.traefik]
  address = ":8080"
  [entryPoints.traefik.auth.basic]
    usersFile = "/.htpasswd"

Feature request

When you specify docker.domain=dev.domain.tld in the TOML and create a Docker Swarm service/stack the default frontend rule will be stackName-serviceName.dev.domain.tld, which is really ugly when you have a single service per stack file.

How to change this? I could specify a custom Host or HostRegexp frontend rule, something like traefik.frontend.rule=HostRegexp:customName.{subdomain:(dev|staging|prod)}.domain.tld but it's really hacky/messy and you're stuck with these 3 environments. What if I add a new VPC for our release/pre-prod environment?

I'm using Terraform to span up a Docker Swarm for 3 different Terraform workspaces / VPCs (dev, staging, production) and using Tr忙fik on each of them....... The traefik.toml is set up on the server initially when the instance is provisioned and the docker.domain is specified in it, based on my DNS zone Terraform resource and I keep my Docker stack/compose files seperate without specifying domain in each of them (because it varies between environments). Same Docker stack/compose file, different environments (VPC / DNS zones).

This would be really beneficial for those who are aiming at infrastructure-as-code with Terraform and trying to seperate domain/DNS/zones from frontend rules and want to keep their Docker stack/compose files "stateless" and not coupled to the environment/domain/DNS zone.

Let's say I want to use the same Docker stack file for 3 different DNS zones and 3 different Tr忙fik instances... dev.domain.tld, staging.domain.tld, prod.domain.tld
I would like to specify myservice as a frontend/subdomain rule and it would work for all 3 different zones (based on docker.domain specified in the traefik.toml on the server), so the same Docker stack/compose file with myservice frontend rule in the Docker stack/compose file, would work for myservice.dev.domain.tld on Tr忙fik instance on _dev_ environment, myservice.staging.domain.tld on Tr忙fik instance on _staging_ environment and myservice.prod.domain.tld on Tr忙fik instance on _production_ environment.

I suggest to allow people to change the name of the stack/service via Tr忙fik frontend label (traefik.name=someCustomName), so it would not become stackName-serviceName but instead someCustomName and that would generate a default frontend rule someCustomName.domain.tld.
Or to create a new variable ${domain} you could use in Docker service/container Tr忙fik labels, so you could set docker.domain=dev.domain.tld (generated via TOML template file in Terraform) and then in stack file, use traefik.frontend.rule=Host:customName.${domain} and that would be translated to Host:customName.dev.domain.tld or whatever domain is set in the TOML. Then people could be in same control, without having to couple the domain to the Docker stack/compose file.

areprovidedocker kinenhancement prioritP3

Most helpful comment

+1
Similar need

All 3 comments

Every time someone does not respect the issue's template, a little bunny dies.

southpark - estrella kill rabbit
southpark - estrella kill rabbit2



Please edit your issue description to respect the issue template as much as possible.

@traefiker I fixed it!

+1
Similar need

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rsoika picture rsoika  路  3Comments

mikaelmorvan picture mikaelmorvan  路  3Comments

pichouk picture pichouk  路  3Comments

pjebs picture pjebs  路  3Comments

arschles picture arschles  路  3Comments