<p>I have a service (CusterIP) like following which is exposing ports of backend POD.</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: fsimulator
  namespace: myns
spec:
  type: ClusterIP
  selector:
    application: oms
  ports:
    - name: s-port
      port: 9780
    - name: b-port
      port: 8780
</code></pre>

<p>Front end POD  should be able to connect to Backend POD using service. Should we replace hostname with service name to connect from Frontend POD to Backend POD ?</p>

<p>I have to supply the service name and port through environment variables to Frontend POD container.
The enviroment variables are set using configMap.</p>

<p>Is it enough to give service name fsimulator as hostname to connect to ?
How to give service if is created inside namespace ? </p>

<p>Thanks </p>

<p>Check out <a href="https://kubernetes.io/docs/concepts/services-networking/service/#discovering-services" rel="nofollow noreferrer">this documentation</a>. The internal service PORT / IP pairs for active services are indeed passed into the containers <em>by default</em>.</p>

<p>As the documentation also says, it is possible (recommended) to use a DNS cluster add-on for service discovery. Accessing <code>service.namespace</code> from outside / inside a service will resolve to the correct service route (or just <code>service</code> from inside the namespace). This is usually the right path to take.</p>

<p>Built-in service discovery is a huge perk of using Kubernetes, use the available tools if at all possible!</p>
