kata-containers 编译安装
kata-runtime 编译安装
1
|
# download source code
|
kata-shim 编译安装
1
|
# download source code
|
kata-proxy 编译安装
1
|
# download source code
|
编译 kata 所需的 kernel
1
|
# download source code
|
编译 agent (可选)
1
|
$ go get -d -u github.com/kata-containers/agent
|
编译 rootfs 文件系统
1
|
# download source code
|
编译 rootfs.img
1
|
# make sure rootfs is not MODIFIED!!! if you want to add new Agent
|
编译 initrd.img
1
|
# make sure rootfs is not MODIFIED!!! if you want to add new Agent
|
编译 qemu on aarch64
1
|
# 下载代码
|
Docker 对接 kata-runtime
修改 Docker 配置文件/etc/docker/daemon.json
1
|
{
|
重启 docker 服务(必须)
验证修改生效
sudo docker run --rm --name test busybox:latest uname -a
与宿主机内核对比,验证是否生效
调试 kata-runtime
1
|
# docker 开启 debug: /etc/docker/daemon.json 添加参数 (需重启服务)
|
Containerd 对接 containerd-shim-kata-v2
修改 containerd 的配置/etc/containerd/config.toml
containerd config default
生成当前版本默认配置
1
|
root = "/var/lib/containerd"
|
注意: 确保containerd-shim-kata-v2
文件在 $PATH 目录下
验证:
1
|
# 创建容器
|
调试 containerd-shim-runtime-v2
1
|
# containerd 配置开启 debug(需重启服务)
|
附录
kata-containers 2.0 安装
-
下载release包
下载 Kata Containers 2.0.0-alpha3
解压后,拷贝至文件夹
/opt
-
准备配置文件和
containerd-shim-kata-v2
1
2
3
4# 准备配置文件
$ cp /opt/kata/share/defaults/kata-containers/configuration-qemu.toml /etc/kata-containers/configuration.toml
# 准备 containerd-shim-kata-v2
$ cp /opt/kata/bin/containerd-shim-kata-v2 /usr/local/bin/配置文件修改如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38[hypervisor.qemu]
path = "/opt/kata/bin/qemu-system-x86_64"
kernel = "/opt/kata/share/kata-containers/vmlinuz.container"
image = "/opt/kata/share/kata-containers/kata-containers.img"
machine_type = "pc"
kernel_params = ""
firmware = ""
machine_accelerators=""
cpu_features="pmu=off"
default_vcpus = 1
default_maxvcpus = 2
default_bridges = 1
default_memory = 2048
disable_block_device_use = false
shared_fs = "virtio-9p"
virtio_fs_daemon = "/opt/kata/bin/virtiofsd"
virtio_fs_cache_size = 1024
virtio_fs_extra_args = []
virtio_fs_cache = "auto"
block_device_driver = "virtio-scsi"
enable_iothreads = false
enable_vhost_user_store = false
vhost_user_store_path = "/var/run/kata-containers/vhost-user"
enable_debug = true
[factory]
[agent.kata]
enable_debug = true
kernel_modules=[]
[netmon]
path = "/opt/kata/libexec/kata-containers/kata-netmon"
enable_debug = true
[runtime]
enable_debug = true
internetworking_model="tcfilter"
disable_guest_seccomp=true
sandbox_cgroup_only=false
experimental=[]
EnablePprof = true
对接docker和containerd需要注意
注意:此版本无法与 docker配合使用,与containerd 使用正常。
In this article, you will learn how to use Kata Containers on IBM Power systems.
#Prerequisites:
You need to install golang version 1.8.3 or newer, make, gcc, qemu.
#Steps:
1.Build and install the Kata Containers runtime
$ go get -d -u github.com/kata-containers/runtime$ cd $GOPATH/src/github.com/kata-containers/runtime$ make && sudo -E PATH=$PATH make install
The build will create the following:
runtime binary: /usr/local/bin/kata-runtime
configuration file: /usr/share/defaults/kata-containers/configuration.toml
2. Check if your system is capable of creating a Kata Container:
$ sudo kata-runtime kata-check
If your system is not able to run Kata Containers, the previous command will error out and explain why.
3. Configure to use initrd image
$ sudo sed -i ‘s/^(image =.*)/# 1/g’ /usr/share/defaults/kata-containers/configuration.toml
4. Enable full debug
$ sudo sed -i -e ‘s/^# *(enable_debug).*=.*$/1 = true/g’ /usr/share/defaults/kata-containers/configuration.toml$ sudo sed -i -e ‘s/^kernel_params = “(.*)”/kernel_params = “1 agent.log=debug”/g’ /usr/share/defaults/kata-containers/configuration.toml
5. Build and install Kata proxy
$ go get -d -u github.com/kata-containers/proxy$ cd $GOPATH/src/github.com/kata-containers/proxy && make && sudo make install
6. Build and install Kata shim
$ go get -d -u github.com/kata-containers/shim$ cd $GOPATH/src/github.com/kata-containers/shim && make && sudo make install
7. Get the osbuilder
$ go get -d -u github.com/kata-containers/osbuilder
8. Build a custom Kata agent — OPTIONAL
$ go get -d -u github.com/kata-containers/agent$ cd $GOPATH/src/github.com/kata-containers/agent && make
9. Create an initrd image
$ export ROOTFS_DIR=”${GOPATH}/src/github.com/kata-containers/osbuilder/rootfs-builder/rootfs"$ sudo rm -rf ${ROOTFS_DIR}$ cd $GOPATH/src/github.com/kata-containers/osbuilder/rootfs-builder$ script -fec ‘sudo -E GOPATH=$GOPATH AGENT_INIT=yes USE_DOCKER=true ./rootfs.sh ${distro}’
AGENT_INIT controls if the guest image uses kata agent as the guest init process. When you create an initrd image, always set AGENT_INIT to yes.
You MUST choose one of alpine, centos and fedora for ${distro}.
Optionally, add your custom agent binary to the rootfs with the following:
$ sudo install -o root -g root -m 0550 -T ../../agent/kata-agent ${ROOTFS_DIR}/sbin/init
10. Build an initrd image
$ cd $GOPATH/src/github.com/kata-containers/osbuilder/initrd-builder$ script -fec ‘sudo -E AGENT_INIT=yes USE_DOCKER=true ./initrd_builder.sh ${ROOTFS_DIR}’
11. Install the initrd image
$ commit=$(git log — format=%h -1 HEAD)$ date=$(date +%Y-%m-%d-%T.%N%z)$ image=”kata-containers-initrd-${date}-${commit}”$ sudo install -o root -g root -m 0640 -D kata-containers-initrd.img “/usr/share/kata-containers/${image}”$ (cd /usr/share/kata-containers && sudo ln -sf “$image” kata-containers-initrd.img)
12. Install guest kernel images
As a prerequisite, you need to install libelf-dev and bc. Otherwise, you will not be able to build the kernel from sources.
$ go get github.com/kata-containers/tests$ cd $GOPATH/src/github.com/kata-containers/tests/.ci$ kernel_arch=”$(./kata-arch.sh)”$ kernel_dir=”$(./kata-arch.sh — kernel)”$ tmpdir=”$(mktemp -d)”$ pushd “$tmpdir”$ curl -L https://raw.githubusercontent.com/kata-containers/packaging/master/kernel/configs/${kernel_arch}_kata_kvm_4.14.x -o .config$ kernel_version=$(grep “Linux/[${kernel_arch}]*” .config | cut -d’ ‘ -f3 | tail -1)$ kernel_tar_file=”linux-${kernel_version}.tar.xz”$ kernel_url=”https://cdn.kernel.org/pub/linux/kernel/v$(echo $kernel_version | cut -f1 -d.).x/${kernel_tar_file}”$ curl -LOk ${kernel_url}$ tar -xf ${kernel_tar_file}$ mv .config “linux-${kernel_version}”$ pushd “linux-${kernel_version}”$ make ARCH=${kernel_dir} -j$(nproc)$ kata_kernel_dir=”/usr/share/kata-containers”$ kata_vmlinuz=”${kata_kernel_dir}/kata-vmlinuz-${kernel_version}.container”$ [ $kernel_arch = ppc64le ] && kernel_file=”$(realpath ./vmlinux)” || kernel_file=”$(realpath arch/${kernel_arch}/boot/bzImage)”$ sudo install -o root -g root -m 0755 -D “${kernel_file}” “${kata_vmlinuz}”$ sudo ln -sf “${kata_vmlinuz}” “${kata_kernel_dir}/vmlinuz.container”$ kata_vmlinux=”${kata_kernel_dir}/kata-vmlinux-${kernel_version}”$ sudo install -o root -g root -m 0755 -D “$(realpath vmlinux)” “${kata_vmlinux}”$ sudo ln -sf “${kata_vmlinux}” “${kata_kernel_dir}/vmlinux.container”$ popd$ popd$ rm -rf “${tmpdir}”
13. Run Kata Containers with Docker
Update Docker configuration
$ dir=/etc/systemd/system/docker.service.d$ file=”$dir/kata-containers.conf”$ sudo mkdir -p “$dir”$ sudo test -e “$file” || echo -e “[Service]
Type=simple
ExecStart=
ExecStart=/usr/bin/dockerd -D — default-runtime runc” | sudo tee “$file”$ sudo grep -q “kata-runtime=” $file || sudo sed -i ‘s!^(ExecStart=[^$].*$)!1 — add-runtime kata-runtime=/usr/local/bin/kata-runtime!g’ “$file”$ sudo systemctl daemon-reload$ sudo systemctl restart docker
14. Create a Kata Container using Docker
$ sudo docker run -ti — runtime kata-runtime busybox sh
15. Check the logs in-case of failure
$ journalctl -q -o cat -a -t kata-runtime
$ journalctl -q -o cat -a -t kata-proxy