Simple TCP Load Balancing

Hey all.

I have what should I think should be a simple setup but I'm struggling to get it going and I'm hoping someone here can help.

I'm using Consul and Nomad scheduled docker containers. I'd like three entrypoints connected to one router, load balancing across three containers (using dynamic ports) that can live on any one of three hosts.

I've got this working with a single entrypoint attached to a single router routing to a single container using labels/tags like this:

"traefik.enable=true",
"traefik.tcp.routers.r1.entrypoints=e1",
"traefik.tcp.routers.r1.rule=HostSNI(`*`)",
"traefik.tcp.routers.r1.service=docker-stuff-0"

I can also get this working with three entrypoints. However, if I want to actually load balance across three containers/services, how do I do it?

If I add the labels above to all three containers I get errors about the same router being defined multiple times. I've also tried statically configuring the router to no avail. I suspect there's a simple answer to this but I've not been able to find it.

Thanks

OK, so I seem to have fixed half of this (a single service with three servers) by simply adding the following labels to each container:

"traefik.enable=true",
"traefik.tcp.services.stuff.loadBalancer.terminationDelay=200"

However, I'm still confused about the router configuration. I can add a definition using labels to one of the containers and that works, but if that particular container fails I've lost my router. I've tried doing this statically in the config file but it seems to be ignored:

[tcp.routers]
  [tcp.routers.stuff]
    entryPoints = ["e1","e2","e3"]
    rule = "HostSNI(`*`)"
    service = "stuff"

Hi @sjiveson

Move the router to the traefik container in that case. This is where I put weird things that I can't pin on any other container/service.

For your toml, you you'd need to define the service as "stuff@consul". Without an @provider it will default to the same provider type where the router is defined.

Thank you, that worked, once I'd tweak the Consul constraints.

This also worked without causing duplicate the router error messages:

"traefik.enable=true"
"traefik.tcp.routers.stuff.entrypoints=e0,e1,e2"
"traefik.tcp.routers.stuff.rule=HostSNI(`*`)"
"traefik.tcp.services.stuff.loadBalancer.terminationDelay=200"]
1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.