2 Kubernetes pod communicating without knowing the exposed address
Asked Answered
C

1

0

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.

Cardiogram answered 23/8, 2019 at 12:21 Comment(0)
A
4

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.

Asphaltite answered 23/8, 2019 at 12:45 Comment(1)
kubernetes.io/docs/concepts/services-networking/dns-pod-service/… might be usefulGirgenti

© 2022 - 2024 — McMap. All rights reserved.