- Docker logs tail: Troubleshoot Docker containers with real-time logging - Wed, Sep 13 2023
- dsregcmd: Troubleshoot and manage Azure Active Directory (Microsoft Entra ID) joined devices - Thu, Aug 31 2023
- Ten sed command examples - Wed, Aug 23 2023
Kubernetes is not known for its ease of use, deployment, configuration, or management. Many different distributions are available, both on-premises and in the public cloud. K3s is a lightweight Kubernetes distribution from Rancher that provides a simple, easy distribution to use in setting up a production-grade Kubernetes cluster.
What is K3s?
K3s is an open-source Kubernetes distribution designed for very small, resource-constrained environments where low-end or edge hardware can be used. It can even run well on Raspberry Pi devices and run optimally on ARM architectures, with ARM64 and ARMv7 supported, and only needs 512 MB of RAM. K3s is a production-ready Kubernetes distribution that can handle many types of workloads.
Even though it is a streamlined version of Kubernetes, it is still a fully compliant Kubernetes distribution that includes the core features of K8s, including container orchestration, networking, security, and storage. K3s brings many benefits with its stripped-down architecture, including a much-reduced attack surface and a small footprint with the binary itself. In addition, with a single binary, K3s can be updated easily, significantly reducing dependencies.
Below is a look at the high-level architecture of the K3s Server and the K3s Agent.
Key features of K3s
K3s Kubernetes is designed to simplify the deployment, management, and scaling of Kubernetes clusters. Some of the key features of K3s Kubernetes include:
- Lightweight and portable—The single K3s file is optimized for low-end ARM, virtual nodes, and cloud environments. K3s is also portable and can be run on any operating system that supports Docker.
- Easy to install and configure—K3s Kubernetes is designed to be easy to install and configure. K3s can be installed using a simple script that automates the installation process. You can also use the open-source utility K3sup, which we will see below.
- High availability—K3s Kubernetes supports high availability by default. It uses the etcd database to store the cluster state and replicates etcd for HA. K3s also supports automatic leader election, which ensures that the cluster can continue to operate in the event of node failure.
- Security—K3s Kubernetes includes several security features to protect your K3s cluster workloads from unauthorized access and attackers. Role-based access control (RBAC) is included, which allows administrators to define fine-grained access controls for users and applications. It also encrypts traffic communication between cluster nodes.
- Ingress controller—A built-in ingress controller with K3s allows you to expose your applications to the internet. The ingress controller supports multiple load-balancing algorithms, such as round-robin and IP hashing, and can be configured using a simple YAML file.
- Helm charts—Like other Kubernetes distributions, K3s Kubernetes includes support for Helm charts, which are packages of preconfigured Kubernetes resources.
K3s Prerequisites
Note the following prerequisites:
- Two nodes cannot have the same hostname unless you use the --with-node-id
- 512 MB RAM minimum
- CPU: 1 minimum
Install K3s
To install K3s Kubernetes, we can use the officially documented approach: Installation | K3s. Another great free, open-source utility allows you to quickly spin up K3s clusters, even with high availability, with only a few commands. The tool is K3sup (pronounced "ketchup"), and you can take a look at the official GitHub repository here: alexellis/k3sup: bootstrap K3s over SSH in < 60s 🚀 (github.com)
Install K3sup
K3sup is a command line tool that simplifies provisioning K3s clusters. To install K3sup:
curl -sLS https://get.k3sup.dev | sh sudo install k3sup /usr/local/bin/ k3sup –help
Connect the K3sup management station to your nodes
The K3sup utility needs to be able to connect to the K3s nodes using SSH with public key authentication. You can generate an SSH key and then copy it to the nodes. Note the commands:
ssh-key-gen
ssh-copy-id <user>@<server IP>
Create the K3s cluster
Now we can create our K3s cluster. We will first create the K3s server node.
k3sup install --ip <your server node IP> --tls-san <for HA VIP IP address> --cluster --user root --local-path ~/.kube/config --context k3s-ha --no-extras --k3s-extra-args "--flannel-iface=ens192 --node-ip <your server node IP>"
Join K3s nodes
Now that we have the server node created, we need to join the agent nodes (worker nodes).
k3sup join --ip <agent node IP> --server-ip <server node IP> --user root --k3s-extra-args "--flannel-iface=ens192 --node-ip <agent node IP>"
Finally, once you have joined your remaining agent nodes, you can view the K3s cluster using kubectl. Below, we run the command:
kubectl get nodes
Conclusion
K3s is a lightweight distribution of Kubernetes designed to simplify the installation, configuration, and management of Kubernetes. It provides core Kubernetes features, including container orchestration, networking, storage, and security. Resource-constrained environments will benefit from the efficiency of K3s, which can be installed on low-end hardware.
Subscribe to 4sysops newsletter!
Using K3s in addition to the K3sup utility allows admins to quickly and easily provision production-grade Kubernetes clusters in just a matter of minutes with the high availability of the etcd database, which is crucial for production workloads.