WordPress on Kubernetes

The Definitive Guide to WordPress on k8s

Load Balancing with MetalLB

In the previous section we’ve installed and configured the Nginx Ingress Controller to bring Internet traffic into our Kubernetes cluster. For most WordPress applications this will be more than enough, and highly available, if you can have at least two Nginx replicas running.

However, in more complex configurations and larger clusters, you might want stable and static IP addresses for your Nginx services, or even non-HTTP/S services, such as SSH or external MySQL access. While NodePort services may still be an option, having proper external cluster IPs is a much better solution.

If you’re working with Kubernetes in a cloud environment, you’ll typically have access to some cloud-backed LoadBalancer implementation, such as a floating IP or an actual TCP load balancer component with a fixed IP. If you’re running a bare-metal Kubernetes cluster, MetalLB is your best option.

Note: all code samples from this section are available on GitHub.

In this section we’ll cover a simple MetalLB installation. We’ll configure a pool of IP addresses, advertise them over the local network using ARP. We’ll create an external MySQL service for our MariaDB cluster, as well as update our Nginx deployment to draw IPs from MetalLB.

What is MetalLB

MetalLB is a load balancer implementation for Kubernetes. Its two main building blocks are Address Allocation and Advertisements. Allocation allows us to define blocks of IPs that are available for our Kubernetes services. Advertisements ensure that external routers know where to route traffic to those IPs.

MetalLB currently supports Layer 2 mode (ARP/NDP) and BGP. Layer 2 is great for testing and is widely compatible with most networks, however BGP is what you’ll want for best performance and availability, if your equipment and/or services provider supports the protocol.

In this tutorial we’ll use Layer 2 mode, which is supported by most providers offering a private network or routing a public IP prefix to a VPC or virtual switch. Layer 2 is also supported in most virtualized environments such as VirtualBox and KVM.

Installing MetalLB

You can install MetalLB from a manifest using:

This article is for premium members only. Memberships start from $125/year and unlock access to all existing and future content on kubeadm.org, including all reference architectures.

Already a member? Login here