Kubernetes Metal LB for On-Prem / BareMetal Cluster in 10 minutes
In this quickstart with Metal LB we will quickly get an on-prem / bare metal load balancer running on Kubernetes (k8s). This is more of a standard layer 2 MetalLB environment. If you would prefer more of a developer related environment on Docker CE, please refer to this guide https://medium.com/@JockDaRock/kubernetes-metal-lb-for-docker-for-mac-windows-in-10-minutes-23e22f54d1c8.
- K8s Cluster with no other load balancers installed. Check out Alex Ellis guides for getting up and running with bare metal kubernetes here if you need help getting started (https://blog.alexellis.io/kubernetes-in-10-minutes/, https://blog.alexellis.io/serverless-kubernetes-on-raspberry-pi/).
- Kubernetes-cli program or kubectl. For mac you should be able to get this with the homebrew package manager and the command line command
brew install kubernetes-cli.Or if you are on Windows and have the chocolatey package manager you can use
choco install kubernetes-cli. You can also use this guide as well https://kubernetes.io/docs/tasks/tools/install-kubectl/.
- Your default gateway router configured for DHCP and able to hand out IP addresses.
The environment I am Using:
Your environment might be a little bit or vastly different than this, but should still work given the above pre-reqs.
- Host: Ubuntu 18.04 Server 16 GB RAM, 4 CPUs running on VirtualBox on a Windows 10 Computer.
- Kube Cluster: Single Node Cluster Version, Kubernetes Version 1.11.3
- Network: VLANed network running on Meraki with DHCP configured for 192.168.X.X network.
Now that we have the pre-reqs out of the way let’s get started.
First we need to apply the MetalLB manifest.
Next we want to check that the controller and the speaker are running. we can do this by using this command.
kubectl get pods -n metallb-system
Once those pods are running we can deploy our MetalLB configuration.
So next we will look at our configuration.
- name: my-ip-space
You will notice the addresses are using a 192.168.X.X network. Please modify this to match the IP scheme of the network you are connected to. You can change this to something like
10.0.1.240/28 or something similar.
That being said, you can access this exact configuration here https://raw.githubusercontent.com/google/metallb/v0.7.3/manifests/example-layer2-config.yaml and download and modify if you need to. If not, we can apply this configuration as is.
Once we have deployed our configuration we are ready to apply our deployment and service manifest.
- name: nginx
- name: http
- name: http
The above configuration is what we are using to deploy our first application. I changed this slightly from the tutorial on the main docs site. This will deploy an nginx app/service to kubernetes that we will be able to access. You can download and change this file as needed (https://raw.githubusercontent.com/JockDaRock/metallb-testing/master/nginxlb.yml) or use as is.
Use the following command
kubectl apply -f https://raw.githubusercontent.com/JockDaRock/metallb-testing/master/nginxlb.yml
We can verify the IP address is assigned by using the
kubectl get services command.
Once the service is up and running we can access it on a browser of our choice at the External IP address listed on port 8080.
You are now ready to go forth to use your new LoadBalancing skills. Let me know how your experience is and if you have any questions.
Check out some other guides and tutorials if you are looking to get started with Kubernetes:
Getting started with Kubernetes can be daunting when you don’t know where to begin. Luckily the folks at Kubernetes…medium.com
Bootstrap Kubernetes the hard way on Google Cloud Platform. No scripts. - kelseyhightower/kubernetes-the-hard-waygithub.com
Also, check the standard guide from the MetalLB site out. I started with this guide while I was learning about MetalLB https://metallb.universe.tf/tutorial/layer2/.