<p>Im using microservice in kubernete and docker and I got an <code>UnknownHostException</code> when Zuul (gateway) forward request data to service
I can't ping to service container by pod name (but when i use docker swarm instead of Kubernetes, i can ping by host name normally)</p>

<p>This is my service yaml file</p>

<pre><code>apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: merchantservice
  labels:
    run: merchantservice
spec:
  template:
    metadata:
      labels:
        name: merchantservice
    spec:
      containers:
      - name: merchantservice
        image: merchantservice:latest
        ports:
        - containerPort: 8001
        env:
          - name: EUREKA_SERVER
            value: "eureka1"
          - name: EUREKA_SERVER2
            value: "eureka2"
          - name: CONFIG_SERVER
            value: "configserver"
---
apiVersion: v1
kind: Service
metadata:
  name: merchantservice
spec:
  selector:
    name: merchantservice
  ports:
    - port: 8001
      targetPort: 8001
  type: LoadBalancer

</code></pre>

<p>And this is error output</p>

<pre><code>2019-05-28 04:29:53.443  WARN 1 --- [nio-8444-exec-6] o.s.c.n.z.filters.post.SendErrorFilter   : Error during filtering

com.netflix.zuul.exception.ZuulException: Forwarding error
...
Caused by: com.netflix.client.ClientException: null
...
Caused by: java.lang.RuntimeException: java.net.UnknownHostException: merchantservice-79cc77d9cc-224mf: Try again
    at rx.exceptions.Exceptions.propagate(Exceptions.java:57) ~[rxjava-1.3.8.jar!/:1.3.8]
    at rx.observables.BlockingObservable.blockForSingle(BlockingObservable.java:463) ~[rxjava-1.3.8.jar!/:1.3.8]
    at rx.observables.BlockingObservable.single(BlockingObservable.java:340) ~[rxjava-1.3.8.jar!/:1.3.8]
    at com.netflix.client.AbstractLoadBalancerAwareClient.executeWithLoadBalancer(AbstractLoadBalancerAwareClient.java:112) ~[ribbon-loadbalancer-2.3.0.jar!/:2.3.0]
    ... 158 common frames omitted
Caused by: java.net.UnknownHostException: merchantservice-79cc77d9cc-224mf: Try again
...
</code></pre>

Kaijin Sabrac
<p>Make sure that you have added eureka.instance.preferIpAddress = true in your application.properties file of the microservice which has to be routed via zuul.</p>

<p>Reference: <a href="https://cloud.spring.io/spring-cloud-netflix/multi/multi_spring-cloud-eureka-server.html#spring-cloud-eureka-server-prefer-ip-address" rel="nofollow noreferrer">https://cloud.spring.io/spring-cloud-netflix/multi/multi_spring-cloud-eureka-server.html#spring-cloud-eureka-server-prefer-ip-address</a></p>
