Kubernetes multiple stateful sets pods communication

2/3/2021

Within same stateful set afaik you can interact between particular pods just by referencing it directly, like this - pod-{0..N-1}.my_service.my_namespace.svc.cluster.local. (some more info here: https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#stable-network-id).

However in my case I have 2 different stateful sets, and I want to be able statefullset1-pod-0 from 1st stateful set to interact with statefullset2-pod-0 from 2nd stateful set(and also statefullset1-pod-1 with statefullset2-pod-1, and so on). Is it possible? If yes, can you please provide example configuration?

-- Ruslan Akhundov
kubernetes
kubernetes-statefulset
statefulset

1 Answer

2/4/2021

However in my case I have 2 different stateful sets, and I want to be able statefullset1-pod-0 from 1st stateful set to interact with statefullset2-pod-0 from 2nd stateful set(and also statefullset1-pod-1 with statefullset2-pod-1, and so on). Is it possible? If yes, can you please provide example configuration?

Yes, your apps can access other StatefulSet as it access any other Service in the cluster, use the DNS name of the Service. E.g. if you have created Service statefullset2-pod-0 in the same namespace, you can access it with http://statefullset2-pod-0 if it is a http-service.

Remember, for StatefulSet, you are responsilbe to create the Pod-identity services yourself.

From the StatefulSet documentation:

StatefulSets currently require a Headless Service to be responsible for the network identity of the Pods. You are responsible for creating this Service.

-- Jonas
Source: StackOverflow