I am running Kubernetes on \"Docker Desktop\" in Windows.
I have a LoadBalancer Service for a deployment which has 3 replicas. I would like to access SPECIFIC pod th
IMO, the only way to achieve this will be:
As mentioned by aerokite, you can use StatefulSets. However, if you don't want to modify your deployments, you can simply use Headless Services. As specified in the documentation:
For headless Services, a cluster IP is not allocated.
For headless Services that define selectors, the endpoints controller creates Endpoints records in the API, and modifies the DNS configuration to return records (addresses) that point directly to the Pods backing the Service.
This means that whenever you query the DNS name for your Service (i.e. my-svc.my-namespace.svc.cluster-domain.example), what you get is a list of all the Pod IPs (unlike regular services where you get the cluster IP). You can then select your Pods using your own mechanisms.
Regarding your new question, if that is your only issue, you can use session affinity. If you set service.spec.sessionAffinity
to ClientIP
, then connections from a particular client will always go to the same Pod each time. You don't need other modifications like the headless Services mentioned above.
You can use StatefulSets if you are not required to use deployment.
For replica 3, you will have 3 pods named
You can access each pod as $(podname).$(service name).$(namespace).svc.cluster.local
For details, check this
You may also want to set up an ingress to point each pod from outside of the cluster.