Internal communication between pods at Kubernetes with code

1/24/2021
<br> Maybe this question is very wrong but my research so far hasn't been very helpful. <br> My plan is to deploy a server app to multiple pods , as replicas (same code running in multiple pods) and I want each pod to be able to communicate with the rest pods. <br> More specifically I need to broadcast a message to all the rest pods every x minutes.

I cannot find examples of how I could do that with Python code or anything helpful related to the communication internally between the pods. I can see some instructions for the yaml configurations that I should use to make that possible , but no practical examples , which makes me think that maybe using Kubernetes is not the best technology service for what I am trying to do (?).

Any advice/suggestion/documentation is more than needed. Thank you

-- Flora Biletsiou
kubernetes
kubernetes-cluster
kubernetes-pod
kubernetes-python-client
kubernetes-service

1 Answer

1/24/2021

Applications is typically deployed as Deployment to Kubernets, however in use-cases where you want stable network identity for your Pods, it is easier to deploy your app as StatefulSet.

When your app is deployed as StatefulSet the pods will be named e.g.: appname-0, appname-1, appname-2 if your StatefulSet is named appname and your replicas is replicas: 3

I cannot find examples of how I could do that with Python code

This is just plain network programming between the pods. You can use any UDP or TCP protocol, e.g. you can use http for this. The network address is the pod name (since your replicas are Pods within the same namespace) e.g. http://appname-0 or http://appname-1.

-- Jonas
Source: StackOverflow