Kubernetes Load Balancer Service

Kubernetes load balancer service is one of the ways which is used to expose a Kubernetes object outside the cluster. When a load balancer service is deployed, an external ip will be allocated by the load balancers provided by cloud providers like AKS, EKS and GCP, with this ip, the exposed service can be accessed outside the cluster.

If we try to deploy load balancer service in a standalone cluster which is hosted on a VM and not cloud providers, the service will still get deployed, but external ip will not get assigned.

Setup details:

Kubernetes cluster with calico CNI, 1 master and 3 worker nodes

Create an Nginx Deployment

[root@host-controller ~]# kubectl create ns lb

[root@host-controller ~]# kubectl create deploy ngnix-data-hub --replicas=3 --image=nginx -n lb
deployment.apps/ngnix-data-hub created
[root@host-controller ~]# kubectl get pods -n lb
NAME READY STATUS RESTARTS AGE
ngnix-data-hub-59b6b55689-jhspd 1/1 Running 0 16s
ngnix-data-hub-59b6b55689-stwmg 1/1 Running 0 16s
ngnix-data-hub-59b6b55689-zzpsg 1/1 Running 0 16s

Expose the deployment via LoadBalancer service

  • Lets expose the deployment via LoadBalancer Service using Kubernetes imperative mode.
[root@host-controller ~]# kubectl expose deploy ngnix-data-hub -n lb --target-port=80 --port=9843 --type LoadBalancer -n lb
service/ngnix-data-hub exposed 
[root@host-controller ~]# kubectl get svc -n lb
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
ngnix-data-hub LoadBalancer 10.100.94.197 <pending> 9843:31241/TCP 13s' 
  • Now since the loadbalancer service is deployed, the service will be assigned with an external ip, if we were using Cloud-providers. In our case, we will see the external IP in  pending state. Since our Kubernetes cluster was deployed in a bare metal

Scope of this article is only on explaining Kubernetes service but is not limited to getting a pending state for the loadbalancer service.
We can use MetalLB as loadbalancing solution in the standalone clusters
Fix for this pending ip state for the service can be found here.

Read More

Metal LB as Load balancing solution for standalone clusters

Search on LinuxDataHub

Leave a Comment