Skip to content

Install k3s

Setup K3s Kubernetes Cluste

Firstly, we need to setup and bootstrap the K3s cluster with the installation script. It’s simple to set up a Server and an Agent. In this article, I will use AWS EC2 instances to setup the K3s cluster.

We have two AWS EC2 instances:

  • k3s-dev-master (K3s Server)
  • k3s-dev-worker (K3s Agent)

Official K3s Documentation: https://docs.k3s.io

K3s Server (ControlPlane/Master Node)

On the k3s-dev-master instance, run the following installation script to bootstrap the K3s server, also known as Kubernetes ControlPlane/Master Node.

curl -sfL https://get.k3s.io | sh -s - server \
    --write-kubeconfig-mode 644 \
    --node-taint "CriticalAddonsOnly=true:NoExecute"

If you want to make your K3s server as a ControlPlane/Master only, Make sure you add CriticalAddonsOnly=true:NoExecute Node taint when bootstrapping the K3s server.

Alternatively, you can also add Node taints with the kubectl command-line tool.

kubectl taint node k3s-dev-master CriticalAddonsOnly=true:NoExecute
kubectl taint node k3s-dev-master node-role.kubernetes.io/master=true:NoSchedule
kubectl taint node k3s-dev-master node-role.kubernetes.io/control-plane=true:NoSchedule

K3s Agent (Worker Node)

On k3s-dev-worker instance, run the following installation script to bootstrap K3s Agent also known as Kubernetes Worker Node to join the ControlPlane/Master Node.

curl -sfL https://get.k3s.io | sh -s - agent \
    --server https://<172.16.x.x>:6443 \
    --token K10d47c3a1abbbc24647fc37f9531ee6d9145d485408dc19f0bf4964c82beeaf175::server:91d5e063491d81783cab2bf1e728e4f1
  • -server Set your K3s Server’s URL that includes IP address and port number.
  • -token Set your K3s Server’s token. You can find that token in your K3s Server’s file path /var/lib/rancher/k3s/server/node-token or /var/lib/rancher/k3s/server/token.

To get K3s Server’s token,

cat /var/lib/rancher/k3s/server/node-token
K10d47c3a1abbbc24647fc37f9531ee6d9145d485408dc19f0bf4964c82beeaf175::server:91d5e063491d81783cab2bf1e728e4f1

Add label to mark Kubernetes Worker Node as Worker role.

kubectl label node k3s-dev-worker node-role.kubernetes.io/worker=true

Finally, we can get nodes with kubectl command line tool

kubectl get nodes -o wide
NAME                 STATUS   ROLES                  AGE   VERSION        INTERNAL-IP      EXTERNAL-IP   OS-IMAGE             KERNEL-VERSION       CONTAINER-RUNTIME
k3s-dev-master       Ready    control-plane,master   8d    v1.28.6+k3s2   172.x.x.x        <none>        Ubuntu 22.04.3 LTS   5.15.0-94-generic    containerd://1.7.11-k3s2
k3s-dev-worker       Ready    worker                 8d    v1.28.6+k3s2   172.x.x.x        <none>        Ubuntu 22.04.3 LTS   5.15.0-94-generic    containerd://1.7.11-k3s2
  • https://k3s.io/
  • https://zawzaww.github.io/posts/automated-k3s-cluster-upgrades/
  • https://github.com/k3s-io/k3s
  • https://traefik.io/glossary/k3s-explained/
Feedback