Interpod Communication

8/6/2020

We have the following in GoogleCloud Kubernetes: 3 REST API Pods which take POSTs and send them to clients that are connected via Websocket.

If one of those Pods is posted on, we want to send this post to all other pods. The question is: How / Where can we find the IPs of the other Pods?

-- Zu Jiry
gcloud
kubernetes

1 Answer

8/6/2020

You can find the pod IP using the below and try hitting the IP but suggest you expose a service to do this.

kubectl get po -n test -o wide 
NAME   READY   STATUS             RESTARTS   AGE   IP           NODE      NOMINATED NODE   READINESS GATES
pod1   1/1     Running            0          98m   10.42.0.16   worker3   <none>   <none>        
pod6   1/1     Running            0          87m   10.44.0.26   worker1   <none>   <none>        

To expose a service:

kubectl expose pod/pod1 -n test --name=svc --port=80 --target-port=80


kubectl run bb --image=busybox -n test -it --rm -- sh
If you don't see a command prompt, try pressing enter.
wget -O- svc:80
Connecting to svc:80 (10.101.174.245:80)
writing to stdout
<html><body><h1>It works!</h1></body></html>
-- DBSand
Source: StackOverflow