I add new services using the cli and i want to automatically bind new services to the load balancer for host based routing , how to perform that ?
Not sure i 100% understand your issue…
Your loadbalancer (presuming your using the built-in loadbalancer in Rancher, can be orchestrated through the CLI too. As such it will be updated when you update it’s config when adding new services etc. Any scale changes to existing services should happen automatically as it uses DNS service discovery.
Thanks for your replay , can you give me an example using CLI to add a new target to the load balancer?
Do you have an existing load balancer in Rancher already? If so, you’d want to export the existing docker-compose.yml for the load balancer, add the additional labels for the hostname routing rules and then upgrade the LB.
For example, your current LB would be in the UI and if you click on the stack and click on “View Config”, you might see this docker-compose.yml for your LB.
lb1:
ports:
- 80:80
labels:
io.rancher.loadbalancer.target.service1: domain1.com
tty: true
image: rancher/load-balancer-service
links:
- service1:service1
stdin_open: true
Now you’ve added your service in the CLI (for example service2
. To upgrade your LB. you’d want to have the same docker-compose.yml, but add in the new rules for your new service.
lb1:
ports:
- 80:80
labels:
io.rancher.loadbalancer.target.service1: domain1.com
# Add your hostname routing rules
io.rancher.loadbalancer.target.service2: domain2.com
tty: true
image: rancher/load-balancer-service
links:
- service1:service1
# Add the link to the service
- service2:service2
stdin_open: true
There would be some small differences if your services are in other stacks.
Here’s how the labels work for hostname routing rules:
Thank you now its clear for me
I tried the steps you mentioned and it worked as expected , but the problem is when performing the upgrade the load balancer stops routing requests till the upgrade is complete which causes downtime . Is there a way to avoid that or to automatically map domain names to containers like jwilder/nginx-proxy for example?