BareMetal LoadBalancer for Kubernetes using MetalLB

Sat, Oct 13, 2018 2-minute read

In this post i’ll show how to install and use MetalLB l2 loadbalancer for Kubernetes.

If you’re not using AWS,GKE or AKS you cannot passed over to pending state on LoadBalancer service on Kubernetes. MetalLB is tool to achive this and create a loadbalancer for your baremetal Kubernetes by supporting BorderGatewayProtocol and L2.

First of all i created DigitalOcean droplet on Frankfurt with 2G ram and installed Kubeadm.

MetalLB installation yaml firstly create namespace for metallb and creating and applying rbac for namespace.

After applying yaml we should check our pods and services to running without any errors.

root@frankfurt-kubeadm1-ub2g:~/metallb# kubectl get po -n metallb-system
NAME                         READY   STATUS    RESTARTS   AGE
controller-765899887-jn8jq   1/1     Running   0          23s
speaker-z6p4q                1/1     Running   0          24s

Speaker sends arp requests and getting ip addresses for lb. Controller is allocate ip address to loadbalancer service for kubernetes.

Last step is we should give a config to metallb. In this config we define which protocol and which ip addresses will be use for service.

Im using kubeadm to creating this example. Only have 1 node and i want to publish to node ip address.

So what im going to do is giving 1 host cidr. “/32”

apiVersion: v1
kind: ConfigMap
metadata:
  namespace: metallb-system
  name: config
data:
  config: |
    address-pools:
    - name: default
      protocol: layer2
      addresses:
      - 159.89.3**.***/32

After applying it we can dig our speaker logs.

{"caller":"arp.go:102","interface":"weave","ip":"159.89.3**.***","msg":"got ARP request for service IP, sending response","responseMAC":"b2:1e:26:**:**:**","senderIP":"159.89.3**.***","senderMAC":"c6:a4:2a:**:**:**","ts":"2018-10-13T12:04:58.497978319Z"}

Our kubectl get svc is looks awesome

root@frankfurt-kubeadm1-ub2g:~/metallb# kubectl get svc nginx
NAME    TYPE           CLUSTER-IP      EXTERNAL-IP     PORT(S)        AGE
nginx   LoadBalancer   10.109.176.39   159.89.3**.***   80:30311/TCP   8m36s

Service panel :

kubernetes-dashboard-service

Trying out:

root@frankfurt-kubeadm1-ub2g:~/metallb# kubectl get svc nginx
NAME    TYPE           CLUSTER-IP      EXTERNAL-IP     PORT(S)        AGE
nginx   LoadBalancer   10.109.176.39   159.89.3**.***   80:30311/TCP   17m
root@frankfurt-kubeadm1-ub2g:~/metallb# curl 159.89.3**.***
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>