NodePort โ Exposing on Every Node
A NodePort Service exposes the Service on each node's IP at a fixed port (between 30000โ32767). Anyone who can reach any node can access the Service.
NodePort is useful for development and testing. For production, you would typically use a LoadBalancer or Ingress.
How NodePort Works
External Client
โ
โ http://any-node-ip:30080
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Node 1 (30080) โโโ โ
โ Node 2 (30080) โโโผโโโถ Service (ClusterIP)โ
โ Node 3 (30080) โโโ โ โ
โ โโโโโโโดโโโโโโ โ
โ โผ โผ โ
โ Pod-1 Pod-2 โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Port 30080 is open on EVERY node
Creating a NodePort Service
apiVersion: v1
kind: Service
metadata:
name: my-nodeport
spec:
type: NodePort
selector:
app: my-app
ports:
- protocol: TCP
port: 80 # Service port (internal)
targetPort: 8080 # Container port
nodePort: 30080 # External port (optional, auto-assigned if omitted)
If you omit nodePort, Kubernetes automatically assigns a port from the 30000โ32767 range.
Accessing the Service
# Get the node IP
kubectl get nodes -o wide
# Access the service (replace with actual node IP)
curl http://192.168.49.2:30080
# Or with Minikube
minikube service my-nodeport --url
You can reach the Service through any node in the cluster, even if the pods are not on that specific node.
NodePort Limitations
Security โ Opening ports 30000โ32767 on every node exposes your service broadly.
Port management โ You need to track which ports are in use across the cluster.
No SSL termination โ NodePort passes raw TCP traffic. No built-in HTTPS support.
No hostname routing โ You cannot route based on domain names.
For production, combine NodePort with a load balancer or use an Ingress controller.