0

I have a deployment pod that needs to grab another the IP address of another deployment pod and use that as an environment variable. The closest I could find was this how-to-know-a-pods-own-ip-address-from-inside-a-container-in-the-pod

I know I can grab the IP address of a service using the environment variable: $<SVC NAME>_SERVICE_HOST injected in a pod that gets created after this service. Is there a similar way to inject a deployment pod's IP address into another deployment pod after the first gets created?

horcle_buzz
  • 2,101
  • 3
  • 30
  • 59

2 Answers2

0

You should consider exposing your target pod through a ClusterIP service, and access that pod using the service's cluster DNS FQDN. Using this method, you don't have to worry about exactly what IP your target pod is at because the Kube proxy will take care of all the DNS and routing for you. You will then only need to know what the ClusterIP service endpoint is and access your target pod through that.

The official docs contain a great case study and an interactive tutorial on this subject.

Hope this helps!

Frank Yucheng Gu
  • 1,807
  • 7
  • 21
  • Unfortunately, the application in the POD requires an IP address. An endpoint won't work. If it were that simple, we'd be able to just use the service's labeled DNS name with the label applied to the deployment pod. – horcle_buzz Apr 20 '19 at 15:02
  • 2
    In that case you might be better off using a service registry (eg. Consul) and have your pod(s) register their metadata that will be visible to other pod(s). You can also use the suggest approach of using the Kubernetes to query your pod IPs. – Frank Yucheng Gu Apr 20 '19 at 17:23
0

There is not way currently to find another pod's IP in DNS or environment variables. For that you need to query Kubernetes API. You may create serviceaccount with pod and deployment list permissions and then use Kubernetes API library or kubectl.

Vasili Angapov
  • 8,061
  • 15
  • 31
  • Sounds a bit laborious, but I'll look into that. The alternative solution is to just make a list of the entire 192.168.x.x name space as "allowed hosts" for accessing the pod in question (the application expects a list of allowed host IP addresses... NB: we are looking trying to disable that requirement, which would obviate this whole mess]. – horcle_buzz Apr 20 '19 at 15:05