I'm working on transferring our current setup from haproxy to træfik.
We have a versioned api, which is url versioned like this:
host/1/api
host/2/api
host/3/api
etc.
In addition you can access our latest api at host/api
. Our api versions run in different docker containers, and translating the old haproxy config into labels in docker has been a breeze (host and prefix matching), however there is one thing I can't seem to figure out:
How can I make host/api
always redirect to the latest version? I can do something when we deploy a new container, but I would prefer to not having to touch old containers every time we do a new deploy.
I was hoping I could use a dynamic file config for this, but so far I haven't really figured out how.
Basically I want host/api
to rewrite to host/3/api
which should then hit correct service for host/3/api
.
When we deploy version 4 of our api (host/4/api
), I would like to make host/api
now rewrite to /host/4/api
and hit that service.
The closests I think I got was using a weighted loadBalancer, but still no dice.
I have whoami1-3 running in docker and able to respond on /[1-2]/api right now.
The general idea is a that I could just replace prefix = "2"
and name = "whoami2-traefik@docker"
with whatever comes at next deploy (3 in this case)
[http.routers]
[http.routers.whoami]
rule = "Host(`whoami.docker.localhost`) && PathPrefix(`/api/`)"
middlewares = ["add-api-prefix"]
entryPoints = ["https"]
service = "whoami"
[http.services]
[http.services.whoami]
[[http.services.whoami.weighted.services]]
name = "whoami2-traefik@docker"
[http.middlewares]
[http.middlewares.add-api-prefix.addPrefix]
prefix = "2"
Grateful for any help!