In this demo we will deploy a simple web application and then configure load balancing using the Kubernetes built-in TCP/UDP load balancing. The demo works only if you run your Kubernetes cluster in a supported cloud provider.
- List the nodes of the cluster:
$ kubectl get nodes
- Deploy two containers (pods) of a simple web application that returns a page with information about the container it is deployed on:
$ kubectl run hello-app --image=nginxdemos/hello --port=80 --replicas=2
- Check if containers were created:
$ kubectl get pods -o wide
- Configure external load balancing for the application:
$ kubectl expose pod hello-app --type="LoadBalancer"
This steps allocates a cloud load balancer that gets configured to load balance our application. It works only if you run your Kubernetes cluster in a supported cloud provider.
- Get the IP address of the allocated cloud load balancer:
$ kubectl get svc hello-app
- Make HTTP requests to the application using the IP address obtained in the previous step.