Own your networking, metallb

Juan Pablo Caivano
IoTOps
Published in
3 min readFeb 17, 2020

Before starting with this article, let me tell you something, you should check our previous post where Frank explains how to enable gitops in k8s, we love helm-controller and this article maybe shows you why, no worry, I will be here drinking a virtual coffee.

Kubernetes, the basics

I’m glad you’re back, so… yeah, if you played with Kubernetes before, you already know what a service is, if not, this guide if for you (I’m considering that you are short of time!), and if you don’t know what an ingress is, so this guide if for you.

Veni, Vidi, Vici. Networking

Kubernetes is taking control of everything, like the Cesar, each domain it’s arrives, it’s sees the way to enter and conquer. From the K8S, there is a lot of approaches to attack the networking, and everything seems to be solved from different layers, but what about when you want to manage your own IP’s addresses?

MetalLB provides Kubernetes services of type LoadBalancer, providing two features to do it, Address Allocation and External Announcement.

Address Allocation

MetalLB assigns and unassigns individual addresses to services, from a given pool. Ensure that you own the pool of addresses, you can assign as many pools as you want.

External Announcement

Ussing standard routing protocols MetalLB announce to the network where the IP lives, that behaviour let your Kubernetes cluster to balance IP using a layer 2 mode (ARP/NDP) and even ussing a BGP mode.

Installation

Install metallb is just simple as having a Kubernetes cluster (version 1.13.0 or later), without a load-balancing functionality. If you love k3s the way we do, you can install k3s with the following sentence:

curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="--no-deploy=servicelb" sh -

After that, apply the manifest:

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

This will deploy the components, that will remain idle until you add a configmap, that will feed the cluster with the pool you want to manage. In a Layer 2 mode, the configuration could something as simple as:

apiVersion: v1
kind: ConfigMap
metadata:
namespace: metallb-system
name: config
data:
config: |
address-pools:
- name: default
protocol: layer2
addresses:
- 192.168.1.240-192.168.1.250

For advance config, take a look at the excellent documentation that this project has.

Finally, if you checked our previous article, you would like to deploy and example app, so you will only need to define a service.loadBalancerIP entry:

apiVersion: helm.cattle.io/v1
kind: HelmChart
metadata:
name: nginx
namespace: kube-system
spec:
chart: https://charts.bitnami.com/bitnami/nginx-5.1.4.tgz
targetNamespace: test
set:
service.loadBalancerIP: "192.168.1.150"

After applying it, you will be able to point your browser to the IP. You can also check the logs of the metallb’s controller and speaker, you will find there interesting information on how’s this work.

Clap our article and let us know if everything worked or not for you!

--

--

Juan Pablo Caivano
IoTOps
Editor for

DevOps Architect at 3XM Group, aka Pulpo. Geek, GNU/Linux’s fan. OpenSource solutions makes me happy.