|
| 1 | +* [Warning](#warning) |
| 2 | +* [Assumptions](#assumptions) |
| 3 | +* [Build and install a Kata Containers runtime](#build-and-install-a-kata-containers-runtime) |
| 4 | + * [Check hardware requirements](#check-hardware-requirements) |
| 5 | + * [Enable full debug](#enable-full-debug) |
| 6 | +* [Build and install Kata proxy](#build-and-install-kata-proxy) |
| 7 | +* [Build and install Kata shim](#build-and-install-kata-shim) |
| 8 | +* [Create an image](#create-an-image) |
| 9 | + * [Build a custom Kata agent - OPTIONAL](#build-a-custom-kata-agent---optional) |
| 10 | + * [Get the osbuilder](#get-the-osbuilder) |
| 11 | + * [Create a rootfs image](#create-a-rootfs-image) |
| 12 | + * [Add a custom agent to the image - OPTIONAL](#add-a-custom-agent-to-the-image---optional) |
| 13 | + * [Build the image](#build-the-image) |
| 14 | +* [Install the image](#install-the-image) |
| 15 | +* [Install guest kernel images](#install-guest-kernel-images) |
| 16 | +* [Update Docker configuration](#update-docker-configuration) |
| 17 | +* [Create a Kata Container](#create-a-kata-container) |
| 18 | +* [Troubleshoot](#troubleshoot) |
| 19 | +* [Appendices](#appendices) |
| 20 | + * [Checking Docker default runtime](#checking-docker-default-runtime) |
| 21 | + |
| 22 | +# Warning |
| 23 | + |
| 24 | +This document is written **specifically for developers**. |
| 25 | + |
| 26 | +# Assumptions |
| 27 | + |
| 28 | +- You are working on a non-critical test or development system. |
| 29 | +- You already have the following installed: |
| 30 | + - [Docker](https://www.docker.com/). |
| 31 | + - [golang](https://golang.org/dl) version 1.8.3 or newer. |
| 32 | + - `make`. |
| 33 | + - `gcc` (required for building the shim and runtime). |
| 34 | + |
| 35 | +- You have installed the Clear Containers `linux-container` and `qemu-lite` |
| 36 | + packages containing the guest kernel images and hypervisor. These packages |
| 37 | + automatically installed when you install Clear Containers, but can be |
| 38 | + installed separately: |
| 39 | + |
| 40 | + https://github.com/clearcontainers/runtime/wiki/Installation |
| 41 | + |
| 42 | +# Build and install the Kata Containers runtime |
| 43 | + |
| 44 | +``` |
| 45 | +$ go get -d -u github.com/kata-containers/runtime |
| 46 | +$ cd $GOPATH/src/github.com/kata-containers/runtime |
| 47 | +$ make && sudo -E PATH=$PATH make install |
| 48 | +``` |
| 49 | + |
| 50 | +The build will create the following: |
| 51 | + |
| 52 | +- runtime binary: `/usr/local/bin/kata-runtime` |
| 53 | +- configuration file: `/usr/share/defaults/kata-containers/configuration.toml` |
| 54 | + |
| 55 | +# Check hardware requirements |
| 56 | + |
| 57 | +You can check if your system is capable of creating a Kata Container by running the following: |
| 58 | + |
| 59 | +``` |
| 60 | +$ sudo kata-runtime kata-check |
| 61 | +``` |
| 62 | + |
| 63 | +If your system is *not* able to run Kata Containers, the previous command will error and explain why. |
| 64 | + |
| 65 | +## Enable full debug |
| 66 | + |
| 67 | +Enable full debug as follows: |
| 68 | +``` |
| 69 | +$ sudo sed -i -e 's/^# *\(enable_debug\).*=.*$/\1 = true/g' /usr/share/defaults/kata-containers/configuration.toml |
| 70 | +$ sudo sed -i -e 's/^kernel_params = ""/kernel_params = "agent.log=debug"/g' /usr/share/defaults/kata-containers/configuration.toml |
| 71 | +``` |
| 72 | + |
| 73 | +# Build and install Kata proxy |
| 74 | + |
| 75 | +``` |
| 76 | +$ go get -d -u github.com/kata-containers/proxy |
| 77 | +$ cd $GOPATH/src/github.com/kata-containers/proxy && make && sudo make install |
| 78 | +``` |
| 79 | + |
| 80 | +# Build and install Kata shim |
| 81 | + |
| 82 | +``` |
| 83 | +$ go get -d -u github.com/kata-containers/shim |
| 84 | +$ cd $GOPATH/src/github.com/kata-containers/shim && make && sudo make install |
| 85 | +``` |
| 86 | + |
| 87 | +# Create an image |
| 88 | + |
| 89 | +## Build a custom Kata agent - OPTIONAL |
| 90 | + |
| 91 | +> **Note:** |
| 92 | +> |
| 93 | +> - You only do this step if you test with the latest version of the agent. |
| 94 | +
|
| 95 | +``` |
| 96 | +$ go get -d -u github.com/kata-containers/agent |
| 97 | +$ cd $GOPATH/src/github.com/kata-containers/agent && make |
| 98 | +``` |
| 99 | + |
| 100 | +## Get the osbuilder |
| 101 | + |
| 102 | +``` |
| 103 | +$ go get -d -u github.com/kata-containers/osbuilder |
| 104 | +``` |
| 105 | + |
| 106 | +## Create a rootfs image |
| 107 | + |
| 108 | +``` |
| 109 | +$ cd $GOPATH/src/github.com/kata-containers/osbuilder/rootfs-builder |
| 110 | +$ script -fec 'sudo -E GOPATH=$GOPATH USE_DOCKER=true ./rootfs.sh clearlinux' |
| 111 | +``` |
| 112 | + |
| 113 | +> **Note:** |
| 114 | +> |
| 115 | +> - You must ensure that the *default Docker runtime* is `runc` to make use of |
| 116 | +> the `USE_DOCKER` variable. If that is not the case, remove the variable |
| 117 | +> from the previous command. See [Checking Docker default runtime](#checking-docker-default-runtime). |
| 118 | +
|
| 119 | +### Add a custom agent to the image - OPTIONAL |
| 120 | + |
| 121 | +> **Note:** |
| 122 | +> |
| 123 | +> - You only do this step if you test with the latest version of the agent. |
| 124 | +
|
| 125 | +``` |
| 126 | +$ sudo install -o root -g root -m 0550 -t rootfs/bin ../../agent/kata-agent |
| 127 | +$ sudo install -o root -g root -m 0440 ../../agent/kata-agent.service rootfs/usr/lib/systemd/system/ |
| 128 | +$ sudo install -o root -g root -m 0440 ../../agent/kata-containers.target rootfs/usr/lib/systemd/system/ |
| 129 | +``` |
| 130 | + |
| 131 | +## Build the image |
| 132 | + |
| 133 | +``` |
| 134 | +$ cd $GOPATH/src/github.com/kata-containers/osbuilder/image-builder |
| 135 | +$ script -fec 'sudo -E USE_DOCKER=true ./image_builder.sh ../rootfs-builder/rootfs' |
| 136 | +``` |
| 137 | + |
| 138 | +> **Notes:** |
| 139 | +> |
| 140 | +> - You must ensure that the *default Docker runtime* is `runc` to make use of |
| 141 | +> the `USE_DOCKER` variable. If that is not the case, remove the variable |
| 142 | +> from the previous command. See [Checking Docker default runtime](#checking-docker-default-runtime). |
| 143 | +> - If you do *not* wish to build under Docker, remove the `USE_DOCKER` |
| 144 | +> variable in the previous command and ensure the `qemu-img` command is |
| 145 | +> available on your system. |
| 146 | +
|
| 147 | +# Install the image |
| 148 | + |
| 149 | +``` |
| 150 | +$ commit=$(git log --format=%h -1 HEAD) |
| 151 | +$ date=$(date +%Y-%m-%d-%T.%N%z) |
| 152 | +$ image="kata-containers-${date}-${commit}" |
| 153 | +$ sudo install -o root -g root -m 0640 -D kata-containers.img "/usr/share/kata-containers/${image}" |
| 154 | +$ (cd /usr/share/kata-containers && sudo ln -sf "$image" kata-containers.img) |
| 155 | +``` |
| 156 | + |
| 157 | +# Install guest kernel images |
| 158 | + |
| 159 | +``` |
| 160 | +$ sudo ln -s /usr/share/clear-containers/vmlinux.container /usr/share/kata-containers/ |
| 161 | +$ sudo ln -s /usr/share/clear-containers/vmlinuz.container /usr/share/kata-containers/ |
| 162 | +``` |
| 163 | + |
| 164 | +> **Note:** |
| 165 | +> |
| 166 | +> - The files in the previous commands are from the Clear Containers |
| 167 | +> `linux-container` package. See [Assumptions](#assumptions). |
| 168 | +
|
| 169 | +# Update Docker configuration |
| 170 | + |
| 171 | +``` |
| 172 | +$ dir=/etc/systemd/system/docker.service.d |
| 173 | +$ file="$dir/kata-containers.conf" |
| 174 | +$ sudo mkdir -p "$dir" |
| 175 | +$ sudo test -e "$file" || echo -e "[Service]\nType=simple\nExecStart=\nExecStart=/usr/bin/dockerd -D --default-runtime runc" | sudo tee "$file" |
| 176 | +$ sudo sed -i 's!^\(ExecStart=[^$].*$\)!\1 --add-runtime kata-runtime=/usr/local/bin/kata-runtime!g' "$file" |
| 177 | +$ sudo systemctl daemon-reload |
| 178 | +$ sudo systemctl restart docker |
| 179 | +``` |
| 180 | + |
| 181 | +# Create a Kata Container |
| 182 | + |
| 183 | +``` |
| 184 | +$ sudo docker run -ti --runtime kata-runtime busybox sh |
| 185 | +``` |
| 186 | + |
| 187 | +# Troubleshoot |
| 188 | + |
| 189 | +To perform analysis on Kata logs, use the |
| 190 | +[`kata-log-parser`](https://github.com/kata-containers/tests/tree/master/cmd/log-parser) |
| 191 | +tool. |
| 192 | + |
| 193 | +# Appendices |
| 194 | + |
| 195 | +## Checking Docker default runtime |
| 196 | + |
| 197 | +``` |
| 198 | +$ sudo docker info 2>/dev/null | grep -i "default runtime" | cut -d: -f2- | grep -q runc && echo "SUCCESS" || echo "ERROR: Incorrect default Docker runtime" |
| 199 | +``` |
0 commit comments