liveBook · Manning

Node port

As explained in Road to Kubernetes

A NodePort Service is a Kubernetes Service type that exposes a port on each cluster node and routes traffic to selected Pods.

A Pod is not reachable from the internet without additional configuration. A NodePort Service opens a port on every cluster node and routes incoming traffic to selected Pods. It is a quick way to expose and test an application without adding a cloud load balancer. section 8.3.2

Listing 8.5 K8s YAML manifest for an NGINX Service
apiVersion: v1
kind: Service
metadata:
  name: first-service-nginx
spec:
  type: NodePort
  ports:
  - port: 5050
    targetPort: 80
    nodePort: 30007
  selector:
    app: my-nginx

In this NGINX Service manifest, nodePort 30007 is the port exposed on each node. The Service uses port 5050, forwards to port 80 on the Pod, and selects Pods labeled app: my-nginx. section 8.3.2

Traffic can arrive at any node and be routed to a selected Pod elsewhere in the cluster. A NodePort left unspecified is assigned automatically; the resulting nonstandard web port may need to appear in a browser address. section 8.5.1 section 8.5

Choose the Service type to match the traffic:

  • Use NodePort for straightforward external access through a port on each node. section 8.3.2
  • Use ClusterIP when traffic should stay inside the cluster. section 8.3.2
  • Consider LoadBalancer when a cloud-managed load balancer and its static public IP are useful, particularly for multiple Services and custom domains. section 8.5 section 8.5.1

How Road to Kubernetes covers it

How deep it goes
Defines NodePort and illustrates its Service YAML and cross-node routing, without detailing routing internals.
Examples
Uses an NGINX Service selecting app: my-nginx and forwarding node port 30007 to Pod port 80.
What it assumes
Assumes an existing Pod and cluster nodes; introduces Service types before configuring external access.
What you can do after
Apply it via Kubernetes Service YAML to expose selected Pods on a port available at every node.
How it connects
Connects Kubernetes Services, Pods, selectors, ClusterIP, LoadBalancer, and custom domains.

Also explained in

Compare how 6 books explain node port →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Road to Kubernetes. The section links point to the parts of the book it draws on.