Cannot find a way to configure Eureka client with Docker swarm mode
See original GitHub issueWhen using Eureka client with Docker swarm mode, I didn’t find a way to correctly configure the client to notify the correct hostname / ip. With Docker swarm mode you have at least two networks (if the container exposes a port to the public network), the ingress and the overlay network used for internal cluster communication (the correct one to use for Eureka). The problem is that, in each container, you have two interfaces eth0 and eth1; these are assigned randomically to the ingress or overlay ip thus is not possible to benefit from spring.cloud.inetutils.ignoredInterfaces
property. So what happens is that randomically Eureka clients advertise the correct host configuration. Did you have any similar case to this or is there a specific Eureka configuration that can help me with that?
Issue Analytics
- State:
- Created 6 years ago
- Comments:25 (6 by maintainers)
I have found two solutions to this problem:
spring.cloud.inetutils.preferredNetworks
propertyeureka.instance.hostName: service-name
andeureka.instance.preferIpAddress: false
, where service-name is the same service-name specified in the Docker compose fileWhat do you think about them?
UPDATE4:
Day 2️⃣. I added code below in all my
spring-boot
apps in a cluster.Lets check
config
andregistry
services.Config:
Registry:
Overlay network
Remember, I asked about
10.0.0.2 / 10.0.0.2
,10.0.0.4 / 10.0.0.4
and so on which Eureka uses by default. Network interfaces show this one as Loopback. Actually every service in Docker Swarm has 3loobpack
and 3eth
interfaces. When we set to prefer10.0
addresses in yaml configuration, we force to use thisloopback
, because the real eth hostname in hex format (979c83c891fa
,b2c8b40d16de
, etc).Okay, we got correct IP addresses on Eureka server from their clients. But we lost other configurations: urls, ports and so on. That’s why requests to gateway and other communications through Eureka stop working…
We need something like this:
But with new custom
EurekaClientConfig
configuration we have:UPDATE5:
I override bean from autoconfiguration
org.springframework.cloud.netflix.eureka. EurekaClientAutoConfiguration#eurekaInstanceConfigBean()
like this:And now I got next Eureka client registration:
And from container:
It is exactly what I want ☕️ I need to test docker swarm scaling with replicas and my problem looks solved.
UPDATE6:
Finish 🥇 I got this works. Docker swarm service replications and Eureka are friends now.
Even Hystrix Dashboard understands replicas count via
Feign
commucations:At this moment I think I solved my problem with Spring Cloud + Docker Swarm. If not, I let you know 😄