What is Kubernetes NodePort?

· Category: Kubernetes

Short answer

NodePort exposes a Kubernetes Service on a static port between 30000 and 32767 on every node in the cluster. Traffic sent to any node's IP on that port is forwarded to the service.

How it works

Kubernetes opens the specified port on each node's network interface. The kube-proxy routes incoming traffic to one of the backend Pods. NodePort builds on ClusterIP, so the service is still accessible internally.

Example

apiVersion: v1
kind: Service
metadata:
  name: web
spec:
  selector:
    app: web
  ports:
  - port: 80
    targetPort: 8080
    nodePort: 30080
  type: NodePort

Why it matters

NodePort is useful for development, on-premise clusters, and environments where cloud load balancers are unavailable. It is a simple way to expose services externally without additional infrastructure.

Key differences

  • NodePort: Accessible via any node's IP and a high port.
  • LoadBalancer: Uses a cloud provider's load balancer for a clean external IP.
  • Ingress: Layer 7 routing for multiple services.

Common issues

  • NodePort range is limited and may conflict.
  • Exposing high ports is less user-friendly than standard ports.
  • Firewall rules must allow traffic on the NodePort range.