title: DiscoveryClient_USER-AUTH/user-auth-66b764457c-k628h:USER-AUTH:5071 - registration failed Cannot execute request on any known server
body: <p>I'm currently working on my microservices project with java spring boot.
  I dockerized everything correctly, but as soon as I try to implement everything on <strong>Kubernetes</strong> it starts to give me problems.</p>
  <p>I run the command <code>kubectl logs mypodname</code> to look at the error and it prints me the following:</p>
  <pre><code> 2022-06-03 18:36:38.082  INFO 1 --- [freshExecutor-0] com.netflix.discovery.DiscoveryClient    : Getting all instance registry info from the eureka server
   2022-06-03 18:36:38.103  INFO 1 --- [tbeatExecutor-0] c.n.d.s.t.d.RedirectingEurekaHttpClient  : Request execution error. endpoint=DefaultEndpoint{ serviceUrl='http://localhost:8761/eureka/}, exception=I/O error on PUT request for &quot;http://localhost:8761/eureka/apps/USER-AUTH/user-auth-66b764457c-k628h:USER-AUTH:5071&quot;: Connect to localhost:8761 [localhost/127.0.0.1] failed: Connection refused; nested exception is org.apache.http.conn.HttpHostConnectException: Connect to localhost:8761 [localhost/127.0.0.1] failed: Connection refused stacktrace=org.springframework.web.client.ResourceAccessException: I/O error on PUT request for &quot;http://localhost:8761/eureka/apps/USER-AUTH/user-auth-66b764457c-k628h:USER-AUTH:5071&quot;: Connect to localhost:8761 [localhost/127.0.0.1] failed: Connection refused; nested exception is org.apache.http.conn.HttpHostConnectException: Connect to localhost:8761 [localhost/127.0.0.1] failed: Connection refused
      at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:785)
      at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:711)
      at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:602)
      at org.springframework.cloud.netflix.eureka.http.RestTemplateEurekaHttpClient.sendHeartBeat(RestTemplateEurekaHttpClient.java:99)
      at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$3.execute(EurekaHttpClientDecorator.java:92)
      at com.netflix.discovery.shared.transport.decorator.RedirectingEurekaHttpClient.executeOnNewServer(RedirectingEurekaHttpClient.java:121)
      at com.netflix.discovery.shared.transport.decorator.RedirectingEurekaHttpClient.execute(RedirectingEurekaHttpClient.java:80)
      at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.sendHeartBeat(EurekaHttpClientDecorator.java:89)
      at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$3.execute(EurekaHttpClientDecorator.java:92)
      at com.netflix.discovery.shared.transport.decorator.RetryableEurekaHttpClient.execute(RetryableEurekaHttpClient.java:120)
      at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.sendHeartBeat(EurekaHttpClientDecorator.java:89)
      at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$3.execute(EurekaHttpClientDecorator.java:92)
      at com.netflix.discovery.shared.transport.decorator.SessionedEurekaHttpClient.execute(SessionedEurekaHttpClient.java:77)
      at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.sendHeartBeat(EurekaHttpClientDecorator.java:89)
      at com.netflix.discovery.DiscoveryClient.renew(DiscoveryClient.java:893)
      at com.netflix.discovery.DiscoveryClient$HeartbeatThread.run(DiscoveryClient.java:1457)
      at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
      at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
      at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
      at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
      at java.base/java.lang.Thread.run(Thread.java:830)
     Caused by: org.apache.http.conn.HttpHostConnectException: Connect to localhost:8761 [localhost/127.0.0.1] failed: Connection refused
      at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:156)
      at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:376)
      at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:393)
      at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
      at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:186)
      at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
      at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
      at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
      at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)
      at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56)
      at org.springframework.http.client.HttpComponentsClientHttpRequest.executeInternal(HttpComponentsClientHttpRequest.java:87)
      at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48)
      at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:66)
      at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:776)
      ... 20 more
    Caused by: java.net.ConnectException: Connection refused
      at java.base/sun.nio.ch.Net.connect0(Native Method)
      at java.base/sun.nio.ch.Net.connect(Net.java:493)
      at java.base/sun.nio.ch.Net.connect(Net.java:482)
      at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:588)
      at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:339)
      at java.base/java.net.Socket.connect(Socket.java:585)
      at org.apache.http.conn.socket.PlainConnectionSocketFactory.connectSocket(PlainConnectionSocketFactory.java:75)
      at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142)
      ... 33 more
  
   2022-06-03 18:36:38.103  INFO 1 --- [freshExecutor-0] c.n.d.s.t.d.RedirectingEurekaHttpClient  : Request execution error. endpoint=DefaultEndpoint{ serviceUrl='http://localhost:8761/eureka/}, exception=I/O error on GET request for &quot;http://localhost:8761/eureka/apps/&quot;: Connect to localhost:8761 [localhost/127.0.0.1] failed: Connection refused; nested exception is org.apache.http.conn.HttpHostConnectException: Connect to localhost:8761 [localhost/127.0.0.1] failed: Connection refused stacktrace=org.springframework.web.client.ResourceAccessException: I/O error on GET request for &quot;http://localhost:8761/eureka/apps/&quot;: Connect to localhost:8761 [localhost/127.0.0.1] failed: Connection refused; nested exception is org.apache.http.conn.HttpHostConnectException: Connect to localhost:8761 [localhost/127.0.0.1] failed: Connection refused
      at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:785)
      at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:711)
      at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:602)
      at org.springframework.cloud.netflix.eureka.http.RestTemplateEurekaHttpClient.getApplicationsInternal(RestTemplateEurekaHttpClient.java:145)
      at org.springframework.cloud.netflix.eureka.http.RestTemplateEurekaHttpClient.getApplications(RestTemplateEurekaHttpClient.java:135)
      at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$6.execute(EurekaHttpClientDecorator.java:137)
      at com.netflix.discovery.shared.transport.decorator.RedirectingEurekaHttpClient.executeOnNewServer(RedirectingEurekaHttpClient.java:121)
      at com.netflix.discovery.shared.transport.decorator.RedirectingEurekaHttpClient.execute(RedirectingEurekaHttpClient.java:80)
      at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.getApplications(EurekaHttpClientDecorator.java:134)
      at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$6.execute(EurekaHttpClientDecorator.java:137)
      at com.netflix.discovery.shared.transport.decorator.RetryableEurekaHttpClient.execute(RetryableEurekaHttpClient.java:120)
      at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.getApplications(EurekaHttpClientDecorator.java:134)
      at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$6.execute(EurekaHttpClientDecorator.java:137)
      at com.netflix.discovery.shared.transport.decorator.SessionedEurekaHttpClient.execute(SessionedEurekaHttpClient.java:77)
      at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.getApplications(EurekaHttpClientDecorator.java:134)
      at com.netflix.discovery.DiscoveryClient.getAndStoreFullRegistry(DiscoveryClient.java:1101)
      at com.netflix.discovery.DiscoveryClient.fetchRegistry(DiscoveryClient.java:1014)
      at com.netflix.discovery.DiscoveryClient.refreshRegistry(DiscoveryClient.java:1531)
      at com.netflix.discovery.DiscoveryClient$CacheRefreshThread.run(DiscoveryClient.java:1498)
      at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
      at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
      at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
      at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
      at java.base/java.lang.Thread.run(Thread.java:830)
    Caused by: org.apache.http.conn.HttpHostConnectException: Connect to localhost:8761 [localhost/127.0.0.1] failed: Connection refused
      at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:156)
      at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:376)
      at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:393)
      at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
      at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:186)
      at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
      at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
      at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
      at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)
      at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56)
      at org.springframework.http.client.HttpComponentsClientHttpRequest.executeInternal(HttpComponentsClientHttpRequest.java:87)
      at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48)
      at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:66)
      at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:776)
      ... 23 more
   Caused by: java.net.ConnectException: Connection refused
      at java.base/sun.nio.ch.Net.connect0(Native Method)
      at java.base/sun.nio.ch.Net.connect(Net.java:493)
      at java.base/sun.nio.ch.Net.connect(Net.java:482)
      at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:588)
      at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:339)
      at java.base/java.net.Socket.connect(Socket.java:585)
      at org.apache.http.conn.socket.PlainConnectionSocketFactory.connectSocket(PlainConnectionSocketFactory.java:75)
      at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142)
      ... 36 more
  </code></pre>
  <p>I've tried to change the yml regarding this microservice, but nothing happens.</p>
  <p><strong>application-properties.yml</strong></p>
  <pre><code> spring:
     servlet:
     multipart:
       max-file-size: 10MB
       max-request-size: 10MB
     application:
       name: USER-AUTH
     datasource:
       username: 'littleshops'
       password: 'littleshops'
       url: jdbc:mysql://localhost:3306/users?useUnicode=true&amp;useJDBCCompliantTimezoneShift=true&amp;useLegacyDatetimeCode=false&amp;serverTimezone=UTC
    jpa:
      properties:
        hibernate:
          dialect: org.hibernate.dialect.MySQL5InnoDBDialect
          naming-strategy: org.hibernate.cfg.ImprovedNamingStrategy
      show-sql: false
      hibernate:
        ddl-auto: update
    mvc:
      throw-exception-if-no-handler-found: true
    web:
      resources:
        add-mappings: false
  
    server:
      port: 5071
      error:
        whitelabel:
          enabled: false
  
  eureka:
    instance:
      prefer-ip-address: true
      hostname: localhost
  client:
     register-with-eureka: true
     fetch-registry: true
     service-url:
        defaultZone: ${EUREKA_URI:http://localhost:8761/eureka}
   ---
  
   spring:
     datasource:
       username: ${spring_datasource_username}
       password: ${spring_datasource_password}
       url: ${spring_datasource_url}
  
  
   jwt:
     secret: 'mysecret'
  </code></pre>
  <p><strong>kubernetes.yml</strong></p>
  <pre><code>apiVersion: v1
  kind: ConfigMap
  metadata:
    name: spring-config
  data:
    dev-config.json:
    '{
      &quot;spring.datasource.url&quot;: &quot;jdbc:mysql://db-user:3308/users?useUnicode=true&amp;useJDBCCompliantTimezoneShift=true&amp;useLegacyDatetimeCode=false&amp;serverTimezone=UTC&quot;,
     &quot;spring.datasource.username&quot;: &quot;myusername&quot;,
     &quot;spring.datasource.password&quot;: &quot;mypassword&quot;
    }'
   ---
  apiVersion: apps/v1
  kind: Deployment
  metadata:
    name: user-auth
    labels:
      app: user-auth
  spec:
    replicas: 1
    template:
     metadata:
      name: user-auth
      labels:
        app: user-auth
     spec:
        containers:
          - env:
            - name: SPRING_APPLICATION_JSON
              valueFrom:
                configMapKeyRef:
                  key: dev-config.json
                  name: spring-config
            name: user-auth
            image: hassanmarji96/user-auth
            imagePullPolicy: Always
            ports:
             - containerPort: 5071
            resources:
                 {}
        restartPolicy: Always
     selector:
        matchLabels:
          app: user-auth
  
     ---
    apiVersion: v1
    kind: Service
    metadata:
      name: user-auth-svc
    spec:
     selector:
         app: user-auth
       type: ClusterIP
       ports:
         - port: 80
           targetPort: 5071
  </code></pre>
  <p>Even if Eureka doesn't recognize the microservice, the microservice itself works..
  I've tried even to add a / at the end of the defaultZone attribute but nothing.</p>
  <p>This is the link to my repo: <a href="https://github.com/hassanmarji96/Backend_Littleshops" rel="nofollow noreferrer">https://github.com/hassanmarji96/Backend_Littleshops</a></p>