When To Use Which Kubernetes Native Service? ClusterIP, NodePort, LoadBalancer or Ingress?
In Kubernetes, a Service is an abstraction level that Kubernetes uses to make a deployed application accessible from the internal and external of the cluster. Kubernetes supports three different types of services:
- Cluster IP
- NodePort
- Load Balancer
It is extremely important to understand the difference between them to correctly design your applications. It’s also important to understand the difference between these concepts and the Ingress…
When To Use ClusterIP?
- Debugging services
- Allowing internal traffic so that other applications in the same cluster can contact the service.
- Designed to be NOT accessible from the external of the cluster.
When To Use NodePort?
- Services that can allow for external connectivity
- The limitation is that we can only have one service per port.
- Ports are limited to 30000–32767.
- Not suitable if node IPs may change — for example with public cloud vms.
When To Use LoadBalancer?
- All traffic on the load-balancer port that is specified will be forwarded to the service. There is no filtering, no routing etc.
When To Use Ingress?
- Ingress is the most useful if you want to expose multiple services under the same IP address using path-based or subdomain routing.
- On the local Kubernetes cluster, it is useful to bypass some NodePort limitations like the port number (you can use 80 port) and use a hostname to bypass the VM IP change.
- On a production system, where Load Balancer is not available, you can bypass the problem of exposing one or more services via NodePort and then use an Ingress in front of them to manage the traffic.