Creating a Highly Available K3s Cluster

K3s is a lightweight Kubernetes distribution, which is easy to install. It is a fully compliant Kubernetes distribution with an embedded SQLite database as the default datastore and supports external datastore such as PostgreSQL, MySQL, and etcd. K3s includes a local storage provider, a service load balancer, a Helm controller, and the Traefik ingress controller. It also automates and manages complex cluster operations such as distributing certificates. K3s are easier to use, and more lightweight, with a binary size of less than 100 MB. In other words, you can run a highly available, certified Kubernetes distribution designed for production workloads on nanodes as well.

However, for a highly available K3s cluster with two master nodes, you can use an external datastore and an external load balancer for balancing the TCP traffic on 80/http, 443/https, 3306/mysql, and 6443/Kubernetes API.

K3s Highly Available Architecture

Architecure of a highly available K3s cluster with an external databases

Infrastructure Requirements

Before You Begin

Creating a Kubernetes Cluster 

1. Connect to master 1, and run the following commands to start the K3s server and connect it to the external datastore:

$export K3S_DATASTORE_ENDPOINT="mysql://user:password@tcp(mysql.example.com:3306/rancher

$curl -sfL https://get.k3s.io |
INSTALL_K3S_EXEC="--write-kubeconfig-mode 644 -t agent-secret --tls-san
k3s.example.com --node-taint k3s-controlplane=true:NoExecute" sh -s -
server

Where:

2. Connect to master 2, and run the following commands to start the K3s server and connect it to the external datastore:  

$export K3S_DATASTORE_ENDPOINT="mysql://user:password@tcp(mysql.example.com:3306/rancher

$curl -sfL https://get.k3s.io |
INSTALL_K3S_EXEC="--write-kubeconfig-mode 644 -t agent-secret --tls-san
k3s.example.com --node-taint k3s-controlplane=true:NoExecute" sh -s -
server

3. To confirm that K3s has been set up successfully, run the following command on either of the K3s server nodes:

$sudo k3s kubectl get nodes 

          The output is similar to:

Java
 




xxxxxxxxxx
1


 
1
NAME      STATUS   ROLES    AGE    VERSION
2
master    Ready    master   168m   v1.18.2+k3s1
3
master2   Ready    master   61m    v1.18.2+k3s1


       Result: You have successfully set up a highly available K3s Kubernetes cluster.

Note: Because K3s server nodes are schedulable by default, the minimum number of nodes for an HA K3s server cluster is two server nodes and zero agent nodes. However, you can always add agent nodes designated to run your apps and services to your cluster.

 

 

 

 

Top