Search code examples
kuberneteskubernetes-podkubernetes-service

2 Kubernetes pod communicating without knowing the exposed address


I plan to deploy 2 kubernetes pods with a NodePort service to expose them into the network. Now i want pod 1 be able to access the pod 2 by his service.

The Problem is i write the Deployment files and i don't know the ip address pod 2 will get from the cluster, but i need to set the address into the file from pod 1 wiva a env. variable. Is there a other way in a kubernetes cluster to make them accessible by sth. like the name of the service or sth. like this?

failed to google for this case, and hope anyone of you can give me a hint.

greetings, Martin.


Solution

  • All kubernetes resources should be referenced by the kubeDNS, you should be able to use the name of the resource to communicate between pods.

    You should be able to make it work with something like this: SERVICENAME.SERVICENAMESPACE:PORT and it can be used in an ENV variable without issue.

    Hope this answer the question.