In the last post, we talked about the Kubernetes context and how you can flip between different Kubernetes cluster control contexts from your Windows machine. We have also spoken about in this series how load balancing gives us better access to our application vs using the node port for access.
This post will highlight how simple it is to deploy your load balancer and configure it for your home lab Kubernetes cluster.
Roll your own Kubernetes Load Balancer
If you deployed your Kubernetes cluster in Cloud, the cloud provider will take care of creating Load balancer instances. But if you are using bare metal for the Kubernetes cluster, you have very limited choices which are where we are in this home lab scenario this also enables us to have a choice and to understand why. As I mentioned this is going to be using MetalLB.
Let’s start with what it looks like without a load balancer on bare metal when we are limited to Node or Cluster port configurations. So I am going to create an Nginx pod.
If we did not have a load balancer configured but we used the following command here. It would stay in the pending state until we did have a load balancer.
kubectl expose deploy nginx –port 80 –type LoadBalancer
Installing MetalLB into your Kubernetes Cluster
To start you can find the installation instructions here. The following commands, in general, is going to deploy MetalLB to your cluster, it will create a namespace called metallb-system and it will create a controller which is what will control IP address assignments and then also speaker which handles the protocols you wish to use.
kubectl create namespace metallb-system
kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.9.5/manifests/namespace.yaml
kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.9.5/manifests/metallb.yaml
# On the first install only
kubectl create secret generic -n metallb-system memberlist –from-literal=secretkey=”$(openssl rand -base64 128)”
when you have than these you should see the new namespace metallb-system and be able to run the following command
kubectl get all -n metallb-system
We then need a config map to make it do something or at least use specific IP addresses on our network, I am using Layer2 in my lab configuration but there are other options that you can find here.
Create your YAML if layer2 as above with a range of IP addresses available on your home lab network and then apply this into your configuration. Where config.YAML is the YAML file with your config as per the above is located.
kubectl apply -f config.yaml
now when you deploy a service that requires port type as LoadBalancer
kubectl expose deploy nginx –port 80 –type LoadBalancer
Instead of pending now, this will give you an IP address available on your home lab network, which is great then if you want to access this from outside your cluster. Now if we check another application I have running already in my cluster. You will see the following when you use the LoadBalancer type on deployment.
And then if we go into that service and describe we can then see that configuration
I want to give another shout out to just me and opensource if you are a consumer of video vs written or both then this guy has created an amazing Kubernetes playlist covering all things Kubernetes and more.
In the next post, we are going to focus on hitting the easy button for our apps using KubeApps, where things do not need to be all in the shell there are also UI options, KubeApps is the “Your Application Dashboard for Kubernetes”
Creating memberlist should be done after creating the namespace otherwise the pods will not start up and the option –from-literal= has only one dash in your example but it only works with two.
But now I know how to troubleshoot a not starting container. Maybe this was your intension 😉
Thanks, Marco, I checked and I did have two dashes unless it is somewhere else in the post as well. and I have added the command to create the namespace.