I'm using Eureka Server 1 and Eureka clients as spring boot apps which runs on Docker containers orchestrated by Rancher (www.rancher.com).
Rancher adds an IP address on eth0 nic of the container (10.42.X.X) for reach other group of containers (services) on other hosts via managed network implemented with IPSec.
The problem is that eth0 holds the docker native IP address from docker0 (172.17.X.x) so the NIC has 2 IP address and eureka clients registers the 172.72.X.X IP with eureka.preferIpAddress:true so Feign clients can't reach other services.
On the other hand, when I unset eureka.preferIpAddress:true the clients register with the container hostname and they has less chances to reach each others.
Am I doing something wrong?
How can I modify eureka config for prefer other IP on the same NIC?
Thanks in advance
Rancher has a metadata service where I can fetch the IP address of the managed network IP assigned to the container:
As I create the containers with docker plugin for maven, the artifact is always copied with the name app.jar, so the base image has an entrypoint like this:
#!/bin/bash
echo "Setting rancher managed ip address on MANAGED_IP environment variable"
export MANAGED_IP=$(curl --retry 5 --connect-timeout 3 -s 169.254.169.250/latest/self/container/primary_ip)
echo "Rancher IP is ${MANAGED_IP}"
java -Djava.security.egd=file:/dev/./urandom -jar /app.jar
This is my config repo (I'm using config server too) with settings for eureka.yml:
eureka
instance:
preferIpAddress: true
ip-address: ${MANAGED_IP}
Now the clients register with Eureka with the managed IP address
Hope this helps others and thanks for your response