Linking / load balancers

Hi All,

Just trying to get my head around a few things as fairly new to rancher / docker.

Say for instance I have an app with a front end and a back end api and I am running multiple instances of the api across a few hosts, whats the best way to point the front end to the api?

I have tried it with service linking which seems to work but I don’t understand what its doing in the background. If I link a service that has multiple containers across multiple hosts does it act as a load balancer?

Should I just set up an internal load balancer and link to that as a service?

Hope someone can advise on best practice.

Thanks,

When you link two services, rancher updates its DNS to include the linked to service with the addresses of all instances. So when you query the DNS you get the all the IP addresses for that service.

Not exactly sure if they do some kind of round robin on the addresses returned, though.

All the addresses are returned, in an order that is randomized every time it is requested. Depending on the client application they may use all of them, pick the first one, a random one, there one most closely matching their subnet, etc. So it sort of acts like a “poor-man’s” balancer. If you need more control then you can create an internal balancer.

Oh that is neat that you can route to multiple containers without a LoadBalancer.

Just out of curiosity is this a Rancher specific feature? Or is this something that Docker/Docker Compose does natively? (for one host)

For multiple hosts and containers cross host, I assume that the networking is setup through rancher-dns on the overlay network?

It is a rancher specific DNS: https://github.com/rancher/rancher-dns

Yes, confirmed I had some time at work to do a little experiment with docker-compose. It doesn’t work with regular docker-compose.

This is actually an unadvertised feature of Rancher to be honest.

Experiment (docker-compose)
serviceA -> SeviceB (with scale 2)

Hosts Files of serviceA

127.0.0.1       localhost
::1     localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.17.0.9      SeviceB_2 4d117dc2589a SeviceB_2
172.17.0.9      ServiceB_2 4d117dc2589a
172.17.0.6      ServiceB 64b6ac77af56 ServiceB_1
...

Experiment (Rancher):

$> cat /etc/hosts
172.17.0.37     4d04d77c89f9
127.0.0.1       localhost
::1     localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

$> dig serviceB
; <<>> DiG 9.9.5-3ubuntu0.8-Ubuntu <<>> yelp
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 56253
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;serviceB.                          IN      A

;; ANSWER SECTION:
serviceB.                   1       IN      A       10.42.106.33
serviceB.                   1       IN      A       10.42.125.51

;; Query time: 7 msec
;; SERVER: 169.254.169.250#53(169.254.169.250)
;; WHEN: Fri Sep 09 16:28:50 UTC 2016
;; MSG SIZE  rcvd: 54