Failover / backup server functionality

Hi there,

I am trying to implement a relatively simple HTTP loadbalancing scenario with Master/Backup failover:

  • two "backend" servers - let's say 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

Is there any way to achieve this functionality with traefik?

Things I have tried so far:

  • creating two frontends/routers, with exact same matchers and defining higher priority on a frontend referring to backend with server A. This worked when server "A" was online, but produced 503 error when it became unavailable

For reference, the config was as follows:

[file]

[backends]
    [backends.primary]
      [backends.primary.servers]
        [backends.primary.servers.server0]
        url = "https://1.1.1.1:1111"
      [backends.primary.healthCheck]
      path = "/"
      interval = "10s"


    [backends.backup]
      [backends.backup.servers]
        [backends.backup.servers.server0]
        url = "https://2.2.2.2:2222"
      [backends.backup.healthCheck]
      path = "/"
      interval = "10s"



[frontends]
  [frontends.api-frontend]
    entryPoints = ["http", "https"]
    backend = "primary"
    passHostHeader = true
    priority = 200

  [frontends.api-frontend.routes]
    [frontends.api-frontend.routes.route0]
        rule = "Host:my.example.com"

  [frontends.api-frontend-backup]
    entryPoints = ["http", "https"]
    backend = "backup"
    passHostHeader = true
    priority = 100

  [frontends.api-frontend-backup.routes]
    [frontends.api-frontend-backup.routes.route0]
        rule = "Host:my.example.com"

  • creating single frontend with a backend containing two servers A & B. In one of the issues on Github I found that setting weight of a server to 0 will make it a "backup" server, which is exactly what I need (at least it was in HAproxy terminology).
    Unfortunately this was not supported by documentation and if I understand correctly, this simply disables the server.

Config was something like that:

[file]

[backends]
    [backends.primary]
      [backends.primary.servers]
        [backends.primary.servers.server0]
        url = "https://1.1.1.1:1111"
        [backends.primary.servers.server1]
        url = "https://2.2.2.2:2222"
        weight = 0
      [backends.primary.healthCheck]
      path = "/"
      interval = "10s"


[frontends]
  [frontends.api-frontend]
    entryPoints = ["http", "https"]
    backend = "primary"
    passHostHeader = true

  [frontends.api-frontend.routes]
    [frontends.api-frontend.routes.route0]
        rule = "Host:my.example.com"

I was searching through this forum and Github issues to find possible solutions but came up empty. The closest I found was PR#3072 but looks like it wasn't merged.

Any ideas?

1 Like