Eureka service can not be found when running in Docker Container - spring

So I have a very simple setup of a Eureka server and one service. When running locally with tomcat everything works perfect. However, when I run these locally in docker containers.. the service registers to the eureka server but whenever I make the http calls via FeignClient it says there is no load balance for the service (Cant find service). It acts as if the service can find the eureka server but the server can not find the service. And once again, only broken when runnind in docker containers.
My Eureka server
spring.application.name=eureka-service
server.port=8761
eureka.client.fetch-registry=false
eureka.client.register-with-eureka=false
My Service
spring.application.name=users-service
server.port=8081
eureka.client.register-with-eureka=true
eureka.client.fetch-registry=false
eureka.instance.prefer-ip-address=true
eureka.client.service-url.defaultZone=http://**EurekaServerIp**:8761\eureka

I was able to fix it by making sure my Eureka server, Services and Zuul gateway were running on the same (Overlay) docker network. However, I now need to find a way to only make the zuul gateway accessible from outside the network, and protect all the services.
EDIT: I found a very easy way to expose gateways and hide services with docker --link, here is a good article https://exampledriven.wordpress.com/2016/06/24/spring-boot-docker-example/

Related

Register on eureka server on a different machine

I have a microservice architecture in developement mode with an API Gateway running on localhost:8080, some services on localhost:8081...8084 and an eureka server on localhost:8761.
The services register with eureka and everything works fine on my local machine.
I'm trying to deploy the services to azure as single containers. So each service will end up with a unique url.
How can I tell my eureka clients (api gateway and services) where the eureka server is running?
No matter what I try, it will always try to find the eureka server at localhost:8761. These are my settings for the API gateway:
eureka:
instance:
instance-id: ${spring.application.name}:${random.uuid}
client:
service-url:
default-zone: ${EUREKA_HOST:http://localhost:8761}/eureka/
I always end up with this error:
How can I get the services to connect to a eureka server that runs on something like https://example.azurewebsites.net:8761 ? The variable EUREKA_HOST has the correct value since I can use it at other places without problem.

Spring boot micro service Deployment

I am new to Micro services architecture.. I want know if it is required to deploy all Spring boot micro services in the same local network ..? As Eureka Discovery service uses Private/Internal IP Address for Registration , i am unable to call a services from another service deployed in different local network...
Please let me know how micro services deployed across multiple Sub nets should communicate each other in this case
or is there a way to tell eureka to use only public IP Address..?
Not sure if this would help, but by default, your eureka client will try to connect to the default localhost:8761 where the eureka discovery server should exist.
In case you have a different location for your discovery-service you can use the following in the application.properties file in your client services.
eureka.client.service-url.defaultZone=http://{address}-{port}/eureka

Programmatically find Eureka server host and port

I want to setup Eureka server for service registry and erueka clients that will get access rest api using the service registry from Eureka server. But we use mesos as our container management system and when we start the Eureka server we will not know which host and port it is running on. So there is an api that we can use that gives us the complete url where Eureka server will be running. Now all the examples for Eureka client that I have seen have hard coded the Eureka server in the config file. Is it possible for Eureka clients to use that api and get the url for Eureka server.
FYI: we are using spring boot and have our own DC and are not on any cloud
I think I found the answer but if someone can confirm that will be great. I need to create my own EurekaClientConfigBean and override the following methods:
public void setEurekaServiceUrlPollIntervalSeconds(int eurekaServiceUrlPollIntervalSeconds)
List<String> getEurekaServerServiceUrls(String zone);

Problems setting up Zuul proxy server with Eureka discovery

I am trying to set up a zuul proxy server which will act as a gateway service for other apis in my microservice architecture.
So far all the tutorials that I have come across have the discovery client and zuul proxy set up in different gradle modules while I am trying to set them up in the same gradle module.
I have defined the routes and can see that my services have been successfully registered in the eureka dashboard.
I have also verified that I can ping the services using a discovery client from my gatekeeper service but whenever I try to access the services from the URL, I get
"Load balancer does not have available server for client:xyz"
exception.
Can somebody please help me setting this up?

Eureka service discovery not working in Azure

I have 2 micro-services that register with Eureka. I run the projects locally and call one micro-service from another using Feign & Ribbon and everything works fine.
However when I deploy everything to Azure it no longer works.
I can see the services registered in eureka dashboard but when I click on a particular service I get an url like this http://100.79.xxxx.xx:xxxx and after loading for a while I get a connection timeout. Same happens in code when one micro-service calls the other through Eureka.
I also added this setting to eureka clients but it didn't help:
eureka.instance.prefer-ip-address: false
It seems that the IP addresses of services instances are not reachable.
Is there a way to make Eureka work on Azure? Thanks for your help.

Resources