しゅれログ

備忘録です。

k3sのagentをRaspberry Pi Zero 2 Wで動かした

k3sはk8sの軽量版。サーバとエージェントに分かれてエッジの用途にもフォーカスされているらしい。 k3sの説明はこちら Rancher labs社のPDF https://rancher.co.jp/pdfs/K3s-eBook4Styles0507.pdf

使ったOSはRaspberry Pi OS (32bit) Debian Bullseye。 インストールは下記を参考に行った。 future-architect.github.io 但し、Raspberry Pi OS (32bit) Debian Bullseyeはcgroupがデフォルトで有効になっておらず。 agentの起動時に下記のようにログにエラーが出るので/boot/cmdline.txtにcgroup_memory=1 cgroup_enable=memoryを追加して再起動

$ journalctl -u k3s-agent
 6月 26 01:47:27 raspberrypi k3s[977]: time="2022-06-26T01:47:27+01:00" level=info msg="Starting k3s agent v1.23.6+k...
 6月 26 01:47:27 raspberrypi k3s[977]: time="2022-06-26T01:47:27+01:00" level=fatal msg="failed to find memory cgroup...
 6月 26 01:47:27 raspberrypi systemd[1]: k3s-agent.service: Main process exited, code=exited, status=1/FAILURE
 6月 26 01:47:27 raspberrypi systemd[1]: k3s-agent.service: Failed with result 'exit-code'.
cat  /boot/cmdline.txt
console=serial0 ... plymouth.ignore-serial-consoles cgroup_memory=1 cgroup_enable=memory

サーバ側から確認する

(base) ~/k3s-raspi$ k3s kubectl get nodes
NAME          STATUS   ROLES    AGE     VERSION
raspberrypi   Ready    <none>   5m37s   v1.23.6+k3s1

大丈夫そう。 試しにkellygriffin/hello:v1を動かす。

(base):~/k3s-raspi$ kubectl get pods
NAME                      READY   STATUS             RESTARTS      AGE
mysite-57b5b46f97-ftvcq   0/1     CrashLoopBackOff   3 (15s ago)   95s
(base):~/k3s-raspi$ kubectl logs mysite-57b5b46f97-ftvcq
standard_init_linux.go:228: exec user process caused: exec format error
(base):~/k3s-raspi$ kubectl get pods --

だめっぽい。とりあえず、deploymentは消しとく。

(base) :~/k3s-raspi$ kubectl delete deployment mysite

エラーメッセージから察するにkellygriffin/helloはarmv7lでは動かないっぽい(?) ので動きそうな名前をしているarm32v7/hello-world:latestをJobで実行することでお茶を濁す

apiVersion: batch/v1
kind: Job
metadata:
  name: workload
spec:
  template:
    metadata:
      labels:
        app: workload
    spec:
      containers:
        - name: workload
          image: arm32v7/hello-world:latest
      restartPolicy: Never
  backoffLimit: 4

(base) ~/k3s-raspi$ kubectl apply -f ./testdeploy.yaml 
job.batch/workload created
(base) ~/k3s-raspi$ kubectl get pods
NAME             READY   STATUS              RESTARTS   AGE
workload-lt7hz   0/1     ContainerCreating   0          3s
(base) ~/k3s-raspi$ kubectl logs workload-lt7hz -f

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (arm32v7)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

(base)~/k3s-raspi$ kubectl get pods
NAME             READY   STATUS      RESTARTS   AGE
workload-lt7hz   0/1     Completed   0          30s

めでたしめでたし