Skip to content
This repository was archived by the owner on Aug 7, 2025. It is now read-only.

Commit a872ccc

Browse files
authored
adding support for HA clusters, using HAProxy (#317)
* adding support for HA clusters, using HAProxy Signed-off-by: David Lyle <dklyle0@gmail.com> * fixing typo * fixing load balancer port default value
1 parent 1525407 commit a872ccc

4 files changed

Lines changed: 79 additions & 4 deletions

File tree

clr-k8s-examples/README.md

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,28 @@ devicemapper storage. This should not be used for production.
6363

6464
> NOTE: This step is done automatically if using vagrant.
6565
66+
### For HA, setup the load balancer node
67+
68+
Ideally, the load balancer node will be a separate node. However, one of the
69+
master nodes can also serve as the load balancer for the cluster. [HAProxy](https://www.haproxy.org/)
70+
is used in these instructions.
71+
72+
```bash
73+
sudo swupd bundle-add haproxy
74+
sudo systemctl enable haproxy
75+
```
76+
77+
Edit the master IP addresses and load balancer address and ports in [`haproxy.cfg.example`](haproxy.cfg.example)
78+
to match the IPs for the new cluster. If using a master node for the load balancer
79+
make sure that the `frontend bind` port is different than the Kubernetes API port, 6443.
80+
If using a separate machine for load balancing, the port can be 6443 if desired.
81+
82+
```bash
83+
sudo mkdir -p /etc/haproxy
84+
sudo cp haproxy.cfg.example /etc/haproxy/haproxy.cfg
85+
sudo systemctl start haproxy
86+
```
87+
6688
## Bring up the master
6789

6890
Run [`create_stack.sh`](create_stack.sh) on the master node. This sets up the
@@ -75,8 +97,9 @@ more information.
7597

7698
> NOTE: Before running [`create_stack.sh`](create_stack.sh) script, make sure to export
7799
the necessary environment variables if needed to be changed. By default it will use
78-
`CLRK8S_CNI` to be canal, and `CLRK8S_RUNNER` to be crio. Cilium is tested only in the
79-
Vagrant.
100+
`CLRK8S_CNI` to be canal, and `CLRK8S_RUNNER` to be crio. Cilium is tested only in the
101+
Vagrant. If creating an HA cluster, make sure to specify `LOAD_BALANCER_IP` and
102+
`LOAD_BALANCER_PORT`.
80103

81104
```bash
82105
# default shows help
@@ -86,6 +109,13 @@ Vagrant.
86109
In order to enable running greater than 110 pods per node, set the environment
87110
variable `HIGH_POD_COUNT` to any non-empty value.
88111

112+
If creating an HA cluster, join the other master nodes to the cluster.
113+
114+
```bash
115+
kubeadm join <load-balancer-ip>:<load-balancer-port> --token <token> --discovery-token-ca-cert-hash <hash> \
116+
--control-plane --certificate-key <certificate-key> --cri-socket=/run/crio/crio.sock
117+
```
118+
89119
## Join Workers to the cluster
90120

91121
```bash
@@ -94,6 +124,9 @@ kubeadm join <master-ip>:<master-port> --token <token> --discovery-token-ca-cert
94124

95125
Note: Remember to append `--cri-socket=/run/crio/crio.sock` to the join command generated by the master.
96126

127+
If creating an HA cluster, join the other worker nodes to the cluster. The same way,
128+
but replacing the `<master-ip>:<master-port>` with `<load-balancer-ip>:<load-balancer-port>`.
129+
97130
On workers just use the join command that the master spits out. There nothing
98131
else you need to run on the worker. All the other Kubernetes customizations are pushed
99132
in from master via the values setup in the `kubeadm.yaml` file.

clr-k8s-examples/create_stack.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ SCRIPT_DIR="$(dirname "${BASH_SOURCE[0]}")"
1414
: ${MASTER_IP:=}
1515
: ${CERT_SANS:=}
1616
HIGH_POD_COUNT=${HIGH_POD_COUNT:-""}
17+
LOAD_BALANCER_IP=${LOAD_BALANCER_IP:-""}
18+
LOAD_BALANCER_PORT="${LOAD_BALANCER_PORT:-6444}"
1719

1820
# versions
1921
CANAL_VER="${CLRK8S_CANAL_VER:-v3.10}"
@@ -90,7 +92,13 @@ function cluster_init() {
9092
echo "/var/lib/etcd exists! skipping init."
9193
return
9294
fi
93-
sudo -E kubeadm init --config=./kubeadm.yaml
95+
96+
if [[ -n "${LOAD_BALANCER_IP}" ]]; then
97+
sed -i "s/ClusterConfiguration/ClusterConfiguration\ncontrolPlaneEndpoint: ${LOAD_BALANCER_IP}:${LOAD_BALANCER_PORT}/g" ./kubeadm.yaml
98+
fi
99+
# upload-certs will automatically upload certificates that should be shared
100+
# across control-plane nodes in HA clusters. It is harmless in non-HA cases.
101+
sudo -E kubeadm init --upload-certs --config=./kubeadm.yaml
94102

95103
rm -rf "${HOME}/.kube"
96104
mkdir -p "${HOME}/.kube"
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
global
2+
log /dev/log local0
3+
chroot /var/lib/haproxy
4+
stats socket /run/haproxy-master.sock mode 660 level admin
5+
stats timeout 30s
6+
user haproxy
7+
group haproxy
8+
daemon
9+
# Default SSL material locations
10+
ca-base /etc/ssl/certs
11+
ssl-default-bind-ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:RSA+AESGCM:RSA+AES:!aNULL:!MD5:!DSS
12+
ssl-default-bind-options no-sslv3
13+
defaults
14+
log global
15+
mode http
16+
option httplog
17+
option dontlognull
18+
timeout connect 5000
19+
timeout client 50000
20+
timeout server 50000
21+
timeout tunnel 4h
22+
frontend kubernetes
23+
bind 10.0.0.100:6444
24+
option tcplog
25+
mode tcp
26+
default_backend kubernetes-master-nodes
27+
28+
backend kubernetes-master-nodes
29+
mode tcp
30+
balance source
31+
option tcp-check
32+
server master-1 10.0.0.100:6443 check fall 3 rise 2
33+
server master-2 10.0.0.101:6443 check fall 3 rise 2
34+
server master-3 10.0.0.102:6443 check fall 3 rise 2

clr-k8s-examples/setup_system.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ if [[ -n "${HIGH_POD_COUNT}" ]]; then
210210
fi
211211
echo "Reloading daemons..."
212212
daemon_reload
213-
echo "Enabling Kublet runner..."
213+
echo "Enabling kubelet runner..."
214214
enable_kubelet_runner
215215
echo "Ensuring system is ready..."
216216
ensure_system_ready

0 commit comments

Comments
 (0)