1

I have a statefulset app which can have any number of replicas. The pods produced should be able to communicate to external comptures. Those pods must act statefully when clients communicate with them. I tried to create headless service and nodeport services, but it still has only one service to communicate with and also couldn't make it to communicate externally. How can I make it allocate external ip and port per each port?

1

Just to clarify if I got you right.

Do you want to have a separate service for every pod/replica in your statefulSet?

If so - this is not how K8s sees services being used. The service is used for grouping and load balancing purposes.

In your case, if you want to have 1-on-1 connection between an external client and a pod, I suggest deploying your statefulSet a number of times with replicas=1 and exposing a service (as NodePort/LB) every time.

| improve this answer | |
  • How else can I communicate with each pod statefully from the outside world? In your soultion you suggest creating copies of the statefulset manually? Because its not a deployment.. – flowerProgrammer Jul 15 at 12:08
  • The logic is like this: In order for a pod to be available from outside it needs to be exposed via a service (NodePort/LB). Service is applied to a group of pods with the same selectors. Since you want to open each pod (a replica of a statefulset in your case), you need to create 1 service per 1 pod. You either create a number of STS with services pointing at them, or can manually label each STS pod and point services to them accordingly. The second option is very dirt though. Are you sure you need exactly this? – Alexey S. Jul 17 at 7:42
  • The reason I need this is that every pod has an app that communicates with an outside app on specific ports. That app has to receive an ip and then it communicates with that app according to saved actions, therefore statefully. – flowerProgrammer Jul 17 at 11:17
  • Therefore the only way I see is to create service for each pod that exposes those ports and then I use the pod's ip adress to give the outside app. – flowerProgrammer Jul 17 at 11:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.