Kubernetes: Exposing Pods Using NodePort and LoadBalancer
Let say we have a situation which is described in the figure above. Without creating Service, the client is not possible to access the your PODs. There are many ways to allow client to access the internal PODs: NodePort, LoadBalancer and Ingress.
We are going to use NodePort to expose our PODs.
Client can access PODs using the ip address of node1 or node2 at port 30000
for example: http://192.168.37.1:30000, or http://192.168.37.2:30000
You may think that if you connect to ip-address of node 1 (192.168.37.1), it will only redirect to the pods reside in node 1. Wrong! In fact, nodeport service will redirect the connection to a random pod, regardless to the node you make the connection to.
The disadvantage of using NodePort is: Let say you tell your client to access your PODs using node1:30000, and node1 fails. Your client can no longer access the service. This is where LoadBalancer service come to rescue.
The Load Balancer and Load Balancer Service are the same resource. Load Balancer Service behaves like NodePort Service. But it has its own ip-address.
Kubernetes On-Prem does not support Load Balancer by default. You have to install and configure load balancer support before hand. Please read MetalLB, https://metallb.universe.tf/