RISC-V Public Beta Platform Released · How to Run k3s on SG2042

Introduction

Kubernetes is an open-source container management platform that enables users to easily replicate, migrate, and deploy applications across clusters with its cross-cluster management feature.

As a lightweight distribution of Kubernetes, k3s offers smaller binary file size and lower resource consumption compared to traditional Kubernetes.

Using k3s not only reduces the cluster startup time but also minimizes the cluster’s resource consumption, making it an essential part of the RISC-V software ecosystem.

In this guide, we will show you how to run k3s on the SG2042 platform.

Part 1: Materials for this Experiment

  • One SG2042 server
  • Precompiled k3s binaries

Download the precompiled k3s binary files from: Releases · CARV-ICS-FORTH/k3s · GitHub

Part 2: Experiment Procedure

1. Download and Run k3s

First, download the precompiled k3s package:


Since the precompiled k3s package is divided into three files, they need to be merged into one:

Unzip the merged file and give the k3s-riscv64 file executable permission:


Test if the file can run by executing it. If the following message appears, it means it runs successfully:

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


==Note: Don’t forget to use sudo to avoid permission issues.==

Test again to see if k3s can run:

2. Download and Run the k3s Installation Script

Of course, having only the k3s binary files is not enough. We need to use the installation script to get the full k3s experience.

Download the k3s installation script: curl -sfL https://get.k3s.io > k3s-install.sh


Make the script executable: chmod +x k3s-install.sh

==Note: If you directly run ./k3s-install.sh, it will show an unsupported architecture error, so we need to pass additional parameters.==INSTALL_K3S_EXEC="server --disable metrics-server" INSTALL_K3S_SKIP_DOWNLOAD="true" bash -x ./k3s-install.sh

Check the status; if it shows active, it means k3s is running: systemctl status k3s

3.Run a k3s Container

Create a new file named hello-sg2042.yaml and copy the following content into it:

Modified from: https://raw.githubusercontent.com/CARV-ICS-FORTH/kubernetes-riscv64/main/examples/hello-kubernetes.yaml

apiVersion: v1
kind: Service
metadata:
  name: hello
spec:
  type: ClusterIP
  ports:
  - port: 8080
  selector:
    app: hello
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello
spec:
  replicas: 1
  selector:
    matchLabels:
      app: hello
  template:
    metadata:
      labels:
        app: hello
    spec:
      containers:
      - name: hello-kubernetes
        image: carvicsforth/hello-kubernetes:1.10.1
        env:
        - name: MESSAGE
          value: "Greeting from SG2042!"

Save and exit. Then, use this template to start a new container: sudo kubectl apply -f hello-sg2042.yaml

==Note: Don’t forget to use sudo; otherwise, it will show a permission error.==


Check the pod status: sudo kubectl get pods -o wide

(If the pod doesn’t show an IP address yet, please wait until it does.)

Use curl to fetch the web page; if it successfully fetches the page, it means the k3s container is running successfully:

4.Allow External Access

Although the page can be accessed from localhost by using curl, external computers cannot access it. So, how can we enable external access?

We need to modify the content of hello-sg2042.yaml. Open hello-sg2042.yaml with a text editor and modify it as follows:

apiVersion: v1
kind: Service
metadata:
  name: hello
spec:
  type: NodePort
  ports:
  - port: 8080
    targetPort: 8080
    nodePort: 30080
    protocol: TCP
  selector:
    app: hello
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello
spec:
  replicas: 1
  selector:
    matchLabels:
      app: hello
  template:
    metadata:
      labels:
        app: hello
    spec:
      containers:
      - name: hello-kubernetes
        image: carvicsforth/hello-kubernetes:1.10.1
        env:
        - name: MESSAGE
          value: "Greeting from SG2042!"

==Note: You can change the nodePort to which you want, but it must be chosen from the range 30000-32767.==

Access the page in the browser using http://175.8.161.253:30080 (replace 30080 with your chosen nodePort if you used a different one).

Part 3: Conclusion:

Thanks to the help of the community, k3s can now run on the SG2042 platform. However, since this fork has not been merged into the official k3s code, k3s does not officially support riscv64 yet.

References:

Running Guide for kubernetes-riscv64 GitHub - CARV-ICS-FORTH/kubernetes-riscv64: Status of work on running Kubernetes on RISC-V

Reprinted From: RISC-V Public Beta Platform Released · How to Run k3s on SG2042