Defining load balancers using rancher-compose and sharing with primary load balancer?

Okay guys, so I work for a company that hosts a lot of websites and we are using Rancher to host them. Ive gotten all of the bugs worked out so far and its working great. Right now we’re testing everything using one server, and as you are aware multiple load balancers can’t listen to the same TCP port. Right now, the way that I’m routing all of the domain names using the regular load balancer image listening to port 80 and using the request hostname feature to send them to the appropriate places. So far this has proven to be a manual process. I separate each website into a directory with its own rancher-compose and docker-compose YAML files.

Is there any way to define a sub-balancer for each website and link it to a main load balancer that listens on port 80? It’s not the biggest deal in the world if I have to manually add the hostnames for each website, but it sure would be fantastic if I could get Rancher to automatically route domains to the appropriate stacks and images. Thanks in advance!

@lovecannon even if you define a sub load balancer - which you can do btw by creating an internal lb for each web site, and then link those internal lbs to the main - public LB - you would still need to define the routing rules for forwarding traffic from port 80 to the internal lbs.

I think what you are looking for is - make a redirect decision based on the request (lets stay, path part of it), but then inside the load balancer to strip off that path after routing decision is made, so you don’t have to manually add path to each of your websites. Unfortunately, stripping off part is not something we support today, but we are thinking about enabling it at some point (refer to this forum post for more details:

@alena, I think you missed the point, slightly. Not about the sub lb, but regarding adding links from a lb to a new service.

I have a similar need as @Lovecannon, where I have a single main LB routing all traffic, based on request host, to services across many different stacks. The problem now is, when we launch service using rancher-compose, how can we automatically add a link from the LB to the new service? It would be nice if we could do it from the same rancher-compose file used to launch the service. The only thing I know works right now is to issue a second rancher-compose upgrading the LB, with an updated list of links to the new service(s).

@kaos got it. I think our upcoming selectors feature would provide a workaround for that:

You can define a selector criteria for the LB service, and then service having the label satisfying the criteria, would join the LB automatically, so there is no need to update LB service .yml file with the new link information.

Aw, cool :smile:

One question though, how would I add additional configuration for the load balancer?

If I’m not mistaken, this will add a link from the LB to a service, but for the case in question, about routing traffic based on request host header, the link in itself isn’t enough. We’d want to be able to tell which hostname it should match against in the request, as well as to which port the traffic should be routed to (and possible, from which source port), etc…

@kaos you are not mistaken. Selectors based approach wouldn’t cover hostname routing use case.

We do have compose format refactoring for LB service in plans; will keep a note of yours/@Lovecannon use cases in mind.


@kaos FYI, I have created this enhancement to track the selector and hostname routing use case.

1 Like

I followed the issues


After both features implemented it should be possible to automatically add services to a loadbalancer also with domain based routing rules.

Because I plan a multi host setup with services behind a (local) LB I have to questions.

  1. Is it possible to add service container to the LB running an the same(!) host? (HTTP to LB-HTTP, SSH to LB-SSH, …)
  2. Will the LB also changed by selector if the container / service will be moved to another host with it own LB?