Long time no update on this blog because busy with a lot of work in real life but I'm committed to trying to update at least 1 post per month again. Starting today, I'm share about K3s. often when we want to learn something it is hindered by resources and so on, as well as kubernetes, but I think that was originally not an excuse, in this case when we want to learn kubernetes and our resources are limited K3s can be a solution.
K3s is Lightweight Kubernetes. Easy to install, half the memory, all in a binary of less than 100 MB. K3s great for Homelab, Edge, Internet Of Things (IoT), Continous Integration (CI), Development, Single board computers (ARM) and etc. K3s is a fully compliant kubernetes with some enhancements like : minimal container image, lightweight datastore, wrapped in simple launcher, secured, external dependencies have been minimized, etc. Let's practices !
Lab Summary :
- Requirements
- Installation
- Cluster Access
- Adding Nodes
- Uninstall / Destroy Cluster
Requirements
K3s is very lightweight, but has some minimum requirements as outlined below.
- if deploy cluster with multiple nodes, hostname can't be same
- Architecture
- x86_64
- armhf
- armd64/aarch64
- s390x
- Operating System
- SUSE based
- Debian Based
- RHEL Based
- Rasber
- Spesifications
- Server : 2 Cores, 2GB Memory
- Agent : 1 core 512MB Memory
# recommended to turn off ufw
$ ufw disable
# if needed to keep ufw enabled
$ ufw allow 6443/tcp #apiserver
$ ufw allow from 10.42.0.0/16 to any #pods
$ ufw allow from 10.43.0.0/16 to any #services
Installation
Let's try install
# bacic installation
$ curl -sfL https://get.k3s.io | sh -
# example disable flannel
$ curl -sfL https://get.k3s.io | sh -s - --flannel-backend none
This script will execute installation process and runs K3s services on our host, we can also manual install with Binary if we need some customization parameter on our cluster, the step is :
- Download K3s release binary releases , recommend to select latest versions
- Custom configuration parameter references server configuration
# using binary to disable flannel
$ INSTALL_K3S_EXEC="--flannel-backend none" k3s server
# multiple arguments
$ k3s server \
--write-kubeconfig-mode "0644" \
--tls-san "example.local" \
--node-label "worker=true" \
--node-label "monitoring=true" \
--cluster-init
multiple configuration use files also supported, the configuration files are read by default from /etc/rancher/k3s/config.yaml and /etc/rancher/k3s/config.yaml.d/*.yaml
Cluster Access
By default, K3s config will store at /etc/rancher/k3s directory. similarly to K8s, we need to define a configuration file location.
$ export KUBECONFIG=/etc/rancher/k3s/k3s.yaml
As an Alternative, we can define the config file in our home directory :
$ mkdir -p ~/.kube
$ sudo k3s kubectl config view --raw | tee ~/.kube/config
$ chmod 600 ~/.kube/config
Adding Nodes
if we want to add new nodes to our cluster, we need to execute command :
# get token on K3s Server
$ cat /var/lib/rancher/k3s/server/node-token
# execute on new nodes
$ curl -sfL https://get.k3s.io | K3S_URL=https://<ip/domain-server-k3s>:6443 K3S_TOKEN=<paste-token> sh -
Uninstalling / Destroy Cluster
# Uninstall server $ /usr/local/bin/k3s-uninstall.sh # Uninstall Agents $ /usr/local/bin/k3s-agent-uninstall.sh
Make sure not exec this on production cluster, K3s my cause data loss!!!
yep, that's all for now thanks, and happy practicing