Using MetalLB And Traefik Load Balancing For Your Bare Metal Kubernetes Cluster – Part 1

1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 5.00 out of 5)

Using MetalLB And Traefik for Load balancing on your Bare Metal Kubernetes Cluster – Part 1

Running a Kubernetes Cluster in your own data center on Bare Metal hardware can be lots of fun but also can be challenging.

One of the changeless are exposing your service to an external Load Balancer, Kubernetes does not offer an implementation of an external load-balancer for bare metal cluster implementations.

The Kubernetes implementations of Network Load Balancers are only available on specific Cloud Providers like AWS, GCP, Azure, etc.. and is enabled by specifying the –cloud-provider= option. leaving a gap/challenge if you create your own Bare Metal Kubernetes Cluster.

While their are many workarounds to address this issue most of them are not perfect and have their own list of challenges. while I was looking for a for a solution, most recently came across a project called MetalLB, at first I was quite sceptical if its going to work, but after testing this for a while I have to say, I am quite happy with the solution.

Below is a quote from the MetalLB website.

Kubernetes does not offer an implementation of network load-balancers (Services of type LoadBalancer) for bare metal clusters. The implementations of Network LB that Kubernetes does ship with are all glue code that calls out to various IaaS platforms (GCP, AWS, Azure…). If you’re not running on a supported IaaS platform (GCP, AWS, Azure…), LoadBalancers will remain in the “pending” state indefinitely when created.

Note: On the MetalLB project website they warn you as follows. MetalLB is a young project. You should treat it as a beta system. The project maturity page explains what that implies., however I using this for a while and it seems quite mature.

One last note, I am continuing to use Traefik for internal micro services / load balancing which works great, however MetalLB helps exposing your service for external use.

Now that we have that out of the way, lets see what it takes to install and configure MetalLB on your Kubernetes cluster.

Installing MetalLB on your Kubernetes cluster

You have two options to install MetalLB on your Kubernetes cluster.

  1. Use the a per-packged MetalLBHelm chart.
  2. Install / configure manually by applying a YAML configuration file.

Installing MetalLB with Helm

Note: To use Helm you first need to install/configure Helm/Tiller on your Kubernetes cluster. you can see a how-to step by step process here Part 1 and here Part 2.

First, lets create a configmap which will be using at helm install time, the below configmap was used with a flannel configuration.
cat values.yaml

Note: There are a number of networking options you can specify likeprotocol: BGP, etc.. please take a look at the MetalLB website for a full list of options.

Once helm is available on your cluster, just run the below to install MetalLB (omit the -tls if your are not using a secure configuration).
Note: The below configuration installs MetalLB with helm including a configmap. (otherwise you get the errors below)

Errors you will see if you don’t specify / use a configmap to list your network range, etc..

You can also check the logs to make sure all looks good, by running the below

If your cluster is not configured to use RBAC, you might run somthing like the below.

An example configmap if using a BGP overlay system.

If all works correctly, you should now have a MetalLB working configuration.

You can also check what helm report about the installation.

To remove MetalLB from your cluster, just run the below.

Installing MetalLB manually

To install MetalLB manually, you would do so in cases ware you don’t have a helm configuration or you would like to install a version not available in the helm repository.

To MetalLB from the web just run the below.

You can also create a deploy file, like the one below.

Then to install just run the below, this will already include your IP address definitions.

A quick check on your pods will reveal something like the below, note the metallb-controller and metallb-speaker.

MetalLB in action

To test MetalLB working, you can deploy any pod(s) to you cluster, and specify the Cluster Type as LoadBalancer.

An example Nginx deployment is below.

Now, just run the below to deploy to your cluster.

Now take a look on your Kubernets Cluster services, note the EXTERNAL-IP that got assigned automatically by MetalLB.

In the next post Part 2 – I will show you how to combine this with Traefik for internal Micro-services Load Balancing.

I hope you enjoyed reading Using MetalLB And Traefik Load Balancing For Your Bare Metal Kubernetes Cluster, give it a thumbs up by rating the article or by just providing feedback.

You might also like – realted to Docker Kubernetes / micro-services.

Leave a Reply

Notify of