Spring boot microservices are getting registered to Eureka with the pod name as the hostname in the Kubernetes cluster - docker desktop - spring

The microservices are getting registered to Eureka with the pod name as hostname, this causing UnknownHostException, when the Zull API gateway trying to forward the request to the service.
The complete setup working fine with the docker-compose, the issues are happening when I am trying to use the Kubernetes.
For example, the order microservice running with the pod name as "oc-order-6b64576f4b-7gp85" and the order microservice getting register to to Eureka with "oc-order-6b64576f4b-7gp85" as the hostname. Which is causing
java.net.UnknownHostException: oc-order-6b64576f4b-7gp85: Name does not resolve
I am running just one instance of each micro-services as a POC and one instance of the Eureka server. How to fix, how micro-service can register them self with the right hostname.
I want to use the Eureka as discovery service as it is well integrated with spring boot and I do not want to do code changes for Kubernetes deployment.

Add the below property to your spring properties file in each service project:
eureka.instance.hostName=${spring.application.name}
or (if you want a different name than the spring application name)
eureka.instance.hostName=<custom-host-name>
Spring boot will now register with the provided hostname in Eureka

Related

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

Spring Cloud Eureka Server : how does Eureka server knows what microservices instances are up?

I am working on Spring cloud framework. So each of my microservices will have to register with Eureka server, so Eureka knows the unique id or the application name.
(1) I have to have more than one instance of same microservice to be registered with Eureka, How do I achieve that? Microservice is deployed in Cloud Foundry.
(2) When all those instances from same microservices are registered with Eureka, how does Eureka know which instances are active and which not? How often Eureak knows and how Eureka gets this information.
Each instance sends are heartbeat to the eureka server, by default every 30 seconds.

Spring Boot Admin server on Cloud Foundry with SimpleDiscoveryClient

I am trying to setup a Spring Boot Admin server on a Cloud foundry. I am using the client Spring Cloud Discovery with SimpleDiscoveryClient configuration. We are not having any Thrid Party service discovery client like eureka. I can see the service getting registered to the spring boot admin server. But when i scale up any service, i see only one instance of that service and the actual number of instances are not reflected. I would like to know if that is possible without Eureka or any other service discovery, if yes how to achieve that without them.
Thanks

Registering Spring Cloud Microservice with Eureka server

I am trying to create spring cloud microservices and also need to include eureka server and zuul as spring cloud tools. Now I created one module in my one spring boot project. I registered that service with eureka server. And also I created one spring boot project for adding zuul service discovery and also registered with eureka project.
Here my doubt is that When I am adding another module as another spring boot project, Can I register that application also with my current eureka server as client? What type of relation that eureka server project and microservice having? one-To-One or One-To-Many? Can I register 3 or 4 microservices with one eureka server as client?
Eureka Server will let you add as many microservices (modules of spring boot projects like you said).
From Spring Cloud landing page:
As long as Spring Cloud Netflix and Eureka Core are on the classpath
any Spring Boot application with #EnableEurekaClient will try to
contact a Eureka server on http://localhost:8761 (the default value of
eureka.client.serviceUrl.defaultZone):
That means that you can use a single eureka server for multiple microservices which are registered as clients to the eureka server.
So yes, it's a One-To-Many relationship.
You will want at one point to look into multiple Eureka servers used in load balancing, for redundancy purposes, but for now you will be fine.

Spring cloud registering multiple instances of same service

I am developing a microservice, using Spring Boot, that exposes REST Endpoint. Because of scalability, I have to run multiple instances of this services on a different port. What will be the configurations for the applications so that it can register with eureka and requests are load balanced? I am using Spring cloud config, Eureka server and zuul.
Attaching following entries in the client properties file will do the trick. This is for Spring cloud config dalston
eureka.instance.instanceId=${spring.application.name}:${spri‌​ng.application.insta‌​nce_id:${random.valu‌​e}}
I guess you meant to register with Eureka instead of Config server.
To register multiple instances that might be running in the same host but listening on a different port you would need to set eureka.instance.metadataMap.instanceId to a unique value maybe using:
eureka.instance.metadataMap.instanceId=${spring.application.name}:${random.int}

Resources