MetalLB load-balancer for Kubernetes¶
Available since MKE 3.7.0
MetalLB is a load-balancer implementation for bare metal Kubernetes clusters, using standard routing protocols.
Prerequisites¶
An MKE cluster that is running Kubernetes 1.13.0 or later, which does not already have network load-balancing functionality.
A cluster network configuration that is compatible with MetalLB.
Available IPv4 addresses that MetalLB can allocate.
BGP operating mode requires one or more routers capable of communicating with BGP.
When using the L2 operating mode, traffic on port 7946 must be allowed between nodes, as required by memberlist. You can configure TCP, UDP, and other ports.
Verification that
kube-proxy
is running iniptables
mode.Verification of the absence of any cloud provider configuration
Install MetalLB¶
You use the MKE configuration file to install MetalLB:
Obtain the current MKE configuration file for the cluster.
Set
cluster_config.metallb_config.enabled
totrue
.Configure at least one IP address pool by setting the values in the
cluster_config.metallb_config.metallb_ip_addr_pool.name
andcluster_config.metallb_config.metallb_ip_addr_pool.external_ip
values.Caution
Make sure to provide correct IP addresses in CIDR format.
MetalLB pool name values must adhere to the RFC 1123 international format:
A lowercase RFC 1123 subdomain must consist of lower case alphanumeric characters,
-
or.
, and must start and end with an alphanumeric character. For example,example.com
, regex used for validation is ‘[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*’)
Example IP address pool settings:
[cluster_config.metallb_config] enabled = true [[cluster_config.metallb_config.metallb_ip_addr_pool]] name = "example1” external_ip = ["192.168.10.0/24", "192.168.1.0/24"] [[cluster_config.metallb_config.metallb_ip_addr_pool]] name = "example2" external_ip = ["52.205.10.1/24"]
When multiple address pools are configured, MKE advertises all of the pools by default. To request assignment from a specific pool, users can add
metallb.universe.tf/address-pool annotation
to the service, with the name of the address pool as the annotation value. In the event that no such annotation is added, MetalLB will assign an IP from one of the configured pools.You can configure both public and private IPs, based on your environment. MKE allows you to define unlimited address pools and is type-agnostic.
Upload the modified MKE configuration file and allow at least 5 minutes for MKE to propagate the configuration changes throughout the cluster.
Verify the successful installation of MetalLB in the cluster.
Verify the creation of the
metallb-system
namespace:kubectl get ns metallb-system
Example output:
NAME STATUS AGE metallb-system Active 93s
Verify that all MetalLB components are running in the system:
Verify the Pods:
kubectl get pods -n metallb-system
Example output:
NAME READY STATUS RESTARTS AGE controller-669d7d89b5-58s2g 1/1 Running 0 119s speaker-cchsw 1/1 Running 0 119s speaker-ph96f 1/1 Running 0 119s
Verify the Daemonsets:
kubectl get daemonsets -n metallb-system
Example output:
NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE speaker 2 2 2 2 2 kubernetes.io/os=linux 28m
Verify the Deployments:
kubectl get deployment -n metallb-system
Example output:
NAME READY UP-TO-DATE AVAILABLE AGE controller 1/1 1 1 29m
Verify the Services:
kubectl get services -n metallb-system
Example output:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE webhook-service ClusterIP 10.96.18.104 <none> 443/TCP 29m
Verify the creation of the Custom Resource Defintions:
kubectl get crd -n metallb-system
Example output:
NAME CREATED AT addresspools.metallb.io 2023-03-16T17:11:02Z bfdprofiles.metallb.io 2023-03-16T17:11:03Z bgpadvertisements.metallb.io 2023-03-16T17:11:03Z bgppeers.metallb.io 2023-03-16T17:11:03Z communities.metallb.io 2023-03-16T17:11:03Z ipaddresspools.metallb.io 2023-03-16T17:11:03Z l2advertisements.metallb.io 2023-03-16T17:11:03Z
Verify the creation of the specified IP pools:
kubectl get IPAddressPools -n metallb-system
Example output:
NAME AUTO ASSIGN AVOID BUGGY IPS ADDRESSES example1 true false ["192.168.10.0/24","192.168.1.0/24"] example2 true false ["52.205.10.1/24"]
Uninstall Metallb¶
To uninstall MetalLB you need only update the MKE configuration file.
Obtain the current MKE configuration file for the cluster.
Set
cluster_config.metallb_config.enabled
tofalse
.Upload the modified MKE configuration file and allow at least 5 minutes for MKE to propagate the configuration changes throughout the cluster.
Verify the successful uninstall of MetalLB in the cluster.
Verify that no MetalLB components are running in the system.
Verify the Pods:
kubectl get pods -n metallb-system
Example output:
No resources found in metallb-system namespace.
Verify the Daemonsets:
kubectl get daemonsets -n metallb-system
Example output:
No resources found in metallb-system namespace.
Verify the Deployments:
kubectl get deployment -n metallb-system
Example output:
No resources found in metallb-system namespace.
Verify the Services:
kubectl get services -n metallb-system
Example output:
No resources found in metallb-system namespace.
Verify the deletion of all IP address pools.
kubectl get IPAddressPools -n metallb-system
Example output:
No resources found in metallb-system namespace.