Installing k3s on rasberry pi 5
Raspberry Pi Imager
Section titled “Raspberry Pi Imager”ssh とか昔は mkdir とかやった記憶なんですが,今は Imager の設定で ssh や鍵認証まで設定できるようになっていました.
Static IP
Section titled “Static IP”現在は NetworkManager で設定するのがナウいようです. 初期は設定ファイルがないので名前を設定することでまずはファイルを生成します.
yuzumone@raspberrypi:~ $ nmcli connection showNAME UUID TYPE DEVICEWired 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_eth0uuid=9f707e45-298e-39b3-80ef-5bbd96c03f46type=ethernetautoconnect-priority=-999interface-name=eth0timestamp=1741091271
[ethernet]
[ipv4]method=manualaddresses=192.168.0.100/24gateway=192.168.0.1dns=8.8.8.8;8.8.4.4;
[ipv6]addr-gen-mode=defaultmethod=auto
[proxy]設定したあとは sudo systemctl restart NetworkManager をして適応します.
Storage
Section titled “Storage”Longhorn を利用するので /var/lib/longhorn に mount することにします.
yuzumone@raspberrypi:~ $ sudo mkfs -t ext4 /dev/sdayuzumone@raspberrypi:~ $ sudo mkdir /var/lib/longhornyuzumone@raspberrypi:~ $ sudo chmod 777 /var/lib/longhornyuzumone@raspberrypi:~ $ sudo mount -t ext4 /dev/sda /var/lib/longhornblkid で UUID を確認して /etc/fstab に追記しておきます.
yuzumone@raspberrypi:~ $ blkid/dev/sda: UUID="919fb770-af9c-487f-a758-6190b524497c" BLOCK_SIZE="4096" TYPE="ext4"yuzumone@raspberrypi:~ $ cat /etc/fstabproc /proc proc defaults 0 0PARTUUID=b5d3bfc3-01 /boot/firmware vfat defaults 0 2PARTUUID=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 0swap off
Section titled “swap off”swap の利用は非推奨なので off します.
cat /proc/swaps で確認ができます.
yuzumone@raspberrypi:~ $ sudo swapoff --allyuzumone@raspberrypi:~ $ sudo systemctl stop dphys-swapfileyuzumone@raspberrypi:~ $ sudo systemctl disable dphys-swapfileyuzumone@raspberrypi:~ $ sudo systemctl status dphys-swapfileyuzumone@raspberrypi:~ $ cat /proc/swapsFilename Type Size Used PriorityEnable cgroups
Section titled “Enable cgroups”cgroup_memory=1 cgroup_enable=memory を /boot/firmware/cmdline.txt に追記.
yuzumone@raspberrypi:~ $ cat /boot/firmware/cmdline.txtconsole=serial0,115200 console=tty1 root=PARTUUID=b5d3bfc3-02 rootfstype=ext4 fsck.repair=yes rootwait cgroup_memory=1 cgroup_enable=memoryInstall k3s
Section titled “Install k3s”クラスタは組まないのでワンライナーのやつで適当にインストールします. クラスタを組む場合は ansible role を利用するのが良さそうです.
yuzumone@raspberrypi:~ $ curl -sfL https://get.k3s.io | sh -s - --write-kubeconfig-mode 644yuzumone@raspberrypi:~ $ kubectl get nodesNAME STATUS ROLES AGE VERSIONraspberrypi Ready control-plane,master 17s v1.31.6+k3s1Install Longhorn
Section titled “Install Longhorn”実際に立てるサービスは cloudflare-tunnel-ingress-controller を利用しようと思うので,内々で見れれば良いものは NodePort で適当にアクセスすることにします.
sudo apt -y install open-iscsihelm repo add longhorn https://charts.longhorn.iohelm repo updatehelm install longhorn longhorn/longhorn --namespace longhorn-system --create-namespace -f values.yaml$ kubectl -n longhorn-system get po1NAME READY STATUS RESTARTS AGEengine-image-ei-c2d50bcc-mnnll 1/1 Running 0 10slonghorn-driver-deployer-7fc7ffcb7f-mqkdg 1/1 Running 0 20slonghorn-manager-l5ggl 2/2 Running 0 20slonghorn-ui-5fcc4bcfc7-dpgcw 1/1 Running 0 20slonghorn-ui-5fcc4bcfc7-ll6wm 1/1 Running 0 20s