安装containerd
使用docker运行kata容器有点麻烦,要用到docker in docker,因此这里用containerd。
1、下载containerd,解压到/usr/local/目录:
tar xvf containerd-1.7.14-linux-amd64.tar.gz -C /usr/local/
2、containerd --version
containerd github.com/containerd/containerd v1.7.14 dcf2847247e18caba8dce86522029642f60fe96b
3、配置containerd的systemd服务:
cat /etc/systemd/system/containerd.service
[Unit]
Description=containerd container runtime
Documentation=h**ps://containerd.io
After=network.target local-fs.target
[Service]
ExecStartPre=-/sbin/modprobe overlay
ExecStart=/usr/local/bin/containerd
Type=notify
Delegate=yes
KillMode=process
Restart=always
RestartSec=5
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNPROC=infinity
LimitCORE=infinity
# Comment TasksMax if your systemd version does not supports it.
# Only systemd 226 and above support this version.
TasksMax=infinity
OOMScoreAdjust=-999
[Install]
WantedBy=multi-user.target
4、生成默认配置:
mkdir /etc/containerd
containerd config default > /etc/containerd/config.toml
5、将kata运行时添加到containerd,/etc/containerd/config.toml:
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.kata]
runtime_type = "io.containerd.kata.v2"
privileged_without_host_devices = false
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes]
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc]
base_runtime_spec = ""
cni_conf_dir = ""
cni_max_conf_num = 0
container_annotations = []
pod_annotations = []
privileged_without_host_devices = false
privileged_without_host_devices_all_devices_allowed = false
runtime_engine = ""
runtime_path = ""
runtime_root = ""
runtime_type = "io.containerd.runc.v2"
sandbox_mode = "podsandbox"
snapshotter = ""
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options]
BinaryName = ""
CriuImagePath = ""
CriuPath = ""
CriuWorkPath = ""
IoGid = 0
IoUid = 0
NoNewKeyring = false
NoPivotRoot = false
Root = ""
ShimCgroup = ""
SystemdCgroup = false
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.kata]
runtime_type = "io.containerd.kata.v2"
privileged_without_host_devices = false
6、重启containerd服务
systemctl daemon-reload
systemctl start containerd
systemctl enable containerd
systemctl status containerd
安装kata-containers
1、下载kata-containers,解压到/,并创建软链接:
tar xvf kata-static-3.2.0-amd64.tar.xz -C /
ln -s /opt/kata/bin/containerd-shim-kata-v2 /usr/local/bin/containerd-shim-kata-v2
ln -s /opt/kata/bin/kata-collect-data.sh /usr/local/bin/kata-collect-data.sh
ln -s /opt/kata/bin/kata-runtime /usr/local/bin/kata-runtime
2、查看版本
kata-runtime --version
kata-runtime kata-check
创建kata容器
1、ctr image import busy-box
2、ctr run --runtime "io.containerd.kata.v2" --rm -t docker.io/library/busybox:latest test-kata uname –r
3、启动容器不退出:
ctr run --runtime "io.containerd.kata.v2" --rm -t docker.io/library/busybox:latest test-kata sleep infinity
4、查看qemu进程:
5、登录容器(虚机):
ctr tasks exec -t --exec-id 1 test-kata sh
6、删除容器:
ctr tasks kill test-kata