title: Service discovery with microservices in kubernetes
body: <p>I've been reading a lot about microservices and kubernetes a lot lately, and also experimenting with the two technologies.
  I am aware of the different pieces available in k8s such as pods, services, deployments...
  I am also aware that services can be of type ClusterIP to restrict connectivity to within the cluster.</p>
  
  <p>Let's say we have 10 microservices that each expose its functionality using some kind of http server. Basically each microservice is a REST API.
  In kubernetes terms, this would be a container managed by a Pod and there would be a Service managing this Pod's connectivity.</p>
  
  <p>My question is the following:
  If you are not using a framework such as Spring that utilizes Eureka, for example bare bone golang http server in each microservice. How does each service find the other service without passing the service name and port number to each microservice.</p>
  
  <p>For example:
  Let's say Service A is exposed on port 8080 which needs to call Service B which is exposed on port 8081 and another service which is running on port 8082; this means that we need to pass the ports as environment variables to Service A...You can clearly see that when the number of services increases, it will be hard maintaining all of these environment variables.</p>
  
  <p>How do people solve such a problem? do they use some kind of centralized service registry? if yes then how would that service registry integrate with the kubernetes Service?</p>
  
  <p>Thanks in advance</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>The provided accepted answer is spot on with the explanation, the thing that I was failing to see is that for example in kubernetes, typically each deployment object has its own IP address so it's okay to use the same port number for each microservice.</p>
  
  <p>In case anyone is interested with a simple/dummy microservice example, I put together a small project that can be run on a local kubernetes cluster with minikube.</p>
  
  <p><a href="https://github.com/fouadkada/simple_microservice_example" rel="nofollow noreferrer">https://github.com/fouadkada/simple_microservice_example</a></p>