Kubernetes Metal LB for On-Prem / BareMetal Cluster in 10 minutes

Jock Reed
Jock Reed
Sep 18, 2018 · 4 min read

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.


  1. 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/).
  2. 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/.
  3. Your default gateway router configured for DHCP and able to hand out IP addresses.


Check out the docs and github repo for MetalLB for more in depth study https://metallb.universe.tf/, https://github.com/google/metallb.

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.

kubectl apply -f https://raw.githubusercontent.com/google/metallb/v0.7.3/manifests/metallb.yaml

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.

Image for post

So next we will look at our configuration.

apiVersion: v1
kind: ConfigMap
namespace: metallb-system
name: config
config: |
- name: my-ip-space
protocol: layer2

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 like10.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.

kubectl apply -f https://raw.githubusercontent.com/google/metallb/v0.7.3/manifests/example-layer2-config.yaml

Once we have deployed our configuration we are ready to apply our deployment and service manifest.

apiVersion: apps/v1beta2
kind: Deployment
name: nginx
app: nginx
app: nginx
- name: nginx
image: nginx:1
- name: http
containerPort: 80
apiVersion: v1
kind: Service
name: nginx
- name: http
port: 8080
protocol: TCP
targetPort: 80
app: nginx
type: LoadBalancer

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.

Image for post

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:


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/.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store