3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

はじめに

最近私用のMacをMBP14in(M1 Max)に買い替えたので、その上でk3sのmasterノードを動かしてみます。

準備

k3sはmacOSをサポートしていないので、Ubuntuインスタンスをmultipassを使って起動します。

# Homebrewでmultipassをインストール
% brew install --cask multipass 
# k3s-masterという名前でUbuntuインスタンスを起動
% multipass launch -n k3s-master 
Launched: k3s-master

k3sを動かしてみる

% multipass shell k3s-master
Welcome to Ubuntu 20.04.3 LTS (GNU/Linux 5.4.0-91-generic aarch64)
# (以下略)
# 公式の手順にしたがってk3sをインストール
ubuntu@k3s-master:~$ curl -sfL https://get.k3s.io | sh -
[INFO]  Finding release for channel stable
[INFO]  Using v1.21.7+k3s1 as release
[INFO]  Downloading hash https://github.com/k3s-io/k3s/releases/download/v1.21.7+k3s1/sha256sum-arm64.txt
[INFO]  Downloading binary https://github.com/k3s-io/k3s/releases/download/v1.21.7+k3s1/k3s-arm64
[INFO]  Verifying binary download
[INFO]  Installing k3s to /usr/local/bin/k3s
[INFO]  Skipping installation of SELinux RPM
[INFO]  Creating /usr/local/bin/kubectl symlink to k3s
[INFO]  Creating /usr/local/bin/crictl symlink to k3s
[INFO]  Creating /usr/local/bin/ctr symlink to k3s
[INFO]  Creating killall script /usr/local/bin/k3s-killall.sh
[INFO]  Creating uninstall script /usr/local/bin/k3s-uninstall.sh
[INFO]  env: Creating environment file /etc/systemd/system/k3s.service.env
[INFO]  systemd: Creating service file /etc/systemd/system/k3s.service
[INFO]  systemd: Enabling k3s unit
Created symlink /etc/systemd/system/multi-user.target.wants/k3s.service → /etc/systemd/system/k3s.service.
[INFO]  systemd: Starting k3s

# ノードが正常に起動していることを確認
ubuntu@k3s-master:~$ sudo kubectl get nodes
NAME         STATUS   ROLES                  AGE   VERSION
k3s-master   Ready    control-plane,master   44s   v1.21.7+k3s1

# busybox Podを試しに動かしてみる
ubuntu@k3s-master:~$ sudo kubectl run test --restart=Never --rm -it --image=busybox -- /bin/sh -c "echo Hello"
Hello
pod "test" deleted

お片付け

アンインストール用のスクリプトも用意されています。

ubuntu@k3s-master:~$ /usr/local/bin/k3s-uninstall.sh
+ id -u
+ [ 1000 -eq 0 ]
+ exec sudo /usr/local/bin/k3s-uninstall.sh
+ id -u
+ [ 0 -eq 0 ]
+ /usr/local/bin/k3s-killall.sh
+ [ -s /etc/systemd/system/k3s.service ]
+ basename /etc/systemd/system/k3s.service
+ systemctl stop k3s.service
+ [ -x /etc/init.d/k3s* ]
+ killtree 2608 2610 2613 3626 3756
+ kill -9 2608 2730 2830 2610 2704 3027 2613 2724 2874 3626 3644 4041 3756 3777 3915 3947
+ do_unmount_and_remove /run/k3s
+ set +x
sh -c 'umount "$0" && rm -rf "$0"' /run/k3s/containerd/io.containerd.runtime.v2.task/k8s.io/f0962e93fb469f8a20d8faf9f1c074522ad45f8234b5a198ba2106c53c58fb95/rootfs 
sh -c 'umount "$0" && rm -rf "$0"' /run/k3s/containerd/io.containerd.runtime.v2.task/k8s.io/e4b44c45d6931200e64348e6612b11db121345d1858bef52ecbddcf6bcb63069/rootfs 
sh -c 'umount "$0" && rm -rf "$0"' /run/k3s/containerd/io.containerd.runtime.v2.task/k8s.io/d16429ff067ab25d92487d173563fb207cd8d1ebf08b86335d9dfcd3b1e4aab3/rootfs 
sh -c 'umount "$0" && rm -rf "$0"' /run/k3s/containerd/io.containerd.runtime.v2.task/k8s.io/945b58cdb42c4c9cf9e43ebdde6a9a794f15203b57412ca0516138b9b9e3445a/rootfs 
sh -c 'umount "$0" && rm -rf "$0"' /run/k3s/containerd/io.containerd.runtime.v2.task/k8s.io/81b568c5126e53b1023e2ac248cf6f70d9f33c81291c76e549c3cec671fb91fc/rootfs 
sh -c 'umount "$0" && rm -rf "$0"' /run/k3s/containerd/io.containerd.runtime.v2.task/k8s.io/3862c9809c4470a3a03920430f3b1b7ee9d806aa96bfc88fe2a3423a61d96812/rootfs 
sh -c 'umount "$0" && rm -rf "$0"' /run/k3s/containerd/io.containerd.runtime.v2.task/k8s.io/32f5e6729966cb434bf19e3d5cd9db14b91583983069f23476da049b454c6582/rootfs 
sh -c 'umount "$0" && rm -rf "$0"' /run/k3s/containerd/io.containerd.runtime.v2.task/k8s.io/2fde7f45a4afa9881967d57cc8812d89ef4ef12c98de6f26a20c4af0c4ee733f/rootfs 
sh -c 'umount "$0" && rm -rf "$0"' /run/k3s/containerd/io.containerd.runtime.v2.task/k8s.io/2ee470601b12f3a9ad9ac1d02a3af5bcab112520c59b7fc8ca8da2c52e5d43d3/rootfs 
sh -c 'umount "$0" && rm -rf "$0"' /run/k3s/containerd/io.containerd.runtime.v2.task/k8s.io/11fa2a4a8abf0a76a412d10246c38f618b79b32a10bf7d1a7c8f3b82cac38e41/rootfs 
sh -c 'umount "$0" && rm -rf "$0"' /run/k3s/containerd/io.containerd.runtime.v2.task/k8s.io/07a822304f9b521ade0cdf24c86ad98260984b8bea694860800dc73643908725/rootfs 
sh -c 'umount "$0" && rm -rf "$0"' /run/k3s/containerd/io.containerd.grpc.v1.cri/sandboxes/e4b44c45d6931200e64348e6612b11db121345d1858bef52ecbddcf6bcb63069/shm 
sh -c 'umount "$0" && rm -rf "$0"' /run/k3s/containerd/io.containerd.grpc.v1.cri/sandboxes/d16429ff067ab25d92487d173563fb207cd8d1ebf08b86335d9dfcd3b1e4aab3/shm 
sh -c 'umount "$0" && rm -rf "$0"' /run/k3s/containerd/io.containerd.grpc.v1.cri/sandboxes/81b568c5126e53b1023e2ac248cf6f70d9f33c81291c76e549c3cec671fb91fc/shm 
sh -c 'umount "$0" && rm -rf "$0"' /run/k3s/containerd/io.containerd.grpc.v1.cri/sandboxes/3862c9809c4470a3a03920430f3b1b7ee9d806aa96bfc88fe2a3423a61d96812/shm 
sh -c 'umount "$0" && rm -rf "$0"' /run/k3s/containerd/io.containerd.grpc.v1.cri/sandboxes/2ee470601b12f3a9ad9ac1d02a3af5bcab112520c59b7fc8ca8da2c52e5d43d3/shm 
+ do_unmount_and_remove /var/lib/rancher/k3s
+ set +x
+ do_unmount_and_remove /var/lib/kubelet/pods
+ set +x
sh -c 'umount "$0" && rm -rf "$0"' /var/lib/kubelet/pods/eb45296f-ce3d-4975-a0a8-034fabdcdb74/volumes/kubernetes.io~projected/kube-api-access-q7wcw 
sh -c 'umount "$0" && rm -rf "$0"' /var/lib/kubelet/pods/60ded7da-90ff-4686-b43e-04d93d40ff8c/volumes/kubernetes.io~projected/kube-api-access-68s6d 
sh -c 'umount "$0" && rm -rf "$0"' /var/lib/kubelet/pods/27eb7e9f-69e3-4500-bc18-15b0a7455d79/volumes/kubernetes.io~projected/kube-api-access-4nb2v 
sh -c 'umount "$0" && rm -rf "$0"' /var/lib/kubelet/pods/2325c86e-a47e-4873-9b5b-73310f6a7714/volumes/kubernetes.io~projected/kube-api-access-zggsc 
sh -c 'umount "$0" && rm -rf "$0"' /var/lib/kubelet/pods/163e2b02-e392-449c-9a3e-6584c4f16a3d/volumes/kubernetes.io~projected/kube-api-access-l44cx 
+ do_unmount_and_remove /var/lib/kubelet/plugins
+ set +x
+ do_unmount_and_remove /run/netns/cni-
+ set +x
sh -c 'umount "$0" && rm -rf "$0"' /run/netns/cni-c9dc24e6-1753-f22d-68ee-26ce89e9822e 
sh -c 'umount "$0" && rm -rf "$0"' /run/netns/cni-c8f3571e-a846-5127-5751-7b1944a84668 
sh -c 'umount "$0" && rm -rf "$0"' /run/netns/cni-a1d2d221-294c-5a9c-b3f5-903ab6e65b2e 
sh -c 'umount "$0" && rm -rf "$0"' /run/netns/cni-7d54cf19-0f7c-d9ae-6bd3-b2f429ca57e3 
sh -c 'umount "$0" && rm -rf "$0"' /run/netns/cni-0a25f41e-40fe-5c4b-1139-fabdda4276a5 
+ xargs -r -t -n 1 ip netns delete
+ grep cni-
+ ip netns show
+ read ignore iface ignore
+ grep master cni0
+ ip link show
+ ip link delete cni0
+ ip link delete flannel.1
+ ip link delete flannel-v6.1
Cannot find device "flannel-v6.1"
+ rm -rf /var/lib/cni/
+ iptables-restore
+ grep -v CNI-
+ grep -v KUBE-
+ iptables-save
+ command -v systemctl
/usr/bin/systemctl
+ systemctl disable k3s
Removed /etc/systemd/system/multi-user.target.wants/k3s.service.
+ systemctl reset-failed k3s
+ systemctl daemon-reload
+ command -v rc-update
+ rm -f /etc/systemd/system/k3s.service
+ rm -f /etc/systemd/system/k3s.service.env
+ trap remove_uninstall EXIT
+ [ -L /usr/local/bin/kubectl ]
+ rm -f /usr/local/bin/kubectl
+ [ -L /usr/local/bin/crictl ]
+ rm -f /usr/local/bin/crictl
+ [ -L /usr/local/bin/ctr ]
+ rm -f /usr/local/bin/ctr
+ rm -rf /etc/rancher/k3s
+ rm -rf /run/k3s
+ rm -rf /run/flannel
+ rm -rf /var/lib/rancher/k3s
+ rm -rf /var/lib/kubelet
+ rm -f /usr/local/bin/k3s
+ rm -f /usr/local/bin/k3s-killall.sh
+ type yum
+ type zypper
+ remove_uninstall
+ rm -f /usr/local/bin/k3s-uninstall.sh
ubuntu@k3s-master:~$ exit

ついでにUbuntuインスタンスもお掃除

% multipass delete k3s-master
% multipass purge

まとめ

Intel Macのときにも試したことがありましたが、M1 Macでも特に差異なく実行することができました。
実際にMacBookを母艦としておうちk8sクラスタを動かすことはあまりないかもしれませんが、PoC的にいろいろ試すことはできそうです。

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?