A node port is a network port on every node in a Kubernetes cluster that accepts traffic for a Service. A Service of type NodePort gives clients another way to reach its pods: they can use a node’s IP address and the node port, while clients inside the cluster can still use the Service’s cluster IP. section 11.2.1 section 11.2
Use NodePort when a ClusterIP Service, which is accessible only inside the cluster, is not enough. The Service selects pods by label. A connection to the node port is forwarded to a selected pod even if that pod runs on a different node from the one the client contacted. section 11.2 section 11.2.1
Listing 11.3 A NodePort service exposing the Kiada pods on two ports
apiVersion: v1
kind: Service
metadata:
name: kiada
spec:
type: NodePort #1
selector:
app: kiada
ports:
- name: http #2
port: 80 #3
nodePort: 30080 #4
targetPort: 8080 #5
- name: https #6
port: 443 #6
nodePort: 30443 #6
targetPort: 8443 #6
This Service manifest exposes two application ports. For HTTP, clients use node port 30080 or cluster-IP port 80; the selected pod receives traffic on target port 8080. The HTTPS entry follows the same pattern with 30443, 443, and 8443. section 11.2.1
Set spec.type to NodePort and define each Service port and its targetPort. You may set nodePort explicitly, as in the manifest, or omit it and let Kubernetes choose an available number. Naming each port is required when a Service exposes multiple ports. section 11.2.1 section 11.1.2
Find and use the node port
Run kubectl get svc to inspect the TYPE and PORT(S) columns. An entry such as 80:30080/TCP means port 80 on the Service’s cluster IP and node port 30080. Run kubectl get nodes -o wide to find a node IP, then try curl 172.18.0.4:30080 if that address is reachable from your client. Any cluster node can forward the request to a selected pod. section 11.2.1
NodePort does not itself provision an external load balancer. A load balancer can direct traffic to the node ports; a LoadBalancer Service can arrange this automatically where the cluster infrastructure supports it. Even when a LoadBalancer Service shows its external IP as <pending>, its assigned node port offers another access route if a node IP is reachable. section 11.2 section 3.3.2





