手元のクラスタ(kind)でgvisorを試す

kindでgvisorを使用できるようにする。

nodeに入る。(自分のケースでは1node構成なので、control-planeになっている。)

docker exec -it kind-control kind-control-plane bash

gvisorをインストールする。

以下はInstallation - gVisorにあるインストールスクリプトを少しいじったものになっている。

  set -e
  ARCH=$(uname -m)
  URL=https://storage.googleapis.com/gvisor/releases/release/latest/${ARCH}
  wget ${URL}/runsc ${URL}/runsc.sha512 \
    ${URL}/containerd-shim-runsc-v1 ${URL}/containerd-shim-runsc-v1.sha512
  sha512sum -c runsc.sha512 \
    -c containerd-shim-runsc-v1.sha512
  rm -f *.sha512
  chmod a+rx runsc containerd-shim-runsc-v1
  mv runsc containerd-shim-runsc-v1 /usr/local/bin

containerdでrunscを利用できるように設定変更。

@@ -7,6 +7,9 @@
   type = "snapshot"
   address = "/run/containerd-fuse-overlayfs.sock"
 
+[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runsc]
+  runtime_type = "io.containerd.runsc.v1"
+
 [plugins."io.containerd.grpc.v1.cri".containerd]
   # save disk space when using a single snapshotter
   discard_unpacked_layers = true

containedを再起動

systemctl restart containerd

RuntimeClassとテスト用podの作成

RuntimeClass

apiVersion: node.k8s.io/v1
kind: RuntimeClass
metadata:
  name: gvisor
handler: runsc

test用pod

apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: nginx
  name: nginx
spec:
  runtimeClassName: gvisor
  containers:
  - image: nginx
    name: nginx
    resources: {}
  dnsPolicy: ClusterFirst
  restartPolicy: Always
status: {}

gvisorが正しく動いていることを確認する

gvisorはuserspace kernelが動くので、コンテナ上のカーネルバージョンとノードのカーネルバージョンに差分がでるようになる。
これを確認する。

# hostmachine
6.5.0-25-generic
# nginx container
root@nginx:/# uname -r           
4.4.0 

ちゃんと差分が出てる。

一応、カーネルのログも確認してみる。

# nginx container
root@nginx:/# dmesg         
[    0.000000] Starting gVisor...
[    0.506367] Moving files to filing cabinet...
[    0.907249] Segmenting fault lines...
[    1.396441] Constructing home...
[    1.678327] Creating cloned children...
[    1.952515] Daemonizing children...
[    2.002172] Reticulating splines...
[    2.237456] Verifying that no non-zero bytes made their way into /dev/zero...
[    2.422350] Letting the watchdogs out...
[    2.890127] Creating process schedule...
[    3.020322] Consulting tar man page...
[    3.473949] Setting up VFS...
[    3.623193] Setting up FUSE...
[    4.057643] Ready!

いい感じ。。