How to access pod by it's hostname from within other pod of the same namespace?

7/16/2019

Is there a way to access a pod by its hostname? I have a pod with hostname: my-pod-1 that need to connect to another pod with hostname: my-pod-2.

What is the best way to achieve this without services?

-- Prakash Bayas
kubernetes
kubernetes-pod

2 Answers

7/17/2019

I am not sure what do you mean exactly by "accessing" a pod but if you need to programmatically make some HTTP calls to some pods, you can do something similar to what this libcluster nodejs library does.

It's hackish but basically it works with enquiring list of endpoints (pod's IPs) from Kubernetes APIs.

-- Rahman
Source: StackOverflow

7/16/2019

Through your description, Headless-Service is you want to find. You can access pod by accessing podName.svc with headless service.

OR access pod by pod ip address.

-- Ray
Source: StackOverflow