Excluding a pod from service in statefulset Kubernetes

465 Views Asked by At

I have a statefulset with 5 replica. This means I have pods with name pod-0 .. pod-4.

I want to create 2 service.

  1. A service that only routes the request to pod-0 ( this is my edit server ) : I know I can achieve this by "statefulset.kubernetes.io/pod-name=pod-0" in the service selector. This is fine.

  2. A service that routes the request to all remaining nodes excluding pod-0( even if the application scales up and add more instances those new instances needs to be mapped to this service) : I am unable to achieve this.

Any idea on how to achieve the 2nd service ??

Since it is deployed via 1 stateful manifest file , all pods are having same label .

1

There are 1 best solutions below

0
On

Thanks for the info . I followed this approach.

  1. Created Role + role binding + service account which have rights to update the label.
  2. At the end of the script that I execute using Docker file [CMD] , I installed kubectl and then executed kubectl label pod ${HOSTNAME} pod-type=${POD_TYPE} --server=kubernetes.default --token=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token) --certificate-authority=/var/run/secrets/kubernetes.io/serviceaccount/ca.crt -n ${POD_NAMESPACE}

Above env variables I am passing in the statefulsets. It served my purpose.