<p>I'm trying to develop a sample application using spring cloud and minikube which consist of 3 spring boot applications.</p>

<p>The first two are two different application (servers) which have the same endpoint but different functionality, and the third one is a client used to integrates the two other applications into one single exposed api.</p>

<p>I managed to deploy all three applications in minikube and managed to develop the full stack and make them communicate between each other, but now I want to go a step further and make the discovery of the two servers automatically, without hard coding the service names.</p>

<p>I deployed the two servers in minikube using the same label and would like to find something so that the client is able to find the services related to the two server apps automatically. This will allow expanding the application easily, so that when I add a new server to the stack the client will find it and expose it without need of any change.</p>

<p>Using Netflix Eureka this can be easily achieved by using something like </p>

<pre><code>discoveryClient.getInstances("service-name").forEach((ServiceInstance s)
</code></pre>

<p>But I do no want to add an extra eureka server to the list of microservices since we are going to use kubernetes.</p>

<p>Is there any library which gives this functionality for kubernetes?</p>

<p>You can use:</p>

<p>CLI: <code>kubectl get services --selector=YOUR-LABEL-NAME</code>.</p>

<p>API: <code>GET /api/v1/namespaces/{namespace}/services</code> with <code>labelSelector</code> parameter see <a href="https://kubernetes.io/docs/api-reference/v1.6/#list-161" rel="nofollow noreferrer">API docs</a>.</p>

<p>However be careful with dynamic service discovery inside services. As derSteve mentions in the comments below - The best practice for dependencies between services is to deploy them as logical bundles called <code>deployments</code> for which it is not necessary to perform discovery of previously unknown services. See this <a href="https://kubernetes.io/docs/concepts/workloads/controllers/deployment/" rel="nofollow noreferrer">link</a>. </p>
