Installing k3s on rasberry pi 5

Table of Contents

Photo by Jainath Ponnala on Unsplash

Raspberry Pi Imager

ssh とか昔は mkdir とかやった記憶なんですが,今は Imager の設定で ssh や鍵認証まで設定できるようになっていました.

Static IP

現在は NetworkManager で設定するのがナウいようです.
初期は設定ファイルがないので名前を設定することでまずはファイルを生成します.

yuzumone@raspberrypi:~ $ nmcli connection show
NAME                UUID                                  TYPE      DEVICE
Wired Connection 1  9f707e45-298e-39b3-80ef-5bbd96c03f46  ethernet  eth0

yuzumone@raspberrypi:~ $ nmcli connection modify 9f707e45-298e-39b3-80ef-5bbd96c03f46 connection.id wired_eth0

/etc/NetworkManager/system-connections 配下に 名前.nmconnection でファイルが生成されます.
あとは [ipv4] のところに設定します.

yuzumone@raspberrypi:~ $ sudo cat /etc/NetworkManager/system-connections/wired_eth0.nmconnection
[connection]
id=wired_eth0
uuid=9f707e45-298e-39b3-80ef-5bbd96c03f46
type=ethernet
autoconnect-priority=-999
interface-name=eth0
timestamp=1741091271

[ethernet]

[ipv4]
method=manual
addresses=192.168.0.100/24
gateway=192.168.0.1
dns=8.8.8.8;8.8.4.4;

[ipv6]
addr-gen-mode=default
method=auto

[proxy]

設定したあとは sudo systemctl restart NetworkManager をして適応します.

Storage

Longhorn を利用するので /var/lib/longhorn に mount することにします.

yuzumone@raspberrypi:~ $ sudo mkfs -t ext4 /dev/sda
yuzumone@raspberrypi:~ $ sudo mkdir /var/lib/longhorn
yuzumone@raspberrypi:~ $ sudo chmod 777 /var/lib/longhorn
yuzumone@raspberrypi:~ $ sudo mount -t ext4 /dev/sda /var/lib/longhorn

blkid で UUID を確認して /etc/fstab に追記しておきます.

yuzumone@raspberrypi:~ $ blkid
/dev/sda: UUID="919fb770-af9c-487f-a758-6190b524497c" BLOCK_SIZE="4096" TYPE="ext4"
yuzumone@raspberrypi:~ $ cat /etc/fstab
proc            /proc           proc    defaults          0       0
PARTUUID=b5d3bfc3-01  /boot/firmware  vfat    defaults          0       2
PARTUUID=b5d3bfc3-02  /               ext4    defaults,noatime  0       1
# a swapfile is not a swap partition, no line here
#   use  dphys-swapfile swap[on|off]  for that

UUID="919fb770-af9c-487f-a758-6190b524497c" /var/lib/longhorn ext4 defaults 0 0

swap off

swap の利用は非推奨なので off します.
cat /proc/swaps で確認ができます.

yuzumone@raspberrypi:~ $ sudo swapoff --all
yuzumone@raspberrypi:~ $ sudo systemctl stop dphys-swapfile
yuzumone@raspberrypi:~ $ sudo systemctl disable dphys-swapfile
yuzumone@raspberrypi:~ $ sudo systemctl status dphys-swapfile
yuzumone@raspberrypi:~ $ cat /proc/swaps
Filename                                Type            Size            Used            Priority

Enable cgroups

cgroup_memory=1 cgroup_enable=memory を /boot/firmware/cmdline.txt に追記.

yuzumone@raspberrypi:~ $ cat /boot/firmware/cmdline.txt
console=serial0,115200 console=tty1 root=PARTUUID=b5d3bfc3-02 rootfstype=ext4 fsck.repair=yes rootwait cgroup_memory=1 cgroup_enable=memory

Install k3s

クラスタは組まないのでワンライナーのやつで適当にインストールします.
クラスタを組む場合は ansible role を利用するのが良さそうです.

yuzumone@raspberrypi:~ $ curl -sfL https://get.k3s.io | sh -s - --write-kubeconfig-mode 644
yuzumone@raspberrypi:~ $ kubectl get nodes
NAME          STATUS   ROLES                  AGE   VERSION
raspberrypi   Ready    control-plane,master   17s   v1.31.6+k3s1

Install Longhorn

実際に立てるサービスは cloudflare-tunnel-ingress-controller を利用しようと思うので,内々で見れれば良いものは NodePort で適当にアクセスすることにします.

sudo apt -y install open-iscsi
helm repo add longhorn https://charts.longhorn.io
helm repo update
helm install longhorn longhorn/longhorn --namespace longhorn-system --create-namespace -f values.yaml
$ kubectl -n longhorn-system get po1
NAME                                        READY   STATUS    RESTARTS   AGE
engine-image-ei-c2d50bcc-mnnll              1/1     Running   0          10s
longhorn-driver-deployer-7fc7ffcb7f-mqkdg   1/1     Running   0          20s
longhorn-manager-l5ggl                      2/2     Running   0          20s
longhorn-ui-5fcc4bcfc7-dpgcw                1/1     Running   0          20s
longhorn-ui-5fcc4bcfc7-ll6wm                1/1     Running   0          20s