Vinay Sorout
Vinay Sorout

Reputation: 56

Does kubernetes service of type NodePort works with worker ip or control plane(master) ip?

Lets say I have one master(192.168.1.1) and one worker(192.168.1.2) nodes in my cluster. And if I create a service of NodePort 30001, then will it work with master IP(192.168.1.1:30001) or worker IP(192.168.1.2:30001)?

Upvotes: 2

Views: 1502

Answers (1)

Krishna Chaurasia
Krishna Chaurasia

Reputation: 9590

The service type NodePort opens the port on all the nodes of the cluster and the pods associated with the NodePort service can be accessible using the IP:port combination where IP represents the nodes' external IP and port represents the port exposed on the node for the NodePort service.

Quoting the docs:

If you set the type field to NodePort, the Kubernetes control plane allocates a port from a range specified by --service-node-port-range flag (default: 30000-32767). Each node proxies that port (the same port number on every Node) into your Service. Your Service reports the allocated port in its .spec.ports[*].nodePort field.

Note that this Service is visible as NodeIP:spec.ports[].nodePort and .spec.clusterIP:spec.ports[].port. (If the --nodeport-addresses flag in kube-proxy is set, would be filtered NodeIP(s).)

The following post gives an example where the application is reachable from the master nodes IP:port combination as well for the NodePort service.

Also, the post at openshift clearly states that ports are opened for all the nodes:

Use NodePorts to expose the service nodePort on all nodes in the cluster.

Upvotes: 3

Related Questions