This document provides a step-by-step guide for load balancing Kubernetes Master using HAProxy. Below are the necessary steps for configuring HA-K3s with 3 machines (haproxy, master1, master2).
- 3 machines:
haproxy
,master1
,master2
- Ubuntu operating system
Execute the following commands in order to complete the installation:
-
HAProxy Installation (on the machine where HAProxy is installed):
sudo apt-get update && sudo apt-get install haproxy -y
-
Configure HAProxy: After installing HAProxy, replace the default configuration with the provided
haproxy.cfg
file:sudo cat /path/to/haproxy.cfg > /etc/haproxy/haproxy.cfg
-
Master1 Installation:
curl -sfL https://get.k3s.io | K3S_TOKEN=SECRET sh -s - server --cluster-init --tls-san=<haproxyIP>
-
Get Node Token (on Master1):
sudo cat /var/lib/rancher/k3s/server/node-token
-
Master2 Installation:
curl -sfL https://get.k3s.io | K3S_TOKEN=<node-token> sh -s - server --server https://<master1IP>:6443 --tls-san=<haproxyIP>
-
Get K3s Configuration File (on Master1):
cat /etc/rancher/k3s/k3s.yaml
-
Install Kubectl on HAProxy Server:
# Kubectl installation steps (add your system-specific commands here)
-
Configure Kubectl:
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" chmod +x kubectl sudo mv kubectl /usr/local/bin mkdir ~/.kube cd ~/.kube vi config
Replace the
server
address in thek3s.yaml
file withhaproxyIP
.
After completing these steps, you should be able to access your Kubernetes cluster through HAProxy. If you encounter any issues, you can seek support from documentation or community forums.