# Container runtime In this section, we will focus on the container runtime. ![image](./img/01_cluster_architecture_container_runtime.png "Container runtime") ## runc First of all, since Kubernetes is an orchestrator for containers, we would like to figure out how to run containers. A thing like OCI can help us here. > The OCI is a project under the Linux Foundation is aims to develop open industry standards for container formats and runtimes. The primary goal of OCI is to ensure container portability and interoperability across different platforms and container runtime implementations. The OCI has two main specifications, Runtime Specification (runtime-spec) and Image Specification (image-spec). As we can see from the description - OCI is a standard that tells us what is a container image and how to run it. But it is only a standard, obviously, there is some tool that implements this standard. And it is true, runc is a reference implementation of the OCI runtime specification. So let's install it and run some container with the usage of runc First of all we need to download runc binaries ```bash wget -q --show-progress --https-only --timestamping \ https://github.com/opencontainers/runc/releases/download/v1.2.6/runc.amd64 ``` After the download process is complete, we need to move runc binaries to proper folder ```bash mv runc.amd64 runc \ && chmod +x runc \ && mv runc /usr/local/bin/ ``` Now, as we have runc configured, we can run busybox container ```bash mkdir -p busybox-container/rootfs/bin \ && cd busybox-container/rootfs/bin \ && wget https://www.busybox.net/downloads/binaries/1.31.0-defconfig-multiarch-musl/busybox-x86_64 \ && chmod +x busybox-x86_64 \ && ./busybox-x86_64 --install . \ && cd ./../.. \ && runc spec \ && sed -i 's/"sh"/"echo","Hello from container runned by runc!","sleep","3600"/' config.json ``` In this step, we downloaded the busybox image, unarchived it, and created the proper files, required by runc to run the container (including container configuration and files that will be accessible from the container). So, let's run our container ```bash runc run busybox ``` Output: ``` Hello from container runned by runc! ``` Great, we created our first container in this tutorial. Now we will clean up our workspace. ```bash cd .. \ && rm -r busybox-container ``` ## containerd As we can see, runc can run containers, but runc interface is something unknown for kubernetes. There is another standard defined which is used by kubelet to communicate with container runtime - CRI > The CRI is a plugin interface which enables the kubelet to use a wide variety of container runtimes, without having a need to recompile the cluster components. In this tutorial, we will use [containerd](https://github.com/containerd/containerd) as a tool which is compattible with CRI. To deploy containerd, first of all, we need to download it. ```bash wget https://github.com/containerd/containerd/releases/download/v2.0.4/containerd-2.0.4-linux-amd64.tar.gz ``` After download process complete, we need to unzip and move containerd binaries to proper folder ```bash mkdir containerd \ && tar -xvf containerd-2.0.4-linux-amd64.tar.gz -C containerd \ && mv containerd/bin/* /bin/ ``` In comparison to the runc, containerd is a service that works like a service that can be called by someone to run a container. It means that we need to run it before we can start communicating with it. We will configure containerd as a service. To do that, we need to create containerd configuration file ```bash { mkdir -p /etc/containerd/ cat << EOF | tee /etc/containerd/config.toml [debug] level = "debug" [plugins] [plugins.'io.containerd.cri.v1.images'] snapshotter = "native" [plugins."io.containerd.cri.v1.runtime"] [plugins."io.containerd.cri.v1.runtime".containerd] default_runtime_name = "runc" [plugins."io.containerd.cri.v1.runtime".containerd.runtimes] [plugins."io.containerd.cri.v1.runtime".containerd.runtimes.runc] runtime_type = "io.containerd.runc.v2" snapshotter = "native" [plugins."io.containerd.cri.v1.runtime".containerd.runtimes.runc.options] BinaryName = "/usr/local/bin/runc" EOF } ``` As we can see, we configured containerd to use runc (we installed before) to run containers. After configuration file create, we need to create containerd service ```bash cat <