<p>Assuming I have two services: customerService and orderService. Both are Springboot applications contained in its own dockerfile.</p>
<p>In production they should be managed using Kubernetes. So there could be mutliple instances of each service. As the services should be able to call each other via REST I want to use ServiceDiscovery to get the destination of a service instance of the respective other type (e.g. customerService wants to get host, port, etc. of a running orderService instance).</p>
<p>I want to achieve this by using an injected DiscoveryClient in my Spring Boot services.</p>
<p>I understand how this works in production as there is the Kubernetes cluster the DiscoveryClient communicates with.</p>
<p>But how does this work in a local environment where there is no Kubernetes but only Docker running?</p>

<p>I think you should be looking into <strong>Kubernetes services</strong> instead of using an injected Discovery client.</p>
<p>For Service discovery and load-balancing, you can use Services in Kubernetes. From Kubernetes documentation:</p>
<blockquote>
<p>An abstract way to expose an application running on a set of Pods as a
network service. With Kubernetes, you don't need to modify your
application to use an unfamiliar service discovery mechanism.
Kubernetes gives Pods their own IP addresses and a single DNS name for
a set of Pods and can load-balance across them.</p>
</blockquote>
<p>By this, you can also avoid the overhead of maintaining discovery server instances and their availability.</p>
<p><em>How does this work in a local environment where there is no Kubernetes but only Docker running?</em></p>
<p>You can use <strong>spring profiles for picking this URL based on your environment</strong>.</p>
<p>For example, you'll have two spring configuration files (application-dev, application-prod) and in the dev file the URL for the second application would be localhost relative and in the prod file, the URL would be the DNS which you'll get as a part of Kubernetes service setup. So use the profile dev while running in local and prod while running in production(or an appropriate profile for your Kubernetes environment).</p>
