猫の手なら貸せる

いろいろ共有できたらいいなとおもってます

microk8s導入時ラズパイで発生するエラーについて

f:id:nkhnd:20210324012608p:plain ワンライナーで導入できるというはずなのですが、さすがラズベリーパイは手間取らせてくれました。そして解決できていない。

環境

  • RaspberryPi 4B(Ubuntu 20.04 LTS)

原因がわかった問題

ノードがいつまでもReadyにならない

インストールには成功し、nodesを参照するがNotReady

root@rasp2:~# kubectl get nodes
NAME    STATUS     ROLES    AGE   VERSION
rasp2   NotReady   <none>   21m   v1.20.2-34+c6851e88267786

WARNING: The memory cgroup is not enabled.

inspectの実行結果。cgroupsが設定されていないためノードがReadyにならない

root@rasp2:~# microk8s inspect
Inspecting Certificates
Inspecting services
  Service snap.microk8s.daemon-cluster-agent is running
  Service snap.microk8s.daemon-containerd is running
  Service snap.microk8s.daemon-apiserver is running
  Service snap.microk8s.daemon-apiserver-kicker is running
  Service snap.microk8s.daemon-control-plane-kicker is running
  Service snap.microk8s.daemon-proxy is running
  Service snap.microk8s.daemon-kubelet is running
  Service snap.microk8s.daemon-scheduler is running
  Service snap.microk8s.daemon-controller-manager is running
  Copy service arguments to the final report tarball
Inspecting AppArmor configuration
Gathering system information
  Copy processes list to the final report tarball
  Copy snap list to the final report tarball
  Copy VM name (or none) to the final report tarball
  Copy disk usage information to the final report tarball
  Copy memory usage information to the final report tarball
  Copy server uptime to the final report tarball
  Copy current linux distribution to the final report tarball
  Copy openSSL information to the final report tarball
  Copy network configuration to the final report tarball
Inspecting kubernetes cluster
  Inspect kubernetes cluster
Inspecting juju
  Inspect Juju
Inspecting kubeflow
  Inspect Kubeflow

WARNING:  The memory cgroup is not enabled. 
The cluster may not be functioning properly. Please ensure cgroups are enabled 
See for example: https://microk8s.io/docs/install-alternatives#heading--arm 
Building the report tarball
  Report tarball is at /var/snap/microk8s/2049/inspection-report-20210322_010730.tar.gz

/boot/firmware/cmdline.txtに以下を追加

cgroup_enable=memory cgroup_memory=1

RaspberryPiではデフォルトでcgroupsが有効化されていないようです。

原因が不明な問題

microk8sのインストールに失敗する

Setup snap "core" (10862) security profiles

インストール時に以下のようなエラーメッセージが表示されてしまった。

root@rasp3:/proc# snap install microk8s --classic 
error: cannot perform the following tasks:
- Setup snap "core" (10862) security profiles (cannot setup profiles for snap "core": cannot create host snap-confine apparmor configuration: cannot reload snap-confine apparmor profile: cannot load apparmor profiles: exit status 1
apparmor_parser output:
Cache read/write disabled: interface file missing. (Kernel needs AppArmor 2.4 compatibility patch.)
Warning: unable to find a suitable fs in /proc/mounts, is it mounted?
Use --subdomainfs to override.
)

apparmorを再起動したら解消しました。

root@rasp3:/proc# /etc/init.d/apparmor restart
Restarting apparmor (via systemctl): apparmor.service.

Automatically connect eligible plugs and slots of snap "microk8s"

上の対応でエラーの内容が変化した。

root@rasp3:/proc# snap install microk8s --classic 
Setup snap "microk8s" (2049) security profiles                                                                                                                                                             |
error: cannot perform the following tasks:
- Automatically connect eligible plugs and slots of snap "microk8s" (internal error: auto-connect of &{"microk8s:kubernetes-support" "snapd:kubernetes-support"} failed: snap "snapd" has no slot named "kubernetes-support")

snapdを再起動すると解消した。

root@rasp3:~# systemctl restart snapd
root@rasp3:~# snap install microk8s --classic 
microk8s (1.20/stable) v1.20.2 from Canonical✓ installed

ノードがいつまで経っても開始されない

他のノードは以下のように自分自身をkubectl get nodesできるが...

root@rasp2:~# kubectl get nodes
NAME    STATUS     ROLES    AGE   VERSION
rasp2   NotReady   <none>   21m   v1.20.2-34+c6851e88267786

問題の起きているノードでは自分自身も取得できない。

root@rasp3:~# kubectl get nodes
No resources found

inspectを行った結果Service snap.microk8s.daemon-kubelet is not runningが出力されていました。

root@rasp3:~# microk8s inspect 
Inspecting Certificates
Inspecting services
  Service snap.microk8s.daemon-cluster-agent is running
  Service snap.microk8s.daemon-containerd is running
  Service snap.microk8s.daemon-apiserver is running
  Service snap.microk8s.daemon-apiserver-kicker is running
  Service snap.microk8s.daemon-control-plane-kicker is running
  Service snap.microk8s.daemon-proxy is running
 FAIL:  Service snap.microk8s.daemon-kubelet is not running

kubeletの再起動を実施 -> 変化なし

microk8s.resetを実施 -> 変化なし

root@rasp3:~# microk8s.reset
Disabling all addons.
(省略)
deployment.apps/calico-kube-controllers created
serviceaccount/calico-kube-controllers created
root@rasp3:~# 
root@rasp3:~# microk8s inspect 
Inspecting Certificates
Inspecting services
  Service snap.microk8s.daemon-cluster-agent is running
  Service snap.microk8s.daemon-containerd is running
  Service snap.microk8s.daemon-apiserver is running
  Service snap.microk8s.daemon-apiserver-kicker is running
  Service snap.microk8s.daemon-control-plane-kicker is running
  Service snap.microk8s.daemon-proxy is running
 FAIL:  Service snap.microk8s.daemon-kubelet is not running
(省略)

一か八かノードの再起動を実施 -> 直った(???)
(裏でcgroupsの問題対処済み)

root@rasp3:~# sudo reboot
Connection to 192.168.3.13 closed by remote host.
Connection to 192.168.3.13 closed.

root@rasp3:~# microk8s inspect
Inspecting Certificates
Inspecting services
  Service snap.microk8s.daemon-cluster-agent is running
  Service snap.microk8s.daemon-containerd is running
  Service snap.microk8s.daemon-apiserver is running
  Service snap.microk8s.daemon-apiserver-kicker is running
  Service snap.microk8s.daemon-control-plane-kicker is running
  Service snap.microk8s.daemon-proxy is running
  Service snap.microk8s.daemon-kubelet is running
  Service snap.microk8s.daemon-scheduler is running
  Service snap.microk8s.daemon-controller-manager is running
  Copy service arguments to the final report tarball
Inspecting AppArmor configuration
Gathering system information
  Copy processes list to the final report tarball
  Copy snap list to the final report tarball
  Copy VM name (or none) to the final report tarball
  Copy disk usage information to the final report tarball
  Copy memory usage information to the final report tarball
  Copy server uptime to the final report tarball
  Copy current linux distribution to the final report tarball
  Copy openSSL information to the final report tarball
  Copy network configuration to the final report tarball
Inspecting kubernetes cluster
  Inspect kubernetes cluster
Inspecting juju
  Inspect Juju
Inspecting kubeflow
  Inspect Kubeflow

Building the report tarball
  Report tarball is at /var/snap/microk8s/2049/inspection-report-20210322_125516.tar.gz

root@rasp3:~# kubectl get nodes
NAME    STATUS     ROLES    AGE   VERSION
rasp3   NotReady   <none>   13s   v1.20.2-34+c6851e88267786

(数分経過)

root@rasp3:~# kubectl get nodes
NAME    STATUS   ROLES    AGE     VERSION
rasp3   Ready    <none>   2m41s   v1.20.2-34+c6851e88267786

なぜ解決したか不明。バックグラウンドでGlusterFSのレプリケーションを行なっていたのでプロセスが重たかった?

終わりに

microk8s、セットアップ簡単なようで難しかったです。
リターンは大きいので徒労というわけでもないけど、なんとも言えない感じです。