Hi there.
I'm struggling trying to make failover setup work.
Here is the requirements:
Two Servers "A" and "B"
Server "A" should receive 100% of incoming traffic. If server "A" fails healthcheck, the traffic should be served from server "B"
Server "B" should not receive ANY traffic as long as server "A" is up
I've tried different approaches but with no luck. is it possible to do this with Traefik and how?
Here is an example of my latest attempt config:
[http]
# Add the router
[http.routers]
[http.routers.app]
entryPoints = ["web"]
service = "service-app"
[http.services]
[http.services.service-app]
[[http.services.service-app.weighted.services]]
name = "master"
weight = 1
[[http.services.service-app.weighted.services]]
name = "slave"
weight = 0
[http.services.master]
[http.services.master.loadBalancer]
[[http.services.master.loadBalancer.servers]]
url = "master.int"
[http.services.master.loadBalancer.healthCheck]
path = "/"
[http.services.slave]
[http.services.slave.loadBalancer]
[[http.services.slave.loadBalancer.servers]]
url = "slave.int"
[http.services.slave.loadBalancer.healthCheck]
path = "/"
zespri
November 18, 2019, 11:25pm
2
Not out of the box no.
What came to mind, if we constrain ourselves to traefik only is that we need to make sure that while health check on A is succeeded health check for B is failing or B is out of the pool. Traefik cannot do this on its own, so you need to come up with your own solution for that. Or (unlikely but not beyond the realm of possible) find someone who did that before.
You can use watched dynamic config or rest api to add/remove services in traefik.
It worked out of the box in v1.7. I've just tested it.
zespri
November 20, 2019, 11:24pm
4
These are migration notes from v1 to v2 https://docs.traefik.io/migration/v1-to-v2/
If you have trouble poriting some configuration over, please give more details. Since we are talking about a very specific scenario please also provide, along with your v1 configuration, how you tested it.
Here is the config for v1.7 that works as expected:
traefik.toml
AllowMinWeightZero = false
defaultEntryPoints = ["web"]
[entryPoints]
[entryPoints.web]
address = ":8081"
[file]
filename = "/etc/traefik/dynamic_conf.toml"
dynamic_conf.toml
[backends]
[backends.master]
[backends.master.healthcheck]
path = "/"
[backends.master.servers.master]
url = "http://172.17.0.1:8080/"
weight = 100
[backends.master.servers.slave]
url = "http://172.17.0.1:8082/"
weight = 0
[backends.slave]
[backends.slave.healthcheck]
path = "/"
[backends.slave.servers.master]
url = "http://172.17.0.1:8080/"
weight = 0
[backends.slave.servers.slave]
url = "http://172.17.0.1:8082/"
weight = 100
[frontends]
[frontends.master]
backend = "master"
[frontends.master.routes.master]
rule = "Headers:X-Server-Select,master"
[frontends.slave]
backend = "slave"
[frontends.slave.routes.slave]
rule = "Headers:X-Server-Select,slave"