K3s load balancing with kube-vip

2024-05-17

Load balancing with kube-vip

Why is there the need of a load balancer when K3s already offers the Service load balancer? K3s offering exposes services on the host (or node) IP. This means that any workload that, for any reason, is moved to a different cluster node will change their IP address, which defeats the purpose of having a multi-node cluster.

Note

When deploying a Kubernetes cluster in a cloud environment, providers use external load balancers to provide access to the Kubernetes instances.

What are the alternatives? There are 2 main methods to load balance a bare metal cluster:

  1. Add an external load balancer in front of the cluster; or
  2. Let the cluster itself handle the load balancing in a self-contained way.
    I chose the latter as it requires less hardware.

Which load balancer to choose then? MetalLB and kube-vip are the most widespread solutions in the self-hosting scene, they offer similar functionalities, at least for my needs.

Initially, I was tempted to go with MetalLB as I could find more tutorials and higher quality documentation, but then I found out that it doesn’t support load balancing Kuberneted API server. This means that, as soon as I decide to expand the cluster to have multiple control planes, I will not have support for load balancing the API server. Not a big deal, but since I’m going to set it up from scratch, why not trade a little more effort with more functionalities?

Tip

I decided to add kube-vip when the cluster was already up and running, the instructions can be found here: Adding kube-vip after setting up the cluster.