<p>I have a Kubernetes cluster with two namespaces, <code>dbns</code> (where a database lives) and <code>jobland</code> (where jobs run from).</p>
<p>I would like to run a <code>Job</code> from a container running in the <code>jobland</code> namespace that will connect to and run scripts against a DB living in the <code>dbns</code> namespace.</p>
<p>When I run <code>get pod,statefulset,svc,configmap -o wide</code> I see that my DB has an IP of <code>10.1.0.34</code>, but I'm assuming thats only &quot;reachable&quot; from other containers running inside the <code>dbns</code> namespace, correct? If so, how could I expose its IP so that items from outside the <code>dbns</code> namespace can connect to it (such as something running in <code>jobland</code>)?</p>

simplezarg
<p>If you are exposing your objects (pods, deployments, etc) using a K8S service you can expose them outside namespaces with an IP or with FQDN</p>
<p>Here is an example of how to do it:<br />
<a href="https://github.com/nirgeier/KubernetesLabs/tree/master/Labs/05-Services#0403-using-the-full-DNS-name" rel="nofollow noreferrer">https://github.com/nirgeier/KubernetesLabs/tree/master/Labs/05-Services#0403-using-the-full-DNS-name</a></p>
<hr />
<ul>
<li><p>As a best practice you should not rely on the Cluster IP since it can change and will &quot;break&quot; your connectivity.</p>
</li>
<li><p>The recommended way is as mentioned above to use the FDDN which is automatically created for you once you add the <code>Service</code> object to your namespace and resource.</p>
</li>
</ul>
<p><a href="https://i.stack.imgur.com/HkKEo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HkKEo.png" alt="enter image description here" /></a></p>
<p>The name (FQDN) will be the same regardless of the IP and cluster which your code are deployed to.</p>
<p>You can verify this name, for example:
<a href="https://i.stack.imgur.com/Fq8Sq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Fq8Sq.png" alt="enter image description here" /></a></p>
