2 Kubernetes pod communicating without knowing the exposed address

烈酒焚心 提交于 2020-02-07 04:06:59

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/57626255/2-kubernetes-pod-communicating-without-knowing-the-exposed-address

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!