How to communicate between pods of the same service on the same k8s cluster using k8s-java-client?

5/26/2019

I have a kubernetes cluster that has many services on it. How can I make one pod publish a message, and receive it from another siblings pods (pods of the same service), using kubernetes-java-client.

Until now, I didn't find a way to do the job done.

Example: 1 Service -> 4 pod (4/4 replicaSet)

Invoke Api in the service, load balance takes the request to 1 Pod, so other pods need to do a reaction because a specific Api in another pod has been activated.

So, the pod publish an event, and other sibling pods consumes the event, an do the reaction. Or the pod communicates directly with its siblings to tell them to do the reaction.

Is this possible, and what is the right way to a similar scenario?

-- Ali Adel Abed
java
java-client
kubernetes
kubernetes-pod

1 Answer

5/26/2019

Other than using the Kubernetes API to discover the peer pods (usually via the endpoints API), it doesn’t provide anything in particular for the actual comms, that would be up to your code.

-- coderanger
Source: StackOverflow