Better Programming

Advice for programmers.

Follow publication

Software-only High Availability and Load Balancing for your Kubernetes API

Using Alpine Linux, HAProxy, and keepalived

Nassos Michas
Better Programming
Published in
5 min readMar 28, 2022
Photo by Vicky Sim on Unsplash

So, you have used your favourite Kubernetes distro and just finished setting up your cluster. It is now time to access it remotely with kubectl, but which of the API servers should you access? And what if you configure one of them in your kube config and it happens to go down?

In the following sections, I will show you how to quickly set up a highly available and load-balanced access to your Kubernetes API using nothing else than software components.

For this lab, I have used k3s deployed on k3OS, forming a highly available Kubernetes cluster with embedded DB using three server nodes.

Software Tools

The setup will incorporate the following software tools:

  • Alpine Linux (Alpine), is a Linux distribution based on musl and BusyBox, designed for security, simplicity, and resource efficiency. It uses OpenRC for its init system and compiles all user-space binaries as position-independent executables with stack-smashing protection. The Alpine distribution to be used for the virtual machines that will be created is based on the Virtual image from https://alpinelinux.org/downloads.
  • HAProxy, is a free and open source software that provides a high availability load balancer and reverse proxy for TCP and HTTP-based applications that spreads requests across multiple servers. It is written in C and has a reputation for being fast and efficient. HAProxy will be installed in the Alpine virtual machines using Alpine’s built-in package manager, apk.
  • keepalived, provides simple and robust facilities for loadbalancing and high-availability to Linux system and Linux based infrastructures. Load balancing framework relies on well-known and widely used Linux Virtual Server (IPVS) kernel module providing Layer4 load balancing. keepalived will be installed in the Alpine virtual machines using Alpine’s built-in package manager, apk.

Infrastructure Layout

This is what we are about to build:

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Nassos Michas
Nassos Michas

Written by Nassos Michas

BSc, MSc in Software engineering | Cert. Scrum master | Cert. Professional for Software Architecture | Cert. Professional for Requirements Engineering

Responses (1)

Write a response