Roger Johansson
Roger Johansson

Reputation: 23214

Cross container/host communication with Rancher

I'm experimenting with Consul, Rancher and Docker.

So I have this REST service that runs on 4 different hosts. each instance of this service register itself in a single Consul container using container linking. that is, all instances know about the Consul container.

This works fine.

What doesnt work fine is when Consul tries to do health checks to my services. If an instance of the service runs on the same host as the consul container, that works. But any instance running on a different host will fail. Address unrachable.

I have tried to extract the service instance container IP in a few different ways. 1) listing all available notwork interfaces and ip's inside the container. 2) "hostname -i" inside the container.

They all yeild IPs. e.g. 172.16.0.06 While Rancher list IP's such as 10.43.100.24 for the same container.

My guess is that Consul should perform the health check on the IP that Rancher shows, and not the IP that I extracted inside the container.

I'm a bit at loss here, How should my service find the IP that it should use to register itself inside Consul?

(I'm aware that this is not really how Consul should be used, but the problem is that containers on one host can not reach containers on another host.. so the Consul part is just to put context on what I'm trying out)

Upvotes: 3

Views: 1448

Answers (2)

Roger Johansson
Roger Johansson

Reputation: 23214

I've marked @leodotcloud's answer as correct as it provides the correct ip if you throw some parsing magic at it.

I've got a more straight forward answer from the Rancher Froums though. https://forums.rancher.com/t/how-to-get-rancher-virtual-ip-from-within-a-container/3668

You can call this URI to get the address back: http://rancher-metadata/2015-12-19/self/container/primary_ip

Upvotes: 1

leodotcloud
leodotcloud

Reputation: 1960

The IP addresses issued by docker are not unique across the cluster. Hence Rancher uses 10.42.0.0/16 subnet to give out unique IP addresses.

You can find the Rancher IP address using this command

ip addr

If you can configure your application to use the Rancher IP address, you will be able to communicate across the hosts.

For detailed information about networking inside Rancher, please check this page: http://rancher.com/day-life-packet-inside-rancher/

Troubleshooting guide: http://docs.rancher.com/rancher/v1.2/en/faqs/troubleshooting/#cross-host-communication

Upvotes: 2

Related Questions