NodePort Service Type
What you'll learn: How to expose a Kubernetes Service on a static port across all cluster nodes, making your application accessible from outside the cluster.
What Is NodePort?
A NodePort is a Service type that extends the ClusterIP functionality by opening a specific port on every node in your Kubernetes cluster. When you create a NodePort Service, Kubernetes automatically allocates a port (default range: 30000-32767) and routes traffic from that port on any node to your Service.
Think of it like this: If ClusterIP is like having an internal phone extension that only works inside your office building, NodePort is like publishing a public phone number that routes to that extension—anyone who calls any office location gets transferred to the right desk.
How NodePort Works
When you define a NodePort Service:
- Kubernetes assigns a static port (the "NodePort") on every node
- External traffic hitting
<NodeIP>:<NodePort>gets forwarded to your Service - The Service then routes traffic to healthy Pods matching its selector
- This works even if the Pod isn't running on the node that received the traffic
For example, if your NodePort is 30080 and you have three nodes with IPs 10.0.1.1, 10.0.1.2, and 10.0.1.3, you can access your application via 10.0.1.1:30080, 10.0.1.2:30080, or 10.0.1.3:30080.
When to Use NodePort
NodePort is ideal for:
- Development and testing environments
- Small-scale production workloads without a load balancer
- Accessing services when LoadBalancer type isn't available
Key Takeaway: NodePort Services expose your application externally by opening the same high-numbered port on every cluster node, allowing outside traffic to reach your Pods through any node's IP address.