bookmark_borderServices: Load Balancer in Kubernetes

LoadBalancer type only works with supported cloud platforms such as GCP, AWS, or Azure. In an unsupportive environment like a virtual box or any other environment, then it would have the same effect as setting Node Port. It just won’t do any kind of external load balancer configuration.

Load Balancer

Load Balancer Service

apiVersion: v1
kind: Service
metadata:
  name: nginx-loadbalancer-service
spec:
  type: LoadBalancer
  ports:
    - targetPort: 80
      port: 80
      nodePort: 31111
  selector:
    app: nginx
$ kubectl create -f nginx-loadbalancer-service.yaml
service/nginx-loadbalancer-service created
$ kubectl get services
NAME                         TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE
nginx-loadbalancer-service   LoadBalancer   10.101.245.47   <pending>     80:31111/TCP   16s

$ kubectl get ep apple-loadbalancer-service
NAME                         ENDPOINTS                                   AGE
apple-loadbalancer-service   172.17.0.3:80,172.17.0.4:80,172.17.0.5:80   5m2s
# If you are using minikube
minikube ip
127.0.0.1

minikube ssh
docker@minikube:~$ curl http://10.101.245.47
docker@minikube:~$ curl http://127.0.0.1:31111
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

Without Cloud platform, you can install and configure a suitable load balancer on it like Nginx.

ANOTE.DEV