<p>Conditions:
I have a <em>3 tier application</em> to deploy using Kubernetes. I have created <strong>two namespaces</strong> for <em>backend</em> and <em>frontend</em> respectively.</p>
<p>Problem:
I want to know how would my <strong>backend</strong> talk to the <strong>frontend</strong> or vice versa.</p>
<p>In simple words, how do backend and frontend communicate if they are in different namespaces?</p>

Mohit Bhatt
<p>Your application will talk to each other using the <strong>Kubernetes service</strong>.</p>
<p>So generally traffic flows moves inside K8s cluster is like</p>
<pre><code>Incoming traffic to any specifc application &gt; Kubernetes service &gt; Kubernetes deployment &gt; PODs &gt; Containers
</code></pre>
<p>So now imagine all your application running inside on Virutal environment. Where they can talk to each other using just the service name. Instead of using IP now you can use service to resolve to IP automatically. Same we do with <code>www.google.com</code> IP managed by DNS automatically.</p>
<p>For <strong>cross namespace</strong> also you have to give the service name.</p>
<pre><code>service-y.namespace-b.svc.cluster.local
</code></pre>
<p>The <strong>format</strong> will be something like</p>
<pre><code>&lt;servicename&gt;.&lt;namespace&gt;.svc.cluster.local
</code></pre>
<p>where your <code>.svc.cluster.local</code> will be auto appended if don't use also.</p>
<p>Kubernetes service : <a href="https://kubernetes.io/docs/concepts/services-networking/service/" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/services-networking/service/</a></p>
<p>Here is example connecting &amp; deploying the application using different services : <a href="https://kubernetes.io/docs/tutorials/stateful-application/mysql-wordpress-persistent-volume/" rel="nofollow noreferrer">https://kubernetes.io/docs/tutorials/stateful-application/mysql-wordpress-persistent-volume/</a></p>
<p><strong>Service 1</strong> will connect to <strong>service 2</strong> using just by name.</p>
<p>MySQL service name is : <strong>wordpress-mysql</strong></p>
<p>WordPress will get connected to <strong>MySQL</strong> using just service passing to environment.</p>
<pre><code>      - image: wordpress:4.8-apache
        name: wordpress
        env:
        - name: WORDPRESS_DB_HOST
          value: wordpress-mysql
</code></pre>
<p>now if it's another <strong>namespace</strong> you just need to append <strong>namespace</strong> name.</p>
<pre><code>          - image: wordpress:4.8-apache
            name: wordpress
            env:
            - name: WORDPRESS_DB_HOST
              value: wordpress-mysql.my-new-namespace.svc.cluster.local
</code></pre>
