k3s icon indicating copy to clipboard operation
k3s copied to clipboard

Add support for RISC-V

Open chazapis opened this issue 1 year ago • 16 comments

Proposed Changes

Add support for the RISC-V architecture

Types of Changes

Add the architecture to the scripts involved in building and packaging K3s; no code changes. This is really possible through cross-compilation at the moment, ~so I am also attaching a script that can be used from inside an Ubuntu Docker image to build K3s for RISC-V (tested on an M1 MacBook)~ so an extra script takes care of preparing the cross-compile environment (edit: updated to reflect latest changes).

Verification

Starting from a clean checkout of the code, one can cross-compile for RISC-V ~in an Ubuntu 22.04 container~, by using the following command (edit: updated to reflect latest changes):

ARCH=riscv64 SKIP_IMAGE=true SKIP_VALIDATE=true SKIP_AIRGAP=true make

This will produce the dist/artifacts/k3s-riscv64 binary, which can be installed in a QEMU VM for verification. I provide a pre-compiled binary and instructions here.

Sample output from a RISC-V QEMU VM for knowing what to expect:

root@ubuntu:~# uname -a
Linux ubuntu 5.19.0-1012-generic #13~22.04.1-Ubuntu SMP Thu Jan 12 15:34:31 UTC 2023 riscv64 riscv64 riscv64 GNU/Linux
root@ubuntu:~# systemctl --no-pager status k3s
● k3s.service - Lightweight Kubernetes
     Loaded: loaded (/etc/systemd/system/k3s.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2023-06-14 11:54:03 UTC; 21min ago
       Docs: https://k3s.io
    Process: 1636 ExecStartPre=/bin/sh -xc ! /usr/bin/systemctl is-enabled --quiet nm-cloud-setup.service (code=exited, status=0/SUCCESS)
    Process: 1638 ExecStartPre=/sbin/modprobe br_netfilter (code=exited, status=0/SUCCESS)
    Process: 1639 ExecStartPre=/sbin/modprobe overlay (code=exited, status=0/SUCCESS)
   Main PID: 1640 (k3s-server)
      Tasks: 28
     Memory: 576.8M
        CPU: 13min 43.205s
     CGroup: /system.slice/k3s.service
             ├─1640 "/usr/local/bin/k3s server" "" "" "" "" "" "" "" "" "" "" "…
             └─1671 "containerd " "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" …

Jun 14 12:15:39 ubuntu k3s[1640]: E0614 12:15:39.202967    1640 kuberuntime_man…
Jun 14 12:15:39 ubuntu k3s[1640]: E0614 12:15:39.204361    1640 pod_workers…2m_k
Jun 14 12:15:47 ubuntu k3s[1640]: E0614 12:15:47.230229    1640 remote_runtime.…
Jun 14 12:15:47 ubuntu k3s[1640]: E0614 12:15:47.231011    1640 kuberuntime_san…
Jun 14 12:15:47 ubuntu k3s[1640]: E0614 12:15:47.231508    1640 kuberuntime_man…
Jun 14 12:15:47 ubuntu k3s[1640]: E0614 12:15:47.233205    1640 pod_workers…th-p
Jun 14 12:15:53 ubuntu k3s[1640]: E0614 12:15:53.273022    1640 remote_runtime.…
Jun 14 12:15:53 ubuntu k3s[1640]: E0614 12:15:53.273533    1640 kuberuntime_san…
Jun 14 12:15:53 ubuntu k3s[1640]: E0614 12:15:53.273851    1640 kuberuntime_man…
Jun 14 12:15:53 ubuntu k3s[1640]: E0614 12:15:53.274418    1640 pod_workers…2m_k
Hint: Some lines were ellipsized, use -l to show in full.
root@ubuntu:~# kubectl get nodes -o wide
NAME     STATUS   ROLES                  AGE   VERSION                      INTERNAL-IP   EXTERNAL-IP   OS-IMAGE             KERNEL-VERSION        CONTAINER-RUNTIME
ubuntu   Ready    control-plane,master   22m   v1.27.2+k3s-b66a1183-dirty   10.0.2.15     <none>        Ubuntu 22.04.2 LTS   5.19.0-1012-generic   containerd://1.7.1-k3s1

Testing

This change is not covered by testing, but I am not sure how this would be possible given limited support of the required utilities for the architecture. This could be initially marked as an "experimental" architecture, until the tools are available for testing.

Linked Issues

This PR is directly related to #7151.

User-Facing Change

NONE

Further Comments

~This should ideally be integrated with the Makefile and the automated build system, but I am not sure how these can support cross-compiling K3s - hence the build script. If someone can provide some hints on how to integrate, please do, as it would be really helpful to have an automated K3s release for RISC-V. I will be happy to help.~ (edit: The changes are now integrated with the K3s automated build system).

~Additionally, this PR is really the first step in the direction of RISC-V support. Utility images should also be made available for the architecture, starting with an image for a pause container. I have been unsuccessful in finding the sources and process of building rancher/mirrored-pause:3.6. Any pointers on that would also be very useful.~ (edit: Required images have been ported to the architecture, changes have been submitted as PRs to relevant projects, read on for details.)

chazapis avatar Jun 14 '23 12:06 chazapis