snippetkubernetesMinor
Create service per pod in statefulset
Viewed 0 times
percreatestatefulsetservicepod
Problem
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?
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?
Solution
The above answer is incorrect. You can use pod name labels, cf: https://stackoverflow.com/questions/68123751/kubernetes-service-for-a-subset-of-statefulset-pods
For example:
You will have to manually create the services when you scale your statefulset up or down. Alternatively, you could create a helm chart or a CRD + Operator.
For example:
apiVersion: v1
kind: Service
metadata:
name: my-sts-1
spec:
...
selector:
statefulset.kubernetes.io/pod-name: my-sts-1
...You will have to manually create the services when you scale your statefulset up or down. Alternatively, you could create a helm chart or a CRD + Operator.
Code Snippets
apiVersion: v1
kind: Service
metadata:
name: my-sts-1
spec:
...
selector:
statefulset.kubernetes.io/pod-name: my-sts-1
...Context
StackExchange DevOps Q#11997, answer score: 4
Revisions (0)
No revisions yet.