A load balancer application can be developed & tested in minikube and with some tricks & no extra costs.
- Clone the repository and navigate to lab-04 folder in Powershell/CLI
- Command to check clusters in minikube
$ minikube profile list - Switch to minikube context
$ kubectl config use-context minikube - Create the Deployment resources in k8s-deployments folder
$ kubectl apply -f ./k8s-deployments/ - Please list the existing Deployments
$ kubectl get deployments - Check pods
$ kubectl get pods - The worker Pod will fail because there is still no connection between the pods
- Create the services
$ kubectl apply -f ./k8s-services/ - Get the services and you will notice that there is no "External IP" for LoadBalancer is pending because minikube is local. For a CSP there will be an external IP assigned which can be accessed from Internet
- Check the pods now and the worker pod will be running with restarts. If it is not running the create then delete the deployment and create the worker deployment once again. The YAML file of worker deployment is in folder "k8s-deployments"
$ kubectl get pods
- Now the tricky part. Each LoadBalaner service creates a NodePort service. We can find out by the below command. If K8s is running in a cluster which does not support LoadBalancer type service, The Loadbalancer won't be provisioned there and it will continue to treat itself like a NodePort service.
$ minikube service - Run the vote service and it will open in new window and would display the NodePort URL. Give your vote
- On cloud providers that support load balancers, an external IP address would be provisioned to access the Service. On minikube, the LoadBalancer type makes the Service accessible through the minikube service command.
$ minikube service vote
- Access the "result" service and check the results (it will be automatically opened in new browser):
$ minikube service result
- Delete Services and deployments
$ kubectl delete -f ./k8s-services/
$ kubectl delete -f ./k8s-deployments/ - Clean everything
$ kubectl delete all --all