K3s is a free and open-source [Link] fully certified Kubernetes-compliant distribution [Link].

It offers a simplified Kubernetes deployment as a lightweight single binary (~45MB) that implements Kubernetes APIs.

Popular features of K3s:

  • Lightweight (uses less than 512 MB of RAM),
  • Full ARM architecture support (e.g. Raspberry Pi),
  • Multi-node or single-node cluster,
  • Edge computing and production ready!

INSTALLATION

Easiest way (takes a few seconds, no interaction required):

curl -sfL https://get.k3s.io | sh -

Run the following command to allow any user to interact with K3s without sudo. Not recommended for production, only for test environments.

sudo chmod 777 /etc/rancher/k3s/k3s.yaml

Check the newly deployed nodes:

k3s kubectl get nodes

Deploy a test application:

k3s kubectl create deployment hello-node --image=registry.k8s.io/echoserver:1.4

Check the deployment and its pods:

k3s kubectl get deployments
k3s kubectl get pods

Copy the configuration file to another machine on the network to manage K3s remotely:

scp /etc/rancher/k3s/k3s.yaml userName@10.10.10.10:.

Note: Replace the username and IP with those of the destination machine.


JOINING AGENTS TO THE CLUSTER

Copy the token that authorizes agents to join the server:

cat /var/lib/rancher/k3s/server/node-token

Then, define the environment variables on the machine that will be configured as a new agent:

export K3S_TOKEN=<paste the node-token here>
export K3S_TOKEN=https://10.10.10.1:6443

Note: Replace the values above with the node token from the first command and the IP address of the K3s server.


CONFIGURING AND ACCESSING THE DASHBOARD

Deploy the dashboard [Link]:

GITHUB_URL=https://github.com/kubernetes/dashboard/releases
VERSION_KUBE_DASHBOARD=$(curl -w '%{url_effective}' -I -L -s -S ${GITHUB_URL}/latest -o /dev/null | sed -e 's|.*/||')
k3s kubectl create -f https://raw.githubusercontent.com/kubernetes/dashboard/${VERSION_KUBE_DASHBOARD}/aio/deploy/recommended.yaml

Create the admin Service Account:

nano dashboard.admin-user.yml
apiVersion: v1
kind: ServiceAccount
metadata:
name: admin-user
namespace: kubernetes-dashboard

Create the RBAC (Role-based access control) for the admin Service Account:

nano dashboard.admin-user-role.yml
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: admin-user
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: admin-user
namespace: kubernetes-dashboard

Deploy both:

k3s kubectl create -f dashboard.admin-user.yml -f dashboard.admin-user-role.yml

Get the admin token:

k3s kubectl -n kubernetes-dashboard create token admin-user

Start the proxy:

k3s kubectl proxy

Note: The proxy is only accessible from within the server. Do not bind it to 0.0.0.0, as the latest version of the dashboard will not allow admin access from outside localhost without HTTPS. To securely connect, establish an SSH tunnel as follows.

Establish an SSH tunnel to the proxy:

ssh 190.10.10.1 -L 8001:localhost:8001 -N

With the proxy running and the SSH tunnel forwarding traffic, navigate to http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/


OTHER POSTS

Minikube on Ubuntu 22.04 [Link].

MicroK8s on Ubuntu 22.04 [Link].

K8s Persistent Volumes [Link].

K8s Cheat Sheet [Link].

K8s Dashboard [Link].