3

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.

Krushna
  • 5,059
  • 5
  • 32
  • 49
  • See here https://stackoverflow.com/questions/40567429/eureka-and-kubernetes. Honestly I personally find Eureka doesn't make much sense when using kubernetes since it already has dns per pod for each service. So you can just use normal RestTemplates. – 123 Jun 11 '20 at 14:02
  • It is a nice suggestion to avoid the use of Eureka in Kubernetes cluster, But I was trying to avoid any code change specifically for Kubernetes, I will look for any solutions if it's there to fix this. – Krushna Jun 12 '20 at 04:56

1 Answers1

2

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

sajux
  • 106
  • 1
  • 8