Sign In

Curriculum 16: Services & Networking

NodePort Services

12 min · 25 XP

NodePort Services

A NodePort Service exposes your application on a static port across every node in the cluster. This allows external traffic to reach your Service by hitting any node's IP address on the assigned port.

Port Range

Kubernetes allocates NodePort values from the range 30000-32767 by default. You can let Kubernetes auto-assign a port or specify one explicitly.

Creating a NodePort Service

apiVersion: v1
kind: Service
metadata:
  name: web-frontend
spec:
  type: NodePort
  selector:
    app: frontend
  ports:
    - port: 80
      targetPort: 3000
      nodePort: 31000
kubectl apply -f nodeport-service.yaml
kubectl get svc web-frontend

The output shows three port values: the Service port (80), the target port on the pod (3000), and the NodePort (31000).

Accessing From Outside the Cluster

Use any node's IP address combined with the NodePort:

# Get node IPs
kubectl get nodes -o wide

# Access the service
curl http://<node-ip>:31000

Every node in the cluster proxies traffic to the correct pods, even if the pod is not running on that specific node.

Verifying the Service

kubectl describe svc web-frontend
kubectl get endpoints web-frontend

Considerations

NodePort is useful for development, testing, and non-production environments. For production workloads, consider LoadBalancer or Ingress instead. NodePort opens a port on every node, which can be a security concern. The limited port range (30000-32767) also means you cannot use standard ports like 80 or 443 directly.