Ubuntu + CRI-O + kubeadmでKubernetesな環境は次のような感じで構築できました。
今回はその構成にKata Containerをねじ込みたいと思います。
過去にcontainerdベースの構成は試していました。こちらもいずれRuntime Classを使ってKataを利用する構成に書き換えたいですね。
概要
今回の内容の要点をまとめると次のとおりです。
- UbuntuにKata Containerをインストール
- Ubuntu + CRI-O + kubeadmでKubernetesクラスターを作成
- Kata Runtimeの設定を追記
- Runtime Classを使ってコンテナー作成
次項でセットアップ手順を取り上げます。
セットアップ手順
UbuntuにKata Containerをインストール
Ubuntuは18.04.3に最新のアップデートを適用した状態の環境を用意します。 Kata Containerのインストール方法は、公式の手順のままでOKです。
$ ARCH=$(arch)
$ BRANCH="${BRANCH:-master}"
$ sudo sh -c "echo 'deb http://download.opensuse.org/repositories/home:/katacontainers:/releases:/${ARCH}:/${BRANCH}/xUbuntu_$(lsb_release -rs)/ /' > /etc/apt/sources.list.d/kata-containers.list"
$ curl -sL http://download.opensuse.org/repositories/home:/katacontainers:/releases:/${ARCH}:/${BRANCH}/xUbuntu_$(lsb_release -rs)/Release.key | sudo apt-key add -
$ sudo -E apt-get update
$ sudo -E apt-get -y install kata-runtime kata-proxy kata-shim qemu-kvm
Ubuntu + CRI-O + kubeadmでKubernetesクラスターを作成
CRI-Oのセットアップをします。 kubeadm、kubelet、kubectlなどをインストールします。 kubeletにCRI-Oのための設定を追記したあと、kubeadm initでKubernetesクラスターを作成します。 何らかのCNIを導入します。
ここは前回の手順と共通するところなので、詳細は次の記事をご覧ください(バージョンは1.17.2に置き換えてください)。
Kata Runtimeの設定を追記
CRI-OがKata Containerを利用するための設定を追記します。KubernetesではRuntime Classが呼び出されたときのみKataを使うように設定してみたいと思います。
# vi /etc/crio/crio.conf [crio.runtime] ... manage_network_ns_lifecycle = true ... # The "crio.runtime.runtimes" table defines a list of OCI compatible runtimes. # The runtime to use is picked based on the runtime_handler provided by the CRI. # If no runtime_handler is provided, the runtime will be picked based on the level # of trust of the workload. [crio.runtime.runtimes.runc] runtime_path = "/usr/lib/cri-o-runc/sbin/runc" runtime_type = "" #以下追記 [crio.runtime.runtimes.kata-runtime] runtime_path = "/usr/bin/kata-runtime" runtime_type = "oci" ...
設定変更後、CRI-Oを再起動します。
# systemctl daemon-reload # systemctl restart crio kubelet
Runtime Classを使ってコンテナー作成
昔のKubernetesは利用できるランタイムは一つだけだったようですが、バージョン1.14以降のKubernetesを使えばRuntime Classを使うことで他のランタイムを使うことができます。
早速試す前に、CRIとしてCRI-Oを設定したKubernetesがきちんと動いているか確認しましょう。次のYAMLを作成してPodを作ってみてください。問題なくRunningになると思います。 うまくいかない場合は kubectl describe -f hello1.yaml で原因を探りましょう。
~# cat hello1.yaml
apiVersion: v1
kind: Pod
metadata:
name: hello-alpine
spec:
containers:
- name: alpine
image: docker.io/alpine
tty: true
~# kubectl create -f hello1.yaml
次に、Runtime Classを使ってコンテナー作成してみます。次のYAMLを作成してPodを作ってみてください。問題なくRunningになると思います。 うまくいかない場合は kubectl describe -f hello1.yaml で原因を探りましょう。
~# cat hello2.yaml
---
apiVersion: node.k8s.io/v1beta1 # RuntimeClass is defined in the node.k8s.io API group
kind: RuntimeClass
metadata:
name: myclass1 # The name the RuntimeClass will be referenced by
# RuntimeClass is a non-namespaced resource
handler: kata-runtime
---
apiVersion: v1
kind: Pod
metadata:
name: hello-alpine2
spec:
runtimeClassName: myclass1
containers:
- name: alpine
image: docker.io/alpine
tty: true
~# kubectl create -f hello2.yaml
実際にKata Runtimeを使ってPodを作っているかは kata-runtime list コマンドと ps aux|grep "<kata-runtime listで出力されたID>"|grep "hello-alpine2" コマンドを使えば確認できると思います。お疲れさまでした。
追記1
CRI-O 1.15では、Untrusted annotation (until CRI-O v1.12)を使った方法でも利用できるようです。
次のように /etc/crio/crio.conf に記述すれば、ページの最後にある nginx-untrusted.yaml のように記述したPod YAMLを使うことでKata Containerを使えるようです。
[crio.runtime] ... runtime_untrusted_workload = "/usr/bin/kata-runtime" default_workload_trust = "untrusted" manage_network_ns_lifecycle = true
追記2
「次はFlannelではなくてCiliumをCNIで使う構成ができるか検証してみたいと思います。」...みたいなことを書いたので試してみましたが、CiliumやWeave Netをつかった構成もうまく動作しました。Network Policyもうまく動いています。