アジョブジ星通信

進捗が出た頃に更新されるブログ。

k3s の中身とメモリ使用量の調査

コンテナに対するあらゆる需要に応えるソリューションこと Kubernetes が流行りですね(雑なはじめかた)。僕も何度かこのビッグウェーブに乗ろうとしましたが、新しい概念の多さと、ズボラ運用には厳しいメモリ使用量で断念してきました。動かしたい環境というのが、メモリ 1GB の VPS だったり、メモリ 1GB の ARM シングルボードコンピュータなわけで……。

そんなところに颯爽と登場したのが k3s です。公式の謳い文句から解説しているページは「k3s kubernetes」で検索すれば無限に出てくると思うので、そちらにおまかせして、じゃあ実際どうやってあの馬鹿でかい Kubernetes をコンパクトにパッケージングしたのかについて見ていきたいと思います。

シングルバイナリ?ホンマか?

シングルバイナリと聞くと、ぱっと思いつくのは BusyBox のように、すべてのプログラムをまとめてコンパイルして、起動時のコマンド名で実行するプログラムを切り替えるスタイルですが、 k3s ではどうでしょうか? 答えは、半分そうで、半分違います。

k3s には、いくつかの実行可能ファイルを tar.gz で圧縮したものが埋め込まれており、初回起動時にディレクトリ(デフォルトでは /var/lib/rancher/k3s/data または ~/.rancher/k3s/data)に展開されます。だから、配布されているバイナリは 40MB 以下なのに、システム要件では 200MB 必要とあるわけですね!

ビルドスクリプトを読んで、どんなバイナリが埋め込まれているのか調べてみましょう。 Go で書かれたプログラムのビルドは scripts/build で行われています。ここでは次の実行可能ファイルがビルドされています。

containerd
containerd という名前だけれど、実態は containerd、k3s-agent、k3s-server、kubectl、crictl を BusyBox スタイルでまとめたもの。 k3s-agent はいろいろ準備して、 conatinerd (つまり自分自身)を起動する。 k3s-server は、おそらくこれが kube-apiserver に相当するもの(Rancher がうまくまとめてるっぽい)。
cni
CNI のプラグインから必要なものだけ集めて、 BusyBox スタイルでまとめたもの。
runc
おそらく手を加えていない runc
containerd-shim
おそらく手を加えていない containerd-shim (containerd と runc の仲介)

また、 Linux カーネルさえあれば動くを掲げており、必要なコマンド類もすべて埋め込まれています。これらのコマンドをビルドするスクリプトは、こちらにあります。Buildrootソースコードから必要なものだけをビルドしたもののようです。

最終的に配布されるパッケージとなる k3s コマンドは、起動時にこのアーカイブを展開し、コマンドライン引数に従って server なら k3s-server、 agent なら k3s-agent、 kubectl なら kubectl、 crictl なら crictl(いずれも containerd へのシンボリックリンク)を exec します。

実際の展開結果を示します。合計 102MB ほどになっています。

$ ls -al /var/lib/rancher/k3s/data/4df430e1473d0225734948e562863c82f20d658ed9c420c77e168aec42eccdb5/bin
total 103976
drwxr-xr-x 2 root root    12288 Mar  3 17:15 .
drwxr-xr-x 3 root root     4096 Mar  3 17:15 ..
lrwxrwxrwx 1 root root        7 Mar  3 17:15 addgroup -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 adduser -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 ar -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 arch -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 arp -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 arping -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 ash -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 awk -> busybox
lrwxrwxrwx 1 root root        9 Mar  3 17:15 b2sum -> coreutils
lrwxrwxrwx 1 root root        9 Mar  3 17:15 base32 -> coreutils
lrwxrwxrwx 1 root root        9 Mar  3 17:15 base64 -> coreutils
lrwxrwxrwx 1 root root        9 Mar  3 17:15 basename -> coreutils
lrwxrwxrwx 1 root root        7 Mar  3 17:15 blkid -> busybox
lrwxrwxrwx 1 root root        3 Mar  3 17:15 bridge -> cni
lrwxrwxrwx 1 root root        7 Mar  3 17:15 bunzip2 -> busybox
-rwxr-xr-x 1 root root   817416 Jan  9 16:48 busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 bzcat -> busybox
lrwxrwxrwx 1 root root        9 Mar  3 17:15 cat -> coreutils
lrwxrwxrwx 1 root root        7 Mar  3 17:15 chattr -> busybox
lrwxrwxrwx 1 root root        9 Mar  3 17:15 chcon -> coreutils
lrwxrwxrwx 1 root root        9 Mar  3 17:15 chgrp -> coreutils
lrwxrwxrwx 1 root root        9 Mar  3 17:15 chmod -> coreutils
lrwxrwxrwx 1 root root        9 Mar  3 17:15 chown -> coreutils
lrwxrwxrwx 1 root root        9 Mar  3 17:15 chroot -> coreutils
lrwxrwxrwx 1 root root        7 Mar  3 17:15 chrt -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 chvt -> busybox
lrwxrwxrwx 1 root root        9 Mar  3 17:15 cksum -> coreutils
lrwxrwxrwx 1 root root        7 Mar  3 17:15 clear -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 cmp -> busybox
-rwxr-xr-x 1 root root  3236320 Feb 26 05:09 cni
lrwxrwxrwx 1 root root        9 Mar  3 17:15 comm -> coreutils
-rwxr-xr-x 1 root root   195376 Jan  9 16:48 conntrack
-rwxr-xr-x 1 root root 85776224 Feb 26 05:09 containerd
-rwxr-xr-x 1 root root  5763776 Feb 26 05:09 containerd-shim
-rwxr-xr-x 1 root root  1118792 Jan  9 16:48 coreutils
lrwxrwxrwx 1 root root        9 Mar  3 17:15 cp -> coreutils
lrwxrwxrwx 1 root root        7 Mar  3 17:15 cpio -> busybox
lrwxrwxrwx 1 root root       10 Mar  3 17:15 crictl -> containerd
lrwxrwxrwx 1 root root        7 Mar  3 17:15 crond -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 crontab -> busybox
lrwxrwxrwx 1 root root        9 Mar  3 17:15 csplit -> coreutils
lrwxrwxrwx 1 root root        9 Mar  3 17:15 cut -> coreutils
lrwxrwxrwx 1 root root        9 Mar  3 17:15 date -> coreutils
lrwxrwxrwx 1 root root        7 Mar  3 17:15 dc -> busybox
lrwxrwxrwx 1 root root        9 Mar  3 17:15 dd -> coreutils
lrwxrwxrwx 1 root root        7 Mar  3 17:15 deallocvt -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 delgroup -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 deluser -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 devmem -> busybox
lrwxrwxrwx 1 root root        9 Mar  3 17:15 df -> coreutils
lrwxrwxrwx 1 root root        7 Mar  3 17:15 diff -> busybox
lrwxrwxrwx 1 root root        9 Mar  3 17:15 dir -> coreutils
lrwxrwxrwx 1 root root        9 Mar  3 17:15 dircolors -> coreutils
lrwxrwxrwx 1 root root        9 Mar  3 17:15 dirname -> coreutils
lrwxrwxrwx 1 root root        7 Mar  3 17:15 dmesg -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 dnsd -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 dnsdomainname -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 dos2unix -> busybox
lrwxrwxrwx 1 root root        9 Mar  3 17:15 du -> coreutils
lrwxrwxrwx 1 root root        7 Mar  3 17:15 dumpkmap -> busybox
-rwxr-xr-x 1 root root   140000 Jan  9 16:48 ebtables
lrwxrwxrwx 1 root root        9 Mar  3 17:15 echo -> coreutils
lrwxrwxrwx 1 root root        7 Mar  3 17:15 egrep -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 eject -> busybox
lrwxrwxrwx 1 root root        9 Mar  3 17:15 env -> coreutils
lrwxrwxrwx 1 root root        7 Mar  3 17:15 ether-wake -> busybox
lrwxrwxrwx 1 root root        9 Mar  3 17:15 expand -> coreutils
lrwxrwxrwx 1 root root        9 Mar  3 17:15 expr -> coreutils
lrwxrwxrwx 1 root root        9 Mar  3 17:15 factor -> coreutils
lrwxrwxrwx 1 root root        7 Mar  3 17:15 fallocate -> busybox
lrwxrwxrwx 1 root root        9 Mar  3 17:15 false -> coreutils
lrwxrwxrwx 1 root root        7 Mar  3 17:15 fbset -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 fdflush -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 fdformat -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 fdisk -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 fgrep -> busybox
-rwxr-xr-x 1 root root   285936 Jan  9 16:48 find
lrwxrwxrwx 1 root root        3 Mar  3 17:15 flannel -> cni
lrwxrwxrwx 1 root root        7 Mar  3 17:15 flock -> busybox
lrwxrwxrwx 1 root root        9 Mar  3 17:15 fmt -> coreutils
lrwxrwxrwx 1 root root        9 Mar  3 17:15 fold -> coreutils
lrwxrwxrwx 1 root root        7 Mar  3 17:15 free -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 freeramdisk -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 fsck -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 fsfreeze -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 fstrim -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 fuser -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 getopt -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 getty -> busybox
lrwxrwxrwx 1 root root        9 Mar  3 17:15 ginstall -> coreutils
lrwxrwxrwx 1 root root        7 Mar  3 17:15 grep -> busybox
lrwxrwxrwx 1 root root        9 Mar  3 17:15 groups -> coreutils
lrwxrwxrwx 1 root root        7 Mar  3 17:15 gunzip -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 gzip -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 halt -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 hdparm -> busybox
lrwxrwxrwx 1 root root        9 Mar  3 17:15 head -> coreutils
lrwxrwxrwx 1 root root        7 Mar  3 17:15 hexdump -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 hexedit -> busybox
lrwxrwxrwx 1 root root        9 Mar  3 17:15 hostid -> coreutils
lrwxrwxrwx 1 root root        3 Mar  3 17:15 host-local -> cni
lrwxrwxrwx 1 root root        7 Mar  3 17:15 hostname -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 hwclock -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 i2cdetect -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 i2cdump -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 i2cget -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 i2cset -> busybox
lrwxrwxrwx 1 root root        9 Mar  3 17:15 id -> coreutils
lrwxrwxrwx 1 root root        7 Mar  3 17:15 ifconfig -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 ifdown -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 ifup -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 inetd -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 init -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 insmod -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 install -> busybox
-rwxr-xr-x 1 root root   509088 Jan  9 16:48 ip
lrwxrwxrwx 1 root root        7 Mar  3 17:15 ipaddr -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 ipcrm -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 ipcs -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 iplink -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 ipneigh -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 iproute -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 iprule -> busybox
-rwxr-xr-x 1 root root   186040 Jan  9 16:48 ipset
lrwxrwxrwx 1 root root       13 Mar  3 17:15 iptables -> xtables-multi
lrwxrwxrwx 1 root root       13 Mar  3 17:15 iptables-restore -> xtables-multi
lrwxrwxrwx 1 root root       13 Mar  3 17:15 iptables-save -> xtables-multi
lrwxrwxrwx 1 root root        7 Mar  3 17:15 iptunnel -> busybox
lrwxrwxrwx 1 root root        9 Mar  3 17:15 join -> coreutils
lrwxrwxrwx 1 root root       10 Mar  3 17:15 k3s-agent -> containerd
lrwxrwxrwx 1 root root       10 Mar  3 17:15 k3s-server -> containerd
lrwxrwxrwx 1 root root        9 Mar  3 17:15 kill -> coreutils
lrwxrwxrwx 1 root root        7 Mar  3 17:15 killall -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 killall5 -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 klogd -> busybox
lrwxrwxrwx 1 root root       10 Mar  3 17:15 kubectl -> containerd
lrwxrwxrwx 1 root root        7 Mar  3 17:15 last -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 less -> busybox
lrwxrwxrwx 1 root root        9 Mar  3 17:15 link -> coreutils
lrwxrwxrwx 1 root root        7 Mar  3 17:15 linux32 -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 linux64 -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 linuxrc -> busybox
lrwxrwxrwx 1 root root        9 Mar  3 17:15 ln -> coreutils
lrwxrwxrwx 1 root root        7 Mar  3 17:15 loadfont -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 loadkmap -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 logger -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 login -> busybox
lrwxrwxrwx 1 root root        9 Mar  3 17:15 logname -> coreutils
lrwxrwxrwx 1 root root        3 Mar  3 17:15 loopback -> cni
lrwxrwxrwx 1 root root        7 Mar  3 17:15 losetup -> busybox
lrwxrwxrwx 1 root root        9 Mar  3 17:15 ls -> coreutils
lrwxrwxrwx 1 root root        7 Mar  3 17:15 lsattr -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 lsmod -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 lsof -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 lspci -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 lsscsi -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 lsusb -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 lzcat -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 lzma -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 lzopcat -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 makedevs -> busybox
lrwxrwxrwx 1 root root        9 Mar  3 17:15 md5sum -> coreutils
lrwxrwxrwx 1 root root        7 Mar  3 17:15 mdev -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 mesg -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 microcom -> busybox
lrwxrwxrwx 1 root root        9 Mar  3 17:15 mkdir -> coreutils
lrwxrwxrwx 1 root root        7 Mar  3 17:15 mkdosfs -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 mke2fs -> busybox
lrwxrwxrwx 1 root root        9 Mar  3 17:15 mkfifo -> coreutils
lrwxrwxrwx 1 root root        9 Mar  3 17:15 mknod -> coreutils
lrwxrwxrwx 1 root root        7 Mar  3 17:15 mkpasswd -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 mkswap -> busybox
lrwxrwxrwx 1 root root        9 Mar  3 17:15 mktemp -> coreutils
lrwxrwxrwx 1 root root        7 Mar  3 17:15 modprobe -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 more -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 mount -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 mountpoint -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 mt -> busybox
lrwxrwxrwx 1 root root        9 Mar  3 17:15 mv -> coreutils
lrwxrwxrwx 1 root root        7 Mar  3 17:15 nameif -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 netstat -> busybox
lrwxrwxrwx 1 root root        9 Mar  3 17:15 nice -> coreutils
lrwxrwxrwx 1 root root        9 Mar  3 17:15 nl -> coreutils
lrwxrwxrwx 1 root root        9 Mar  3 17:15 nohup -> coreutils
lrwxrwxrwx 1 root root        9 Mar  3 17:15 nproc -> coreutils
lrwxrwxrwx 1 root root        7 Mar  3 17:15 nslookup -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 nuke -> busybox
lrwxrwxrwx 1 root root        9 Mar  3 17:15 numfmt -> coreutils
lrwxrwxrwx 1 root root        9 Mar  3 17:15 od -> coreutils
lrwxrwxrwx 1 root root        7 Mar  3 17:15 openvt -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 partprobe -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 passwd -> busybox
lrwxrwxrwx 1 root root        9 Mar  3 17:15 paste -> coreutils
lrwxrwxrwx 1 root root        7 Mar  3 17:15 patch -> busybox
lrwxrwxrwx 1 root root        9 Mar  3 17:15 pathchk -> coreutils
lrwxrwxrwx 1 root root        7 Mar  3 17:15 pidof -> busybox
-rwxr-xr-x 1 root root   219280 Jan  9 16:48 pigz
lrwxrwxrwx 1 root root        7 Mar  3 17:15 ping -> busybox
lrwxrwxrwx 1 root root        9 Mar  3 17:15 pinky -> coreutils
lrwxrwxrwx 1 root root        7 Mar  3 17:15 pipe_progress -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 pivot_root -> busybox
lrwxrwxrwx 1 root root        3 Mar  3 17:15 portmap -> cni
lrwxrwxrwx 1 root root        7 Mar  3 17:15 poweroff -> busybox
lrwxrwxrwx 1 root root        9 Mar  3 17:15 pr -> coreutils
lrwxrwxrwx 1 root root        9 Mar  3 17:15 printenv -> coreutils
lrwxrwxrwx 1 root root        9 Mar  3 17:15 printf -> coreutils
lrwxrwxrwx 1 root root        7 Mar  3 17:15 ps -> busybox
lrwxrwxrwx 1 root root        9 Mar  3 17:15 ptx -> coreutils
lrwxrwxrwx 1 root root        9 Mar  3 17:15 pwd -> coreutils
lrwxrwxrwx 1 root root        7 Mar  3 17:15 rdate -> busybox
lrwxrwxrwx 1 root root        9 Mar  3 17:15 readlink -> coreutils
lrwxrwxrwx 1 root root        7 Mar  3 17:15 readprofile -> busybox
lrwxrwxrwx 1 root root        9 Mar  3 17:15 realpath -> coreutils
lrwxrwxrwx 1 root root        7 Mar  3 17:15 reboot -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 renice -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 reset -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 resize -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 resume -> busybox
lrwxrwxrwx 1 root root        9 Mar  3 17:15 rm -> coreutils
lrwxrwxrwx 1 root root        9 Mar  3 17:15 rmdir -> coreutils
lrwxrwxrwx 1 root root        7 Mar  3 17:15 rmmod -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 route -> busybox
-rwxr-xr-x 1 root root  7308352 Feb 26 05:09 runc
lrwxrwxrwx 1 root root        9 Mar  3 17:15 runcon -> coreutils
lrwxrwxrwx 1 root root        7 Mar  3 17:15 run-init -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 runlevel -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 run-parts -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 sed -> busybox
lrwxrwxrwx 1 root root        9 Mar  3 17:15 seq -> coreutils
lrwxrwxrwx 1 root root        7 Mar  3 17:15 setarch -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 setconsole -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 setfattr -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 setkeycodes -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 setlogcons -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 setpriv -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 setserial -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 setsid -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 sh -> busybox
lrwxrwxrwx 1 root root        9 Mar  3 17:15 sha1sum -> coreutils
lrwxrwxrwx 1 root root        9 Mar  3 17:15 sha224sum -> coreutils
lrwxrwxrwx 1 root root        9 Mar  3 17:15 sha256sum -> coreutils
lrwxrwxrwx 1 root root        9 Mar  3 17:15 sha384sum -> coreutils
lrwxrwxrwx 1 root root        7 Mar  3 17:15 sha3sum -> busybox
lrwxrwxrwx 1 root root        9 Mar  3 17:15 sha512sum -> coreutils
lrwxrwxrwx 1 root root        9 Mar  3 17:15 shred -> coreutils
lrwxrwxrwx 1 root root        9 Mar  3 17:15 shuf -> coreutils
lrwxrwxrwx 1 root root        9 Mar  3 17:15 sleep -> coreutils
-rwxr-xr-x 1 root root   310280 Jan  9 16:48 socat
lrwxrwxrwx 1 root root        9 Mar  3 17:15 sort -> coreutils
lrwxrwxrwx 1 root root        9 Mar  3 17:15 split -> coreutils
lrwxrwxrwx 1 root root        7 Mar  3 17:15 start-stop-daemon -> busybox
lrwxrwxrwx 1 root root        9 Mar  3 17:15 stat -> coreutils
lrwxrwxrwx 1 root root        7 Mar  3 17:15 strings -> busybox
lrwxrwxrwx 1 root root        9 Mar  3 17:15 stty -> coreutils
lrwxrwxrwx 1 root root        7 Mar  3 17:15 su -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 sulogin -> busybox
lrwxrwxrwx 1 root root        9 Mar  3 17:15 sum -> coreutils
lrwxrwxrwx 1 root root        7 Mar  3 17:15 svc -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 svok -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 swapoff -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 swapon -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 switch_root -> busybox
lrwxrwxrwx 1 root root        9 Mar  3 17:15 sync -> coreutils
lrwxrwxrwx 1 root root        7 Mar  3 17:15 sysctl -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 syslogd -> busybox
lrwxrwxrwx 1 root root        9 Mar  3 17:15 tac -> coreutils
lrwxrwxrwx 1 root root        9 Mar  3 17:15 tail -> coreutils
lrwxrwxrwx 1 root root        7 Mar  3 17:15 tar -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 tc -> busybox
lrwxrwxrwx 1 root root        9 Mar  3 17:15 tee -> coreutils
lrwxrwxrwx 1 root root        7 Mar  3 17:15 telnet -> busybox
lrwxrwxrwx 1 root root        9 Mar  3 17:15 test -> coreutils
lrwxrwxrwx 1 root root        7 Mar  3 17:15 tftp -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 time -> busybox
lrwxrwxrwx 1 root root        9 Mar  3 17:15 timeout -> coreutils
lrwxrwxrwx 1 root root        7 Mar  3 17:15 top -> busybox
lrwxrwxrwx 1 root root        9 Mar  3 17:15 touch -> coreutils
lrwxrwxrwx 1 root root        9 Mar  3 17:15 tr -> coreutils
lrwxrwxrwx 1 root root        7 Mar  3 17:15 traceroute -> busybox
lrwxrwxrwx 1 root root        9 Mar  3 17:15 true -> coreutils
lrwxrwxrwx 1 root root        9 Mar  3 17:15 truncate -> coreutils
lrwxrwxrwx 1 root root        9 Mar  3 17:15 tsort -> coreutils
lrwxrwxrwx 1 root root        9 Mar  3 17:15 tty -> coreutils
lrwxrwxrwx 1 root root        7 Mar  3 17:15 ubirename -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 udhcpc -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 uevent -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 umount -> busybox
lrwxrwxrwx 1 root root        9 Mar  3 17:15 uname -> coreutils
lrwxrwxrwx 1 root root        9 Mar  3 17:15 unexpand -> coreutils
lrwxrwxrwx 1 root root        9 Mar  3 17:15 uniq -> coreutils
lrwxrwxrwx 1 root root        7 Mar  3 17:15 unix2dos -> busybox
lrwxrwxrwx 1 root root        9 Mar  3 17:15 unlink -> coreutils
lrwxrwxrwx 1 root root        7 Mar  3 17:15 unlzma -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 unlzop -> busybox
lrwxrwxrwx 1 root root        4 Mar  3 17:15 unpigz -> pigz
lrwxrwxrwx 1 root root        7 Mar  3 17:15 unxz -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 unzip -> busybox
lrwxrwxrwx 1 root root        9 Mar  3 17:15 uptime -> coreutils
lrwxrwxrwx 1 root root        9 Mar  3 17:15 users -> coreutils
lrwxrwxrwx 1 root root        7 Mar  3 17:15 usleep -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 uudecode -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 uuencode -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 vconfig -> busybox
lrwxrwxrwx 1 root root        9 Mar  3 17:15 vdir -> coreutils
lrwxrwxrwx 1 root root        7 Mar  3 17:15 vi -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 vlock -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 w -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 watch -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 watchdog -> busybox
lrwxrwxrwx 1 root root        9 Mar  3 17:15 wc -> coreutils
lrwxrwxrwx 1 root root        7 Mar  3 17:15 wget -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 which -> busybox
lrwxrwxrwx 1 root root        9 Mar  3 17:15 who -> coreutils
lrwxrwxrwx 1 root root        9 Mar  3 17:15 whoami -> coreutils
lrwxrwxrwx 1 root root        7 Mar  3 17:15 xargs -> busybox
-rwxr-xr-x 1 root root   556256 Jan  9 16:48 xtables-multi
lrwxrwxrwx 1 root root        7 Mar  3 17:15 xxd -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 xz -> busybox
lrwxrwxrwx 1 root root        7 Mar  3 17:15 xzcat -> busybox
lrwxrwxrwx 1 root root        9 Mar  3 17:15 yes -> coreutils
lrwxrwxrwx 1 root root        7 Mar  3 17:15 zcat -> busybox

ディスクとメモリの使用量

せっかくですので、比較をやってみましょう。お相手は、簡単に構築できるというコンセプトは同じの MicroK8s です。 MicroK8s は、シングルノーKubernetes を実行するためのバイナリと設定の寄せ集めをシェルスクリプトでラップしたものになっています。 Ubuntu においてインストールの簡単さという点では最強です。

実験環境は、 Hyper-VUbuntu Server 18.04 をインストールして、全パッケージを最新にした状態のスナップショットを使用します。メモリは 2GB 割り当ててあります。 MicroK8s と k3s のバージョンは以下の通りです。

名前 バージョン
MicroK8s 1.13.3 (stable channel)
k3s 0.1.0

MicroK8s

ではまず MicroK8s から試していきます。インストールする前のディスクの使用量は、 df コマンドで調べたところ、 3916MB でした。

インストールは非常に簡単で、次のコマンドを実行するだけで完了です。

sudo snap install microk8s --classic

# 起動を待つ
microk8s.status --wait-ready

インストール直後は、何もアドオンがインストールされていない状況で、 Kubernetes 上には Pod が 1 つもない状態になっています。このとき、ディスクの使用量は 4258MB だったので、インストールと初回起動で 342MB を使用しました。

MicroK8s によって起動されたと思われるプロセスを示します(ps axuf)。

USER        PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root       2064  1.3  1.4 137692 27776 ?        Ssl  16:52   0:02 /snap/microk8s/412/kube-proxy --master=http://127.0.0.1:8080 --cluster-cidr=10.152.
root       2079  0.1  0.1  20048  3460 ?        Ss   16:52   0:00 /bin/bash /snap/microk8s/412/apiservice-kicker
root       4227  0.0  0.0   6176   792 ?        S    16:56   0:00  \_ sleep 3
root       2093  7.5  3.9 1564588 76512 ?       Ssl  16:52   0:16 /snap/microk8s/412/kubelet --kubeconfig=/snap/microk8s/412/configs/kubelet.config -
root       2102 13.9 16.2 446868 314316 ?       Ssl  16:52   0:31 /snap/microk8s/412/kube-apiserver --insecure-bind-address=0.0.0.0 --cert-dir=/var/s
root       2117  3.7  1.7 10534472 34256 ?      Ssl  16:52   0:08 /snap/microk8s/412/etcd --data-dir=/var/snap/microk8s/common/var/run/etcd --adverti
root       2135 15.9  5.1 205244 98488 ?        Ssl  16:52   0:35 /snap/microk8s/412/kube-controller-manager --master=http://127.0.0.1:8080 --service
root       2166  2.1  3.7 563180 72560 ?        Ssl  16:52   0:04 /snap/microk8s/412/usr/bin/dockerd --add-runtime nvidia=/snap/microk8s/412/usr/bin/
root       2572  0.7  1.7 510640 34536 ?        Ssl  16:52   0:01  \_ docker-containerd --config /var/snap/microk8s/common/var/run/docker/containerd/
root       2177  6.3  1.6 140100 32404 ?        Ssl  16:52   0:14 /snap/microk8s/412/kube-scheduler --master=http://127.0.0.1:8080

RSS(物理メモリ使用量)の単純な合計で 679MB になります。

k3s では、 CoreDNS と Traefik が DNSIngress を担当するようですので、 MicroK8s でも同様の環境になるよう、アドオンを追加してみましょう。

$ microk8s.enable dns ingress

デプロイが完了するまで少し待つと、 3 つの Pod が追加されます。

$ microk8s.kubectl get pods --all-namespaces
NAMESPACE     NAME                                      READY   STATUS    RESTARTS   AGE
default       default-http-backend-855bc7bc45-vbxdb     1/1     Running   0          90s
default       nginx-ingress-microk8s-controller-spjnz   1/1     Running   0          89s
kube-system   kube-dns-6ccd496668-czsrg                 3/3     Running   0          96s

同様に、ディスク使用量を調べると、 4666MB だったので、 MicroK8s インストール前と比べると 750MB 増加していることがわかります。

プロセスも同様に調べると、追加された Pod のコンテナに対応してプロセスが増えています。

USER        PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root       2064  1.0  1.4 137692 28012 ?        Ssl  16:52   0:04 /snap/microk8s/412/kube-proxy --master=http://127.0.0.1:8080 --cluster-cidr=10.152.
root       2079  0.1  0.1  20048  2932 ?        Ss   16:52   0:00 /bin/bash /snap/microk8s/412/apiservice-kicker
root       6736  0.0  0.0   6176   764 ?        S    16:59   0:00  \_ sleep 3
root       2102 11.8 16.3 447124 315668 ?       Ssl  16:52   0:45 /snap/microk8s/412/kube-apiserver --insecure-bind-address=0.0.0.0 --cert-dir=/var/s
root       2117  3.5  1.8 10535528 35024 ?      Ssl  16:52   0:13 /snap/microk8s/412/etcd --data-dir=/var/snap/microk8s/common/var/run/etcd --adverti
root       2135 14.6  5.4 205628 105000 ?       Ssl  16:52   0:56 /snap/microk8s/412/kube-controller-manager --master=http://127.0.0.1:8080 --service
root       2166  6.5  4.8 1284904 93300 ?       Ssl  16:52   0:25 /snap/microk8s/412/usr/bin/dockerd --add-runtime nvidia=/snap/microk8s/412/usr/bin/
root       2572  0.6  1.7 760168 33160 ?        Ssl  16:52   0:02  \_ docker-containerd --config /var/snap/microk8s/common/var/run/docker/containerd/
root       4884  0.0  0.2   7504  4040 ?        Sl   16:57   0:00      \_ docker-containerd-shim -namespace moby -workdir /var/snap/microk8s/common/v
root       5122  0.0  0.0   1024     4 ?        Ss   16:57   0:00      |   \_ /pause
root       4887  0.0  0.1   7504  3352 ?        Sl   16:57   0:00      \_ docker-containerd-shim -namespace moby -workdir /var/snap/microk8s/common/v
root       4986  0.0  0.0   1024     4 ?        Ss   16:57   0:00      |   \_ /pause
root       4939  0.0  0.2   8912  4308 ?        Sl   16:57   0:00      \_ docker-containerd-shim -namespace moby -workdir /var/snap/microk8s/common/v
root       4964  0.0  0.0   1024     4 ?        Ss   16:57   0:00      |   \_ /pause
root       5477  0.0  0.1   7504  3568 ?        Sl   16:57   0:00      \_ docker-containerd-shim -namespace moby -workdir /var/snap/microk8s/common/v
root       5509  0.0  0.0   4052   648 ?        Ss   16:57   0:00      |   \_ /usr/bin/dumb-init /nginx-ingress-controller --default-backend-service=
root       5550  1.6  1.2  38172 24160 ?        Ssl  16:57   0:01      |       \_ /nginx-ingress-controller --default-backend-service=default/default
root       5605  0.1  1.8 139428 36436 ?        S    16:57   0:00      |           \_ nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
nobody     6041  0.0  1.9 401764 38184 ?        Sl   16:58   0:00      |               \_ nginx: worker process
nobody     6042  0.0  1.9 401764 38184 ?        Sl   16:58   0:00      |               \_ nginx: worker process
nobody     6043  0.0  1.9 401764 38184 ?        Sl   16:58   0:00      |               \_ nginx: worker process
nobody     6140  0.0  1.9 401764 38184 ?        Sl   16:58   0:00      |               \_ nginx: worker process
root       5785  0.0  0.2   7568  4316 ?        Sl   16:57   0:00      \_ docker-containerd-shim -namespace moby -workdir /var/snap/microk8s/common/v
root       5815  0.3  1.1  39460 22064 ?        Ssl  16:57   0:00      |   \_ /kube-dns --domain=cluster.local. --dns-port=10053 --config-dir=/kube-d
root       5890  0.0  0.1   7504  3528 ?        Sl   16:58   0:00      \_ docker-containerd-shim -namespace moby -workdir /var/snap/microk8s/common/v
nobody     5921  0.0  0.2   8292  4656 ?        Ssl  16:58   0:00      |   \_ /server
root       6207  0.0  0.1   7440  3508 ?        Sl   16:58   0:00      \_ docker-containerd-shim -namespace moby -workdir /var/snap/microk8s/common/v
root       6228  0.1  1.0  32568 19636 ?        Ssl  16:58   0:00      |   \_ /dnsmasq-nanny -v=2 -logtostderr -configDir=/etc/k8s/dns/dnsmasq-nanny
root       6277  0.0  0.0   1172   824 ?        S    16:58   0:00      |       \_ /usr/sbin/dnsmasq -k --cache-size=1000 --no-negcache --log-facility
root       6378  0.0  0.2   7696  4248 ?        Sl   16:58   0:00      \_ docker-containerd-shim -namespace moby -workdir /var/snap/microk8s/common/v
nobody     6398  0.3  1.0  33416 19796 ?        Ssl  16:58   0:00          \_ /sidecar --v=2 --logtostderr --probe=kubedns,127.0.0.1:10053,kubernetes
root       2177  5.7  1.7 140100 34036 ?        Ssl  16:52   0:22 /snap/microk8s/412/kube-scheduler --master=http://127.0.0.1:8080
root       4631  7.4  4.3 1638576 83612 ?       Ssl  16:57   0:08 /snap/microk8s/412/kubelet --kubeconfig=/snap/microk8s/412/configs/kubelet.config -

RSS の合計は 1056MB です。つまり何も本質的な Pod をデプロイしていないにも関わらず、(雑な計算ですが)1GB のメモリが必要ということがわかりました。つらいですね。

操作ログ

k3s

それでは、 k3s がどれほど健闘してくれるのかを見ていきましょう。実験開始時のディスク使用量は、 4007MB でした。

インストールは、 1 ファイルをダウンロードしてくるだけと、非常に簡単です。

sudo wget -O /usr/local/bin/k3s https://github.com/rancher/k3s/releases/download/v0.1.0/k3s
sudo chmod a+x /usr/local/bin/k3s

この実行可能ファイルは、 36MB でした。

起動も以下の通り root で k3s server を実行するだけです。 root 以外で実行すると「must run as root unless --disable-agent is specified」とエラーになります。コンテナを起動するには root である必要がありますが、 kube-apiserver になるだけだったら root は要らないということでしょう。

sudo k3s server

起動して 30 秒くらい待つと、 API が応答を返してくれるようになります。 k3s の初期設定に含まれている Pod がすべて起動し終わると、このようになります。

$ k3s kubectl get pods --all-namespaces
NAMESPACE     NAME                             READY   STATUS      RESTARTS   AGE
kube-system   coredns-7748f7f6df-xjdck         1/1     Running     0          98s
kube-system   helm-install-traefik-wpxtr       0/1     Completed   0          97s
kube-system   svclb-traefik-68bf87cd49-s6zct   2/2     Running     0          49s
kube-system   traefik-dcd66ffd7-2cxsp          1/1     Running     0          49s

ここまでくれば、平常状態として落ち着いたということなので、ディスク使用量とメモリ使用量を調べてみましょう。

k3s が実行中のときに df を実行すると、コンテナのファイルシステムが丸見えです。

$ df
Filesystem     1K-blocks    Used Available Use% Mounted on
udev              933964       0    933964   0% /dev
tmpfs             192920    1004    191916   1% /run
/dev/sda2       32378672 4516096  26194788  15% /
tmpfs             964588       0    964588   0% /dev/shm
tmpfs               5120       0      5120   0% /run/lock
tmpfs             964588       0    964588   0% /sys/fs/cgroup
/dev/loop0         88704   88704         0 100% /snap/core/4486
/dev/sda1         523248    6152    517096   2% /boot/efi
tmpfs             192916       0    192916   0% /run/user/1000
/dev/loop1         93184   93184         0 100% /snap/core/6405
shm                65536       0     65536   0% /run/k3s/containerd/io.containerd.grpc.v1.cri/sandboxes/0e81fed3ef7f431a88dedc39673237dffb622ac9f6787d5f4fe1f276f1abee98/shm
overlay         32378672 4516096  26194788  15% /run/k3s/containerd/io.containerd.runtime.v1.linux/k8s.io/0e81fed3ef7f431a88dedc39673237dffb622ac9f6787d5f4fe1f276f1abee98/rootfs
overlay         32378672 4516096  26194788  15% /run/k3s/containerd/io.containerd.runtime.v1.linux/k8s.io/280f805f2dc3e1d44e3863feb5bf2473ecc3deba8a2cb4afd25a0b00b01d1f56/rootfs
shm                65536       0     65536   0% /run/k3s/containerd/io.containerd.grpc.v1.cri/sandboxes/1c0f3752efc0b80a9d061849b8d8e1102a878b6656f3390a7a497378898d95c1/shm
overlay         32378672 4516096  26194788  15% /run/k3s/containerd/io.containerd.runtime.v1.linux/k8s.io/1c0f3752efc0b80a9d061849b8d8e1102a878b6656f3390a7a497378898d95c1/rootfs
shm                65536       0     65536   0% /run/k3s/containerd/io.containerd.grpc.v1.cri/sandboxes/5d97f4ca5f5a9b411f475168348bc8a3c556dc6af3fc052184054d0a218e0956/shm
overlay         32378672 4516096  26194788  15% /run/k3s/containerd/io.containerd.runtime.v1.linux/k8s.io/5d97f4ca5f5a9b411f475168348bc8a3c556dc6af3fc052184054d0a218e0956/rootfs
overlay         32378672 4516096  26194788  15% /run/k3s/containerd/io.containerd.runtime.v1.linux/k8s.io/5d3638c53a42dac010b73bc9f490727e42c10715184a3da69a8ae7a515ec7b30/rootfs
overlay         32378672 4516096  26194788  15% /run/k3s/containerd/io.containerd.runtime.v1.linux/k8s.io/0ba750b1790f57e359e87bf69f764ef8d3df9e12e648e5551464f695cb82ab81/rootfs
overlay         32378672 4516096  26194788  15% /run/k3s/containerd/io.containerd.runtime.v1.linux/k8s.io/795267aaecee9d2f8e8ae12b27aac12acb9485b13fe8887a9d99eee553e49b3b/rootfs

それはともかく / の使用量は 4410MB なので、実験開始前から 403MB の増加です。

プロセスも見てみましょう。

USER        PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
azyobuz+   1842  0.0  0.2  21460  5152 pts/1    Ss   17:12   0:00  |       \_ -bash
root       1947  0.0  0.2  68612  4416 pts/1    S+   17:15   0:00  |           \_ sudo k3s server
root       1948 41.5 13.7 332292 264612 pts/1   Sl+  17:15   1:12  |               \_ k3s server
root       1977  5.8  4.0 190064 78524 pts/1    Sl+  17:15   0:09  |                   \_ containerd -c /var/lib/rancher/k3s/agent/etc/containerd/config.toml -a /run/k3s/containerd
root       2465  0.0  0.2 108760  5128 pts/1    Sl   17:15   0:00  |                       \_ containerd-shim -namespace k8s.io -workdir /var/lib/rancher/k3s/agent/containerd/io.co
root       2482  0.0  0.0   1024     4 ?        Ss   17:15   0:00  |                       |   \_ /pause
root       2654  0.0  0.2 108760  5308 pts/1    Sl   17:16   0:00  |                       \_ containerd-shim -namespace k8s.io -workdir /var/lib/rancher/k3s/agent/containerd/io.co
root       2672  0.6  1.5 142912 30152 ?        Ssl  17:16   0:00  |                       |   \_ /coredns -conf /etc/coredns/Corefile
root       3166  0.0  0.2 107352  5140 pts/1    Sl   17:16   0:00  |                       \_ containerd-shim -namespace k8s.io -workdir /var/lib/rancher/k3s/agent/containerd/io.co
root       3185  0.0  0.0   1024     4 ?        Ss   17:16   0:00  |                       |   \_ /pause
root       3222  0.0  0.2 108760  4620 pts/1    Sl   17:16   0:00  |                       \_ containerd-shim -namespace k8s.io -workdir /var/lib/rancher/k3s/agent/containerd/io.co
root       3240  0.0  0.0   1024     4 ?        Ss   17:16   0:00  |                       |   \_ /pause
root       3303  0.0  0.2 108760  5316 pts/1    Sl   17:16   0:00  |                       \_ containerd-shim -namespace k8s.io -workdir /var/lib/rancher/k3s/agent/containerd/io.co
root       3324  1.9  2.3 172020 46240 ?        Ssl  17:16   0:01  |                       |   \_ /traefik --configfile=/config/traefik.toml
root       3390  0.0  0.2 108760  5068 pts/1    Sl   17:16   0:00  |                       \_ containerd-shim -namespace k8s.io -workdir /var/lib/rancher/k3s/agent/containerd/io.co
root       3410  0.0  0.0   1584  1120 ?        Ss   17:16   0:00  |                       |   \_ /bin/sh /usr/bin/entry
root       3456  0.0  0.2 108824  5072 pts/1    Sl   17:16   0:00  |                       \_ containerd-shim -namespace k8s.io -workdir /var/lib/rancher/k3s/agent/containerd/io.co
root       3484  0.0  0.0   1584  1124 ?        Ss   17:16   0:00  |                           \_ /bin/sh /usr/bin/entry

ちょうど Pod に対応する pause プロセスと、 Running なコンテナに対応するプロセスが存在していることがわかります。 RSS の合計(bash、sudo を除く)は 447MB です。

操作ログ

結果のまとめ

Kubernetes ディストリビューション ディスク使用量 (MB) メモリ使用量 (MB)
MicroK8s (アドオンなし) 342 679
MicroK8s (DNS, Ingress アドオン) 750 1056
k3s 403 447

k3s は、 tar.gz が埋め込まれている k3s 実行可能ファイルと、展開後のファイルの合算なので、ディスク使用量では少し足を引っ張りましたが、サーバー機能の多くを 1 バイナリに収めているので、メモリ使用量ではかなり健闘しています。このメモリ使用量は適当に ps コマンドが吐く RSS を足しただけなので、実際に長時間稼働させていれば、アクセス頻度の少ないデータはスワップに吐き出されるでしょうから、常時これだけのメモリ容量を占有されるわけではないはずです。しかし、初期状態でどのくらいのメモリを使用しているかは、自分の Pod をどれだけデプロイできるかという重要な問題と関係するので、初期状態におけるメモリ使用量が少ないことは非常に意味のあることだと思います。

追記: k3s のディスク使用量ですが、 root で k3s server を実行した後、一般ユーザーで k3s kubectl を実行しているので、2か所にファイルが展開された結果のサイズになっているかもしれません。再調査する元気が起きないですが、たぶん 100MB くらい大きい値が出てしまっています。

結論

k3s は、シングルバイナリ!というと何か違うような気もしますが、軽量で、そして簡単に使える Kubernetes ディストリビューションとして、素晴らしいものに仕上がっていると思います。ただ、これでもまだメモリ 1GB 環境で動かすにはメモリ使用量が多いなぁという気持ちがあります。うーん。