Add MetalLB to MicroK8S
There is a question that pops up inside my head every time I work with Kubernetes [1], "Why the hell does it not implement a network load balancer?". It did have network load balancers but tied to public cloud providers (e.g., AWS, GCP, etc.). What if I want to run Kubernetes clusters in my private clouds or even in my bare-metal infrastructures? Fortunately, I found MetalLB [2].
"MetalLB hooks into your Kubernetes cluster, and provides a network load-balancer implementation. In short, it allows you to create Kubernetes services of type “LoadBalancer” in clusters that don’t run on a cloud provider, and thus cannot simply hook into paid products to provide load-balancers." ~MetalLB documentations.
So, whenever I spin up a new Kubernetes cluster in my bare-metal infrastructures (or for my MicroK8S [4] clusters), I normally have to deploy MetalLB and with Layer 2 configuration as depicted in figure 1. There are also other configurations such as BGP, automatic IP assignment configuration, etc. Check out [3] for more details.
If you're using MicroK8S like myself to experiment this and that with Kubernetes, you may find the PR [5] I made last year to install MetalLB into MicroK8S useful. It automates the MetalLB deployment into MicroK8S with the standard setup. The PR was merged and now you can run this command:
microk8s.enable metallb
Looks pretty cool huh? But actually, It's nothing special. What I did simply was following MicroK8S structure for supporting actions. They are a collection of bash shell scripts and yaml files to deploy external services into MicroK8S clusters such as Prometheus, Istio, etc. Below are the steps that I did:
1. Create a yaml file to deploy MetalLB resources (metallb.yaml, resources such as Deployment, ConfigMap, etc.) into MicroK8S, and put it inside "metallb/microk8s-resources/actions/"
Note: the "{{ip_range}}" placeholder will be replaced by the real IP range when you run "microk8s.enable metallb" command.
2. Create a bash script to enable MetalLB, the metallb/microk8s-resources/actions/enable.metallb.sh:
What it does is asking you to input the IP address range, validate it, update the metallb.yaml file, and finally apply it with the needed credentials. This will create the "metallb-system" namespace inside MicroK8S and install MetalLB components in it.
3. Finally create another bash script to allow disabling MetalLB, the metallb/microk8s-resources/actions/disable.metallb.sh
The bash script will just delete the "metallb-system" namespace and everything belongs to it will also be deleted.
Alright, cool, experimenting with Kubernetes with MicroK8S is quite cool. It's now even better with the support of MetalLB. Hope you find this feature useful. Please leave here any comments if you find any errors or have any suggestions.
References:
[1] https://kubernetes.io/
[2] https://metallb.universe.tf/
[3] https://metallb.universe.tf/configuration/
[4] https://microk8s.io/
[5] https://github.com/ubuntu/microk8s/pull/759
"MetalLB hooks into your Kubernetes cluster, and provides a network load-balancer implementation. In short, it allows you to create Kubernetes services of type “LoadBalancer” in clusters that don’t run on a cloud provider, and thus cannot simply hook into paid products to provide load-balancers." ~MetalLB documentations.
So, whenever I spin up a new Kubernetes cluster in my bare-metal infrastructures (or for my MicroK8S [4] clusters), I normally have to deploy MetalLB and with Layer 2 configuration as depicted in figure 1. There are also other configurations such as BGP, automatic IP assignment configuration, etc. Check out [3] for more details.
Figure 1: MetalLB Layer 2 configuration example
If you're using MicroK8S like myself to experiment this and that with Kubernetes, you may find the PR [5] I made last year to install MetalLB into MicroK8S useful. It automates the MetalLB deployment into MicroK8S with the standard setup. The PR was merged and now you can run this command:
microk8s.enable metallb
Looks pretty cool huh? But actually, It's nothing special. What I did simply was following MicroK8S structure for supporting actions. They are a collection of bash shell scripts and yaml files to deploy external services into MicroK8S clusters such as Prometheus, Istio, etc. Below are the steps that I did:
1. Create a yaml file to deploy MetalLB resources (metallb.yaml, resources such as Deployment, ConfigMap, etc.) into MicroK8S, and put it inside "metallb/microk8s-resources/actions/"
Note: the "{{ip_range}}" placeholder will be replaced by the real IP range when you run "microk8s.enable metallb" command.
2. Create a bash script to enable MetalLB, the metallb/microk8s-resources/actions/enable.metallb.sh:
What it does is asking you to input the IP address range, validate it, update the metallb.yaml file, and finally apply it with the needed credentials. This will create the "metallb-system" namespace inside MicroK8S and install MetalLB components in it.
3. Finally create another bash script to allow disabling MetalLB, the metallb/microk8s-resources/actions/disable.metallb.sh
The bash script will just delete the "metallb-system" namespace and everything belongs to it will also be deleted.
Alright, cool, experimenting with Kubernetes with MicroK8S is quite cool. It's now even better with the support of MetalLB. Hope you find this feature useful. Please leave here any comments if you find any errors or have any suggestions.
References:
[1] https://kubernetes.io/
[2] https://metallb.universe.tf/
[3] https://metallb.universe.tf/configuration/
[4] https://microk8s.io/
[5] https://github.com/ubuntu/microk8s/pull/759
Comments
Post a Comment