K3s Cluster in a Weekend – Part 2 – MetalLB
MetalLB is used to handle load balancing services for bare metal installation of Kubernetes, with LoadBalancer declarative providing network connectivity into the cluster. To get a better understanding of how modular and flexible Kubernetes can be, ServiceLB which ships as the default service load balance used by K3s, can be disabled during installation or through configuration. Once disabled, MetalLB can be setup.
Start with disabling ServiceLB by adding a statement to config.yaml
echo disable:
- \"servicelb\" >> /etc/rancher/k3s/config.yaml
Using Helm, install MetalLB.
helm repo add metallb https://metallb.github.io/metallb
helm install metallb metallb/metallb
IPAddressPool configures the addresses available for MetalLB to assign to Services deployed in K3s. The IP address selected from the pool effectively act as the “external” address for the service in the cluster.
---
apiVersion: metallb.io/v1beta1
kind: IPAddressPool
metadata:
name: metallb-address-pool
namespace: metallb-system
spec:
addresses:
- 10.33.0.200-10.33.0.254
---
apiVersion: metallb.io/v1beta1
kind: L2Advertisement
metadata:
name: metallb-l2-adver
namespace: metallb-system
spec:
ipAddressPools:
- default
Now, MetalLB will automatically assign the next available IP address to any Service with configuration type: LoadBalancer