Setting Up K3S on K1 Cluster Board

Introduction to K3S

K3s is a lightweight Kubernetes distribution designed for resource-constrained environments such as IoT devices, edge computing, and small clusters. It is certified by the Cloud Native Computing Foundation (CNCF) and provides full Kubernetes functionality with a smaller footprint.

Core Features

  • Lightweight: Only 10% the size of a typical Kubernetes installation.
  • Easy to Install: Simple installation process with minimal additional configuration.
  • Automatic Updates: Built-in auto-update mechanism ensures the latest version is always running.
  • Embedded Database: Defaults to SQLite database, eliminating the need for an external database.
  • ARM Architecture Support: Ideal for low-power devices like Raspberry Pi or custom RISC-V boards.
  • Low Resource Requirements: Designed for systems with limited CPU and memory resources, ensuring efficient operation.

Environment Preparation

Obtaining IP Addresses

After starting the cluster board, first obtain the IP addresses of each board:

Method 1:

Open the router’s management interface and locate the IP addresses of each node.

Method 2:

Use a serial tool to connect to the cluster board and enter the command:

ifconfig

Method 3:

Use fping to scan the IP addresses in the subnet from another machine

If fping is not installed, you need to install it first

sudo apt update
sudo apt install fping
fping -a 192.168.2.1 192.168.2.255 -g -q
192.168.2.113
192.168.2.116
192.168.2.117
192.168.2.120

Then use the arp tool to find the MAC addresses corresponding to the IP addresses

arp   
地址                     类型   硬件地址           标志 Mask           接口
192.168.2.116           ether   fe:fe:fe:12:34:58   C                     end1
192.168.2.117           ether   fe:fe:fe:12:34:59   C                     end1
192.168.2.113           ether   fe:fe:fe:12:34:66   C                     end1
192.168.2.120           ether   fe:fe:fe:12:34:67   C                     end1

MAC addresses with the same first few digits belong to our cluster, allowing us to obtain the IP addresses of each K1 core board.

Current example cluster IPs are: 192.168.2.113, 192.168.2.116, 192.168.2.117, 192.168.2.120, with 120 being the master node.

Installing k3s

Connect to the four nodes via SSH

Downloading k3s

Download the community-packaged k3s executable

https://github.com/CARV-ICS-FORTH/k3s/releases
bit-brick-desktop% ls
k3s-riscv64.gz.aa k3s-riscv64.gz.ab k3s-riscv64.gz.ac

Extract the k3s executable

Since the precompiled k3s package is split into three files, you need to merge them into one file, decompress it, and add execution permissions

bit-brick-desktop% cat k3s-riscv64.gz.a* > k3s-riscv64.gz
bit-brick-desktop% gzip -d k3s-riscv64.gz
bit-brick-desktop% chmod +x k3s-riscv64

Run the k3s-riscv64 command to confirm it can execute

    bit-brick-desktop% ./k3s-riscv64 
  NAME:
  k3s-riscv64 - Kubernetes, but small and simple
   
  USAGE:
  k3s-riscv64 [global options] command [command options] [arguments...]
   
  VERSION:
  v1.31.1+k3s-34f8fa8d (34f8fa8d)
   
  COMMANDS:
  server           Run management server
  agent           Run node agent
  kubectl         Run kubectl
  crictl           Run crictl
  ctr             Run ctr
  check-config     Run config check
  token           Manage bootstrap tokens
  etcd-snapshot    
  secrets-encrypt Control secrets encryption and keys rotation
  certificate     Manage K3s certificates
  completion       Install shell completion script
  help, h         Shows a list of commands or help for one command
   
  GLOBAL OPTIONS:
   --debug                     (logging) Turn on debug logs [$K3S_DEBUG]
   --data-dir value, -d value (data) Folder to hold state default /var/lib/rancher/k3s or ${HOME}/.rancher/k3s if not root [$K3S_DATA_DIR]
   --help, -h                 show help
   --version, -v               print the version

Copy the k3s-riscv64 file to /usr/local/bin/ and rename it to k3s

    bit-brick-desktop% sudo cp k3s-riscv64 /usr/local/bin/k3s

Note: The above steps need to be executed on all four nodes

Installing k3s on the Master Node

My master node is 192.168.2.120

First, download the k3s.sh script

    curl -sfL https://get.k3s.io > k3s.sh 
   chmod +x k3s.sh

Execute the k3s.sh script

    bit-brick-desktop%  INSTALL_K3S_EXEC="server --advertise-address 192.168.2.120" INSTALL_K3S_SKIP_DOWNLOAD="true" bash -x ./k3s.sh      

INSTALL_K3S_SKIP_DOWNLOAD="true" indicates skipping the download of the k3s binary and using the local k3s binary instead.

Check the status

    systemctl status k3s
  ● k3s.service - Lightweight Kubernetes
      Loaded: loaded (/etc/systemd/system/k3s.service; enabled; preset: enabled)
      Active: active (running) since Tue 2025-04-22 15:25:10 CST; 1min 1s ago
      Docs: https://k3s.io
  Main PID: 881 (k3s-server)
      Tasks: 54
      Memory: 630.7M (peak: 648.7M)
          CPU: 2min 22.682s
      CGroup: /system.slice/k3s.service
              ├─ 881 "/usr/local/bin/k3s server"
              └─1742 "containerd "

The output should be active (running).

Check node status

Use the command to check the node

    sudo kubectl get nodes

The result should be

    spacemit-k1-x-bit-brick-board% sudo kubectl get nodes
[sudo] bit-brick 的密码:
NAME STATUS ROLES AGE VERSION
spacemit-k1-x-bit-brick-board Ready control-plane,master 2m51s v1.31.1+k3s-34f8fa8d

The master node should display Ready (if it shows NotReady, it is usually due to the network plugin not being configured).

Obtain the join token

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

This token is used for worker nodes to join the cluster.

Installing k3s on Agent Nodes

k3s does not allow duplicate hostnames, so first set unique hostnames for each node

sudo hostnamectl set-hostname node-113

Of course, you can also specify the node name during the K3S installation Proceed similarly for the other nodes

Example for 192.168.2.113:

# 以192.168.2.113为例:

K3S_URL=https://192.168.2.120:6443 \
K3S_TOKEN="K105d480b39525f7b32cd63980819ab20284ba0f3edf4d41e9db3edc7428b205fbd::server:92e4391689e15760421cda0859751854" \
INSTALL_K3S_SKIP_DOWNLOAD="true" \
INSTALL_K3S_EXEC="agent --node-name node-113" \
bash -x ./k3s.sh

Similarly, install on the 116 node


K3S_URL=https://192.168.2.120:6443 \
K3S_TOKEN="K105d480b39525f7b32cd63980819ab20284ba0f3edf4d41e9db3edc7428b205fbd::server:92e4391689e15760421cda0859751854" \
INSTALL_K3S_SKIP_DOWNLOAD="true" \
INSTALL_K3S_EXEC="agent --node-name node-116" \
bash -x ./k3s.sh

Similarly, install on the 117 node

  K3S_URL=https://192.168.2.120:6443 \
K3S_TOKEN="K105d480b39525f7b32cd63980819ab20284ba0f3edf4d41e9db3edc7428b205fbd::server:92e4391689e15760421cda0859751854" \
INSTALL_K3S_SKIP_DOWNLOAD="true" \
INSTALL_K3S_EXEC="agent --node-name node-117" \
bash -x ./k3s.sh

Once everything is set up, run the command on the master node to check the node status

spacemit-k1-x-bit-brick-board% sudo kubectl get nodes -o wide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
node-113 Ready <none> 2m29s v1.31.1+k3s-34f8fa8d 192.168.2.113 <none> Bianbu 2.1 6.6.63 containerd://1.7.21-k3s2
node-116 Ready <none> 53s v1.31.1+k3s-34f8fa8d 192.168.2.116 <none> Bianbu 2.1 6.6.63 containerd://1.7.21-k3s2
node-117 Ready <none> 9s v1.31.1+k3s-34f8fa8d 192.168.2.117 <none> Bianbu 2.1 6.6.63 containerd://1.7.21-k3s2
spacemit-k1-x-bit-brick-board Ready control-plane,master 22m v1.31.1+k3s-34f8fa8d 192.168.2.120 <none> Bianbu 2.1 6.6.63 containerd://1.7.21-k3s2

We have now completed the installation of the K3S cluster on the K1 cluster board. You can now manage your cluster board using K3S. ^_^

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top