Kubernetes load balancing demonstration¶
This document outlines a practical demonstration of load balancing within a Kubernetes environment, specifically utilizing kubectl commands and curl to verify traffic distribution across application pods.^[400-devops-06-kubernetes-k8s-learning-08-collect-readme.md]
Accessing Services¶
Access to the application is typically managed locally via port forwarding. This creates a secure tunnel between a local port and the specific Kubernetes Service, allowing requests to hit the cluster load balancer.^[400-devops-06-kubernetes-k8s-learning-08-collect-readme.md]
[kubectl port-forward](<./kubectl-port-forward.md>) service/svc-myapp 8080:80 --address 0.0.0.0
Verifying Distribution¶
To confirm that the load balancer is correctly distributing traffic, a loop can be used to send multiple requests to the forwarded endpoint.^[400-devops-06-kubernetes-k8s-learning-08-collect-readme.md]
for i in {1..10}
do
curl localhost:8000
done
In a successful demonstration with two versions of an application (v1 and v2) running, the output will alternate between the two versions, indicating that requests are being handled by different backend pods.^[400-devops-06-kubernetes-k8s-learning-08-collect-readme.md]
Hello MyApp | Version: v1 | <a href="hostname.html">Pod Name</a>
Hello MyApp | Version: v2 | <a href="hostname.html">Pod Name</a>
Hello MyApp | Version: v1 | <a href="hostname.html">Pod Name</a>
Hello MyApp | Version: v2 | <a href="hostname.html">Pod Name</a>
Sources¶
^[400-devops-06-kubernetes-k8s-learning-08-collect-readme.md]