Deploy k3s(kubernetes) ha cluster with 3 master nodes
Deploy k3s(kubernetes) ha cluster with 3 master node with etcd storage
Why k3s ? Read there
Req:
ubuntu 20.04
6 nodes(you can use 2 master nodes for make HA Cluster with mysql or postgres database as cluster backend)
WAY1 – Using etcd as database backend
In K3s v1.19.1+, embedded etcd is used.
To run K3s in this mode, you must have an odd number of server nodes. We recommend starting with three nodes.
Prepare file /etc/hosts on all nodes cluster.
192.168.122.104 k3s-master-1
192.168.122.105 k3s-master-2
192.168.122.106 k3s-master-3
192.168.122.101 k3s-worker-1
192.168.122.102 k3s-worker-2
192.168.122.103 k3s-worker-3
MASTER 1 INIT
Install k3s with official way with latest version(1.19.3)
export K3S_KUBECONFIG_MODE="644"
export INSTALL_K3S_CHANNEL="latest"
curl -sfL https://get.k3s.io | sh -
get token for k3s
cat /var/lib/rancher/k3s/server/node-token
kill porcess on port 6443
kill -9 $(lsof -i :6443 | grep LISTEN | awk '{print $2}')
And make cluster init
K3S_TOKEN="K10da6d3b43164285d34f09aa5c38464c94ab7b5254381347cad1388430934d58e1::server:0e14477cea9cf607c150d6e35425274e" k3s server --cluster-init
wait minute and press ctrl+c. Skip errors
Restart k3s service via systemctl
systemctl restart k3s
MASTER 2,3 ADD to Master1
Install k3s
export K3S_KUBECONFIG_MODE="644"
export INSTALL_K3S_CHANNEL="latest"
curl -sfL https://get.k3s.io | sh -
Connect to exist masters
kill -9 $(lsof -i :6443 | grep LISTEN | awk '{print $2}')
K3S_TOKEN="K10da6d3b43164285d34f09aa5c38464c94ab7b5254381347cad1388430934d58e1::server:0e14477cea9cf607c150d6e35425274e" k3s server --server https://k3s-master-1:6443
wait minute and press ctrl+c. Skip errors
Restart k3s service via systemctl
systemctl restart k3s
Done
WORKERS ADD
export K3S_KUBECONFIG_MODE="644"
export INSTALL_K3S_CHANNEL="latest"
export K3S_URL="https://k3s-master-1:6443"
export K3S_TOKEN="K10da6d3b43164285d34f09aa5c38464c94ab7b5254381347cad1388430934d58e1::server:0e14477cea9cf607c150d6e35425274e"
curl -sfL https://get.k3s.io | sh -
SEE CLUSTER STATUS
root@vm104:~# kubectl get node
NAME STATUS ROLES AGE VERSION
vm101 Ready worker 4m11s v1.19.3+k3s2
vm102 Ready worker 3m55s v1.19.3+k3s2
vm103 Ready worker 3m54s v1.19.3+k3s2
vm104 Ready etcd,master 15m v1.19.3+k3s2
vm105 NotReady etcd,master 9m44s v1.19.3+k3s2
vm106 Ready etcd,master 6m16s v1.19.3+k3s2