<p>I am doing a POC on simple microservices architecture using typical Spring cloud stack but instead of Eureka server, service discovery is to be made using spring-cloud-kubernetes which is not working.</p>

<p>The whole POC is here - <a href="https://github.com/dhananjay12/spring-microservices-using-spring-kubernetes" rel="nofollow noreferrer">https://github.com/dhananjay12/spring-microservices-using-spring-kubernetes</a></p>

<p>Gateway as a edge server and 2 downstream services- user-service and contact-us-service.</p>

<p>The k8 setup is in k8s folder.</p>

<p>The downstream services have following dependencies:</p>

<pre class="lang-xml prettyprint-override"><code>&lt;dependency&gt;
            &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
            &lt;artifactId&gt;spring-cloud-starter-kubernetes&lt;/artifactId&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
            &lt;artifactId&gt;spring-cloud-starter-netflix-eureka-client&lt;/artifactId&gt;
        &lt;/dependency&gt;
</code></pre>

<p>application.yml</p>

<pre><code>server:
  port: 8100

management:
  endpoints:
    web:
      exposure:
        include: '*'


spring:
  cloud:
    kubernetes:
      enabled: true
      reload:
        enabled: true
eureka:
  client:
    enabled: false
</code></pre>

<p>bootstrap.yml:</p>

<pre><code>spring:
  application:
    name: user-service
</code></pre>

<p>and annotation of <code>@EnableDiscoveryClient</code> in the main class.</p>

<p>The gateway service has too relevant kubernetes dependencies:</p>

<pre class="lang-xml prettyprint-override"><code>&lt;dependency&gt;
            &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
            &lt;artifactId&gt;spring-cloud-starter-kubernetes&lt;/artifactId&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
            &lt;artifactId&gt;spring-cloud-starter-netflix-ribbon&lt;/artifactId&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
            &lt;artifactId&gt;spring-cloud-starter-kubernetes-ribbon&lt;/artifactId&gt;
        &lt;/dependency&gt;
</code></pre>

<p>application.yml</p>

<pre><code>server:
  port: 8050

spring:
  application:
    name: gateway
  cloud:
    kubernetes:
      enabled: true
      reload:
        enabled: true
    gateway:
      discovery:
        locator:
          lowerCaseServiceId: true
          enabled: true

eureka:
  client:
    enabled: false


logging:
  level:
    root: DEBUG
    org.springframework.gateway: TRACE
    org.springframework.cloud.gateway: TRACE
    org.springframework.cloud.loadbalancer: TRACE


management:
  endpoints:
    web:
      exposure:
        include: '*'


</code></pre>

<p>bootstrap.yml</p>

<pre><code>spring:
  application:
    name: gateway
</code></pre>

<p>and annotation of <code>@EnableDiscoveryClient</code> in the main class.</p>

<p>Please see the deployment and service yaml here - <a href="https://github.com/dhananjay12/spring-microservices-using-spring-kubernetes/tree/master/k8s" rel="nofollow noreferrer">https://github.com/dhananjay12/spring-microservices-using-spring-kubernetes/tree/master/k8s</a></p>

<p>I am able to get to gateway but it is not routing to downstream service like user-service:</p>

<p>For example - /user-service/users/getPublicMailingAddress</p>

<p>gives Whitable error page </p>

<p><a href="https://i.stack.imgur.com/Jn5I7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Jn5I7.png" alt="enter image description here"></a></p>

<p>and the logs in gateway shows:</p>

<pre><code>
2019-07-07 06:40:30.017 TRACE 1 --- [or-http-epoll-2] o.s.c.g.h.p.RoutePredicateFactory : Pattern "[/my-nginx-nginx-ingress-controller/**]" does not match against value "/user-service/users/getPublicMailingAddress"
</code></pre>

Dhananjay
<p>Spring Cloud Kubernetes requires access to the Kubernetes API in order to be able to retrieve a list of addresses for pods running for a single service. If you use Kubernetes, you should just execute the following command:</p>

<pre><code>kubectl create clusterrolebinding admin --clusterrole=cluster-admin --serviceaccount=default:default
</code></pre>
