K3s Load Balancing with Klipper
If your cluster is using K3s, and you have only one node, then you could be adequately served by the built in "klipper" loadbalbancer provided with k3s.
If you want more than one node in your cluster1 (either now or in future), I'd steer you towards MetalLB instead).
How does it work?
When not deployed with --disable servicelb
, every time you create a service of type LoadBalancer
, k3s will deploy a daemonset (a collection of pods which run on every host in the cluster), listening on that given port on the host. So deploying a LoadBalancer service for nginx on ports 80 and 443, for example, would result in every cluster host listening on ports 80 and 443, and sending any incoming traffic to the nginx service.
Well that's great, isn't it?
Yes, to get you started. But consider the following limitations:
- This magic can only happen once per port. So you can't, for example, run two mysql instances on port 3306.
- Because every host listens on the exposed ports, you can't run anything else on the hosts, which listens on those ports
- Having multiple hosts listening on a given port still doesn't solve the problem of how to reliably direct traffic to all hosts, and how to gracefully fail over if one of the hosts fails.
To tackle these issues, you need some more advanced network configuration, along with MetalLB.
Chef's notes 📓
-
And seriously, if you're building a Kubernetes cluster, of course you'll want more than one host! ↩
Tip your waiter (sponsor) 👏
Did you receive excellent service? Want to compliment the chef? (..and support development of current and future recipes!) Sponsor me on Github / Ko-Fi / Patreon, or see the contribute page for more (free or paid) ways to say thank you! 👏
Employ your chef (engage) 🤝
Is this too much of a geeky PITA? Do you just want results, stat? I do this for a living - I'm a full-time Kubernetes contractor, providing consulting and engineering expertise to businesses needing short-term, short-notice support in the cloud-native space, including AWS/Azure/GKE, Kubernetes, CI/CD and automation.
Learn more about working with me here.
Flirt with waiter (subscribe) 💌
Want to know now when this recipe gets updated, or when future recipes are added? Subscribe to the RSS feed, or leave your email address below, and we'll keep you updated.