As per my understanding, NodePort service types in Kubernetes opens a port at node level through which external clients can access specific pods.
I would like to clarify one point regarding this. Assume a scenario where I deploy one service with 10 replicas, and all these 10 pods are placed in a single worker node. As I expose this service as NodePort, how the Kubernetes select the pods from available 10 pods in the same Node?
I assume k8s cannot simply map NodePort to actual port, as multiples ports are running in the same node. Is there a mechanism to select pods here? Or am I missing some basics here?
In K8s, when you expose a svc as type NodePort
, it opens a port on all nodes in the cluster. Regardless of whether multiple replicas of the service are on the same node, K8s handles incoming traffic on the NodePort
efficiently by internally load balancing it to any pod associated with the svc. This ensures high availability and scalability without being affected by pod placement.