<p>I am running into issues with Kubernetes Service Discovery on Spring Boot applications. </p>

<p>I should be able to discover the services whether my spring boot application is running within or out of Kubernetes cluster. Our local development won't be on k8s cluster.</p>

<p>I am using Service Discovery via DNS. I tried using <a href="https://github.com/spring-cloud-incubator/spring-cloud-kubernetes" rel="nofollow noreferrer">spring-cloud-starter-kubernetes</a></p>

<pre><code>    &lt;dependency&gt;
        &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
        &lt;artifactId&gt;spring-cloud-starter-kubernetes&lt;/artifactId&gt;
        &lt;version&gt;0.2.0.RELEASE&lt;/version&gt;
    &lt;/dependency&gt;
</code></pre>

<p>As per documentation you should be able to autowire DiscoveryClient and good to go</p>

<pre><code>@Autowire
private DiscoveryClient discoveryClient;
</code></pre>

<p>DiscoveryClient is part of spring-cloud-commons. spring-cloud-starter-kuberenetes doesn't have it. </p>

<p>Anyone solved similar problem using the same library or a different one? Please share the solution</p>

<p>Thanks!</p>

<p>I have solved this issue using the Spring Cloud Kubernetes Dependencies</p>

<p><code>&lt;spring.cloud.kubernetes&gt;0.2.0.RELEASE&lt;/spring.cloud.kubernetes&gt;</code></p>

<pre><code>&lt;dependency&gt;
        &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
        &lt;artifactId&gt;spring-cloud-kubernetes-ribbon&lt;/artifactId&gt;
        &lt;version&gt;${spring.cloud.kubernetes}&lt;/version&gt;
    &lt;/dependency&gt;

    &lt;dependency&gt;
        &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
        &lt;artifactId&gt;spring-cloud-kubernetes-config&lt;/artifactId&gt;
        &lt;version&gt;${spring.cloud.kubernetes}&lt;/version&gt;
    &lt;/dependency&gt;

    &lt;dependency&gt;
        &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
        &lt;artifactId&gt;spring-cloud-kubernetes-core&lt;/artifactId&gt;
        &lt;version&gt;${spring.cloud.kubernetes}&lt;/version&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
        &lt;artifactId&gt;spring-cloud-kubernetes-discovery&lt;/artifactId&gt;
        &lt;version&gt;${spring.cloud.kubernetes}&lt;/version&gt;
    &lt;/dependency&gt;
</code></pre>

<p>What was very important for me was the ribbon dependency as it makes use of a load balanced rest template in order to substitute service names for the correct pod IP's that are found in your kubernetes cluster.</p>

<p>I have created a git repo as part of answering a larger set of questions but it should be more than sufficient if someone is looking a way to implement Kubernetes service discovery in place of Eureka or Consul.</p>

<p><a href="https://github.com/foundery-rmb/kubernetes-service-discovery" rel="nofollow noreferrer">https://github.com/foundery-rmb/kubernetes-service-discovery</a></p>
