Build a Kubernetes HA cluster consisting of:
Virtual IP (VIP)
|
+-------------+
| HAProxy |
+-------------+
/ | \
/ | \
cp1 cp2 cp3
| |
worker1 worker2
Set hostnames:
hostnamectl set-hostname cp1 hostnamectl set-hostname cp2 hostnamectl set-hostname cp3 hostnamectl set-hostname worker1 hostnamectl set-hostname worker2
Add hosts file entries:
192.168.1.11 cp1 192.168.1.12 cp2 192.168.1.13 cp3 192.168.1.21 worker1 192.168.1.22 worker2
Disable swap:
swapoff -a sed -i '/swap/d' /etc/fstab
wget https://raw.githubusercontent.com/sandervanvugt/cka/master/install-cri.sh chmod +x install-cri.sh ./install-cri.sh
Run on ALL Kubernetes nodes.
frontend kubernetes
bind *:6443
default_backend kubeapi
backend kubeapi
balance roundrobin
server cp1 192.168.1.11:6443 check
server cp2 192.168.1.12:6443 check
server cp3 192.168.1.13:6443 check
Restart service:
systemctl restart haproxy systemctl enable haproxy
Verify:
ss -tlnp | grep 6443
Example Virtual IP:
192.168.1.100
Verify VIP assignment:
ip addr
kubeadm init \ --control-plane-endpoint "192.168.1.100:6443" \ --upload-certs \ --pod-network-cidr=192.168.0.0/16
--control-plane-endpoint.
mkdir -p $HOME/.kube sudo cp /etc/kubernetes/admin.conf \ $HOME/.kube/config sudo chown $(id -u):$(id -g) \ $HOME/.kube/config
Verify:
kubectl get nodes
Regenerate Worker Join:
kubeadm token create --print-join-command
Regenerate Control Plane Certificate Key:
kubeadm init phase upload-certs --upload-certs
kubeadm join 192.168.1.100:6443 \ --token <token> \ --discovery-token-ca-cert-hash sha256:<hash> \ --control-plane \ --certificate-key <certificate-key>
Expected Result:
kubectl get nodes
cp1 Ready cp2 Ready cp3 Ready
Run on BOTH cp2 and cp3:
mkdir -p $HOME/.kube sudo cp /etc/kubernetes/admin.conf \ $HOME/.kube/config sudo chown $(id -u):$(id -g) \ $HOME/.kube/config
Verify:
kubectl get nodes
kubeadm join 192.168.1.100:6443 \ --token <token> \ --discovery-token-ca-cert-hash sha256:<hash>
Run on:
kubectl apply -f calico.yaml
Verify:
kubectl get nodes
kubectl get nodes
| Node | Status | Role |
|---|---|---|
| cp1 | Ready | control-plane |
| cp2 | Ready | control-plane |
| cp3 | Ready | control-plane |
| worker1 | Ready | worker |
| worker2 | Ready | worker |