Kubernetes: how to discover neighbor pods

11/8/2016

I have started 3 different pods (in GKE):

kubectl run ubuntu --image myimage --namespace misko -r 3 --command -- /some/binary --bind-to-port 1234

Now I need to discover hostnames/ip addresses of those pods from 4th pod which needs to connect to those 3 nodes.

Is it possible to do that?

-- Misko
kubernetes
service-discovery

1 Answer

11/8/2016

This is creating a Deployment that will control the pods behaviour and replicas but you have to create a service for this deployment in order to expose the ports inside or outside the cluster.

kubectl expose deployment ubuntu --port=1234 --target-port=1234

After that you can access the pods in round-robin using the service name and the port number:

ububtu:1234

If the other pod it's on a different namespace, you may use the full DNS instead:

ubuntu.misko.svc.cluster.local:1234

Please take a look at kubectl expose for more examples

-- Camil
Source: StackOverflow