Reputation: 68
I have a Kubernetes cluster with two namespaces, dbns
(where a database lives) and jobland
(where jobs run from).
I would like to run a Job
from a container running in the jobland
namespace that will connect to and run scripts against a DB living in the dbns
namespace.
When I run get pod,statefulset,svc,configmap -o wide
I see that my DB has an IP of 10.1.0.34
, but I'm assuming thats only "reachable" from other containers running inside the dbns
namespace, correct? If so, how could I expose its IP so that items from outside the dbns
namespace can connect to it (such as something running in jobland
)?
Upvotes: 0
Views: 51
Reputation: 141946
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
Here is an example of how to do it:
https://github.com/nirgeier/KubernetesLabs/tree/master/Labs/05-Services#0403-using-the-full-DNS-name
As a best practice you should not rely on the Cluster IP since it can change and will "break" your connectivity.
The recommended way is as mentioned above to use the FDDN which is automatically created for you once you add the Service
object to your namespace and resource.
The name (FQDN) will be the same regardless of the IP and cluster which your code are deployed to.
You can verify this name, for example:
Upvotes: 2