It seems that DNS Service does not work in a way documentation prescribes it:
When queried by the service name, the DNS service returns a randomized list of IP addresses of the healthy containers implementing that service.
I’ve created Nginx
stack, added nginx
service and created lb-test
load balancer for this service.
I then created a different stack, added debian
service and linked lb-test
from nginx
service as nginx-lb
in the debian
service.
Below are my results, it seems that IPs are not randomized and always returned in the same order:
root@4a398d57a8ab:~# for _ in {1..4}; do echo '~/~'; getent hosts nginx-lb; sleep 1; done
~/~
10.42.67.172 nginx-lb.rancher.internal
10.42.180.18 nginx-lb.rancher.internal
~/~
10.42.67.172 nginx-lb.rancher.internal
10.42.180.18 nginx-lb.rancher.internal
~/~
10.42.67.172 nginx-lb.rancher.internal
10.42.180.18 nginx-lb.rancher.internal
~/~
10.42.67.172 nginx-lb.rancher.internal
10.42.180.18 nginx-lb.rancher.internal
root@4a398d57a8ab:~# for _ in {1..4}; do echo '~/~'; getent hosts lb-test.nginx; sleep 1; done
~/~
10.42.67.172 lb-test.nginx
10.42.180.18 lb-test.nginx
~/~
10.42.67.172 lb-test.nginx
10.42.180.18 lb-test.nginx
~/~
10.42.67.172 lb-test.nginx
10.42.180.18 lb-test.nginx
~/~
10.42.67.172 lb-test.nginx
10.42.180.18 lb-test.nginx
In comparison with AWS
I have expected that returned list of IP addresses will be rotated in a round robin fashion.
A simple application simulation:
root@4a398d57a8ab:~# for _ in {1..30}; do curl -sv lb-test.nginx 2>&1 | grep 'Connected to'; done
* Connected to lb-test.nginx (10.42.180.18) port 80 (#0)
* Connected to lb-test.nginx (10.42.180.18) port 80 (#0)
* Connected to lb-test.nginx (10.42.180.18) port 80 (#0)
* Connected to lb-test.nginx (10.42.180.18) port 80 (#0)
* Connected to lb-test.nginx (10.42.180.18) port 80 (#0)
* Connected to lb-test.nginx (10.42.180.18) port 80 (#0)
* Connected to lb-test.nginx (10.42.180.18) port 80 (#0)
* Connected to lb-test.nginx (10.42.180.18) port 80 (#0)
* Connected to lb-test.nginx (10.42.180.18) port 80 (#0)
* Connected to lb-test.nginx (10.42.180.18) port 80 (#0)
* Connected to lb-test.nginx (10.42.180.18) port 80 (#0)
* Connected to lb-test.nginx (10.42.180.18) port 80 (#0)
* Connected to lb-test.nginx (10.42.180.18) port 80 (#0)
* Connected to lb-test.nginx (10.42.180.18) port 80 (#0)
* Connected to lb-test.nginx (10.42.180.18) port 80 (#0)
* Connected to lb-test.nginx (10.42.180.18) port 80 (#0)
* Connected to lb-test.nginx (10.42.180.18) port 80 (#0)
* Connected to lb-test.nginx (10.42.180.18) port 80 (#0)
* Connected to lb-test.nginx (10.42.180.18) port 80 (#0)
* Connected to lb-test.nginx (10.42.180.18) port 80 (#0)
* Connected to lb-test.nginx (10.42.180.18) port 80 (#0)
* Connected to lb-test.nginx (10.42.180.18) port 80 (#0)
* Connected to lb-test.nginx (10.42.180.18) port 80 (#0)
* Connected to lb-test.nginx (10.42.180.18) port 80 (#0)
* Connected to lb-test.nginx (10.42.180.18) port 80 (#0)
* Connected to lb-test.nginx (10.42.180.18) port 80 (#0)
* Connected to lb-test.nginx (10.42.180.18) port 80 (#0)
* Connected to lb-test.nginx (10.42.180.18) port 80 (#0)
* Connected to lb-test.nginx (10.42.180.18) port 80 (#0)
* Connected to lb-test.nginx (10.42.180.18) port 80 (#0)
root@4a398d57a8ab:~# for _ in {1..30}; do curl -sv nginx-lb 2>&1 | grep 'Connected to'; done
* Connected to nginx-lb (10.42.180.18) port 80 (#0)
* Connected to nginx-lb (10.42.180.18) port 80 (#0)
* Connected to nginx-lb (10.42.180.18) port 80 (#0)
* Connected to nginx-lb (10.42.180.18) port 80 (#0)
* Connected to nginx-lb (10.42.180.18) port 80 (#0)
* Connected to nginx-lb (10.42.180.18) port 80 (#0)
* Connected to nginx-lb (10.42.180.18) port 80 (#0)
* Connected to nginx-lb (10.42.180.18) port 80 (#0)
* Connected to nginx-lb (10.42.180.18) port 80 (#0)
* Connected to nginx-lb (10.42.180.18) port 80 (#0)
* Connected to nginx-lb (10.42.180.18) port 80 (#0)
* Connected to nginx-lb (10.42.180.18) port 80 (#0)
* Connected to nginx-lb (10.42.180.18) port 80 (#0)
* Connected to nginx-lb (10.42.180.18) port 80 (#0)
* Connected to nginx-lb (10.42.180.18) port 80 (#0)
* Connected to nginx-lb (10.42.180.18) port 80 (#0)
* Connected to nginx-lb (10.42.180.18) port 80 (#0)
* Connected to nginx-lb (10.42.180.18) port 80 (#0)
* Connected to nginx-lb (10.42.180.18) port 80 (#0)
* Connected to nginx-lb (10.42.180.18) port 80 (#0)
* Connected to nginx-lb (10.42.180.18) port 80 (#0)
* Connected to nginx-lb (10.42.180.18) port 80 (#0)
* Connected to nginx-lb (10.42.180.18) port 80 (#0)
* Connected to nginx-lb (10.42.180.18) port 80 (#0)
* Connected to nginx-lb (10.42.180.18) port 80 (#0)
* Connected to nginx-lb (10.42.180.18) port 80 (#0)
* Connected to nginx-lb (10.42.180.18) port 80 (#0)
* Connected to nginx-lb (10.42.180.18) port 80 (#0)
* Connected to nginx-lb (10.42.180.18) port 80 (#0)
* Connected to nginx-lb (10.42.180.18) port 80 (#0)
Each time my application (curl script) has connected to the same nginx
container (10.42.180.18).
Any ideas?
BTW, I’m using the following components:
Rancher v1.4.1
Cattle v0.176.9
User Interface v1.4.6
Rancher CLI v0.4.1
Rancher Compose v0.12.2