<p>I have a single kubernetes service called MyServices which hold four deployments. Each deployment is running as a single pod and each pod has its own port number.</p>

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

<p>As mentioned all the pods are running inside one kubernetes service. </p>

<p>I am able to call the services through the external IP Address of that kubernetes service and port number. </p>

<p><strong>Example : 92.18.1.1:3011/MicroserviceA</strong> Or <strong>92.18.1.1:3012/MicroserviceB</strong></p>

<p>I am now trying to develop and orchestration layer that calls these services and get a response from them, However, I am trying to figure out a way in which I do NOT need to specify every micro-service port number, instead I can call them through their endpoint/ServiceName. Example: <strong>192.168.1.1/MicroserviceA</strong></p>

<p>How can I achieve above statement?</p>

<p>From architecture perspective, is it a good idea to deploy all microservice inside a single kubenetes service (like my current approach) or each micro-service needs it's own service</p>

<p>Below is the kubernetes deployment file ( I removed the script for micro-service C and D since they are identical to A and B):</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: myservice
spec:
  selector:
    app: microservice
  ports:
    - name: microserviceA
      protocol: TCP
      port: 3011
      targetPort: 3011
    - name: microserviceB
      protocol: TCP
      port: 3012
      targetPort: 3012
    - name: microserviceC
      protocol: TCP
      port: 3013
      targetPort: 3013
    - name: microserviceD
      protocol: TCP
      port: 3014
      targetPort: 3014
  type: LoadBalancer
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: microserviceAdeployment
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: microservice
    spec:
      containers:
      - image: dockerhub.com/myimage:v1
        name: microservice
        ports:
        - containerPort: 3011
      imagePullSecrets:
      - name: regcred
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: microserviceBdeployment
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: microservice
    spec:
      containers:
      - image: dockerhub.com/myimage:v1
        name: microservice
        ports:
        - containerPort: 3012
</code></pre>

<p>There is a way to <a href="https://stackoverflow.com/a/39260160/6309">discover all the port of Kubernetes services</a>.</p>

<p>So you could consider using <code>kubectl get svc</code>, as seen in "<a href="https://kubernetes.io/docs/tutorials/services/source-ip/#source-ip-for-services-with-type-nodeport" rel="nofollow noreferrer">Source IP for Services with Type=NodePort</a>"</p>

<pre><code>NODEPORT=$(kubectl get -o jsonpath="{.spec.ports[0].nodePort}" services &lt;yourService&gt;)
</code></pre>

<hr>

<blockquote>
  <p>, I am trying to figure out a way in which I do NOT need to specify every micro-service port number, instead I can call them through their endpoint/ServiceName</p>
</blockquote>

<p>Then you need to expose those services through one entry point, typically a reverse-proxy like NGiNX.<br>
The idea is to expose said services using the default ports (80 or 443), and reverse-proxy them to the actual URL and port number.</p>

<p>Check "<a href="https://www.nginx.com/blog/service-discovery-in-a-microservices-architecture/" rel="nofollow noreferrer">Service Discovery in a Microservices Architecture</a>" for the general idea.</p>

<p><a href="https://i.stack.imgur.com/QoMZg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QoMZg.png" alt="https://cdn-1.wp.nginx.com/wp-content/uploads/2016/04/Richardson-microservices-part4-1_difficult-service-discovery.png"></a></p>

<p>And "<a href="https://www.nginx.com/blog/service-discovery-nginx-plus-etcd/" rel="nofollow noreferrer">Service Discovery for NGINX Plus with etcd</a>" for an implementation (using NGiNX plus, so could be non-free).<br>
Or "<a href="https://hackernoon.com/setting-up-nginx-ingress-on-kubernetes-2b733d8d2f45" rel="nofollow noreferrer">Setting up Nginx Ingress on Kubernetes</a>" for a more manual approach.</p>
