IntroArchitectureSingle Server SetupHigh Availability SetupSetting up a single node clusterIngressResources
Intro
- K3s is a full blown K8s distribution packaged as a single binary. It allows setting up the K8s cluster much easier as we only have to install a single binary, which installs all the required control-plane components as pods in the
kube-system
namespace.
- K3s uses SQLite as the storage backend by default, also supports MySQL, Postgres and ETCD as the storage backend.
- K3s automatically restarts after node reboots or if the process crashes or is killed (resilient)
- Installs the following by default:
containerd
as the container runtime- Flannel (CNI)
- CoreDNS
- Traefik (Ingress Controller)
- KlipperLB - load balancer solution to allow the Traefik load balancer service (Traefik proxy) to be available on port 80 and 443 on the node
- K3s monitors the manifests directory and installs all the resources present in it -
/var/lib/rancher/k3s/server/manifests
- K3s comes with
HelmChart
CRD to automate installing Helm charts when the cluster is bootstrapped. It avoids having to install the helm chart using the command line as an additional step.HelmChartConfig
CRD can be used to modify the static config (values.yaml
) in the helm chart.
Architecture
- A server node is defined as a host running the
k3s server
command, with control-plane and datastore components managed by K3s.
- An agent node is defined as a host running the
k3s agent
command, without any datastore or control-plane components.
- Both servers and agents run the kubelet, container runtime, and CNI.
Single Server Setup
Single server setups use a local SQLite DB to store the cluster state. Embedded SQLite is not supported in multi-server configuration.
High Availability Setup
When using embedded etcd DB, we need at least 3 server nodes (master nodes). This is required to have quorum in case a master node goes down.
If instead, we’re using an external DB to store the cluster state, we can get away with 2 master nodes.
Setting up a single node cluster
Run
curl -sfL https://get.k3s.io | sh -s - --write-kubeconfig-mode 600
on any node to start a K3s cluster on the node. It will automatically install the required utilities like kubectl
and will also create a kubeconfig
file at /etc/rancher/k3s/k3s.yaml
which will be automatically referenced by kubectl
.If you’re planning to use
helm
along with the K3s setup, you need to move the kube config file to .kube
directory - sudo mv /etc/rancher/k3s/k3s.yaml ~/.kube/config
K3s is much better to setup single node containerized applications when compared to docker-compose.
Ingress
Since K3s clusters come with ingress controller pre-installed, we can directly create ingress resources to route external traffic to services within the cluster.
Resources
- Official Docs - amazing documentation to get anything done
- Well explained how to setup a K3s cluster with GitOps - Single-node Kubernetes Clusters Using K3s with Benefits of GitOps • Lasse Højgaard • GOTO 2021 - YouTube