Node port
NodePort is a type of service that exposes a port on every node in the cluster. It allows external access to the service by forwarding traffic from the specified port on each node to the corresponding port on the pods targeted by the service. NodePort services are often used when you need to access your application from outside the cluster without requiring a load balancer.
This exposes the service on each Node’s IP at a static port. Since a ClusterIP service, to which the NodePort service will route, is automatically created. We can contact the NodePort service outside the cluster.
- A Nodeport service is the most primitive way to get external traffic directly to your service.
- NodePort, as the same implies, opens a specific port on all the Nodes (the VMs), and any traffic that is sent to this port is forwarded to the service.
When to use Node Port?
- There are many downsides to this method
- You can only have one service per port
- You can only use ports 30,000-32,767
- If your Node/VM IP address change, you need to deal with that
- For these reasons, I don’t recommend using this method in production to directly expose your service. If you are running a service that doesn’t have to be always available, or you are very cost-sensitive, this method will work for you. A good example of such an application is a demo app or something temporary.
Kubernetes – ClusterIP vs NodePort vs LoadBalancer
Three main service types are used in Kubernetes networking: ClusterIP, NodePort, and LoadBalancer. Each has a specific function in controlling external access and service-to-service communication. Comprehending their distinctions is essential for efficiently coordinating applications. This article explores the differences between NodePort, ClusterIP, and LoadBalancer services and provides guidance on when and how to use each for the best Kubernetes networking experience.