<p>I have 2 Springboot microservices, one is the Eureka server and the other one is the Gateway.</p>
<p>I can't find the right configuration to make the Gateway register to the Eureka server.</p>
<p>This is the <code>eureka.yml</code> with the K8s configuration:</p>
<p><strong>Eureka.yml</strong></p>
<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: eureka-cm
data:
  eureka_service_address: http://eureka-0.eureka:8761/eureka

---

apiVersion: v1
kind: Service
metadata:
  name: eureka
  labels:
    app: eureka
spec:
  clusterIP: None
  ports:
    - port: 8761
      name: eureka
  selector:
    app: eureka

---

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: eureka
spec:
  serviceName: &quot;eureka&quot;
  replicas: 1
  selector:
    matchLabels:
      app: eureka
  template:
    metadata:
      labels:
        app: eureka
    spec:
      containers:
        - name: eureka
          image: myrepo/eureka1.0:eureka
          imagePullPolicy: Always
          ports:
            - containerPort: 8761
          env:
            - name: EUREKA_SERVER_ADDRESS
              valueFrom:
                configMapKeyRef:
                  name: eureka-cm
                  key: eureka_service_address


---                  

apiVersion: v1
kind: Service
metadata:
  name: eureka-lb
  labels:
    app: eureka
spec:
  selector:
    app: eureka
  type: NodePort
  ports:
    - port: 80
      targetPort: 8761
</code></pre>
<p><strong>Eureka.application.yml</strong></p>
<pre><code>spring:
  application:
    name: eureka
server:
  port: 8761
eureka:
  instance:
    hostname: &quot;${HOSTNAME}.eureka&quot;
  client:
    register-with-eureka: false
    fetch-registry: false
    serviceUrl:
      defaultZone: ${EUREKA_SERVER_ADDRESS}
</code></pre>
<p><strong>Gateway.yml</strong></p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: cloud-gateway-app
  labels:
    app: cloud-gateway-app
spec:
  replicas: 1
  selector:
    matchLabels:
      app: cloud-gateway-app
  template:
    metadata:
      labels:
        app: cloud-gateway-app
    spec:
      containers:
        - name: cloud-gateway-app
          image: myrepo/gateway1.0:gateway
          imagePullPolicy: Always
          ports:
            - containerPort: 9191

---
apiVersion: v1
kind: Service
metadata:
  name: cloud-gateway-svc
spec:
  type: LoadBalancer
  ports:
    - port: 80
      targetPort: 9191
      protocol: TCP
  selector:
    app: cloud-gateway-app
</code></pre>
<p><strong>Gateway.application.yml</strong></p>
<pre><code>eureka:
  instance:
    preferIpAddress: true
    hostname: eureka-0
  client:
    registerWithEureka: true
    fetchRegistry: true
    serviceUrl:
      defaultZone: http://eureka-0.eureka.default.svc.cluster.local:8761/eureka
</code></pre>
<p>This is the error I got when I check the logs of the Gateway's pod:</p>
<pre><code>error on POST request for &quot;http://eureka-0.eureka.default.svc.cluster.local:8761/eureka/apps/API-GATEWAY&quot;: eureka-0.eureka.default.svc.cluster.local; nested exception is java.net.UnknownHostException: eureka-0.eureka.default.svc.cluster.local
</code></pre>
<p>Following the documentation I've tried to set <code>defaultZone</code> property of the <strong>Gateway.application.properties</strong> file following this pattern:</p>
<pre><code>172-17-0-3.default.pod.cluster.local:8761/eureka
</code></pre>
<p>But in this way too, I can't subscribe to the Eureka Server.</p>

<p>I resolved by modifying the Gateway.application.yml in this way:</p>
<pre><code>eureka:
  instance:
    preferIpAddress: true
    hostname: eureka-0
  client:
    registerWithEureka: true
    fetchRegistry: true
    serviceUrl:
      defaultZone: http://eureka-0.eureka:8761/eureka/
</code></pre>
<p>EDIT:</p>
<p>I'm encountering some problems in registering other microservices to the Eureka Server.
I've tried by increasing the replicas of the Eureka Server and made each microservice register to a dedicated replica, but as now this is not working.</p>
