Kata Containers: When VM Security Meets Container Speed

Virtualization tutorial - IT technology blog
Virtualization tutorial - IT technology blog

Traditional Container Vulnerabilities and Why Kata Containers Was Born

If you’ve been using Docker or K8s for a long time, you probably know that the “Achilles’ heel” of containers is sharing the same kernel with the host machine. Containers start fast and light thanks to this mechanism. However, if a hacker gains control of a container, they can exploit kernel vulnerabilities to perform a “container breakout” attack. From there, the entire server falls into malicious hands.

In my home lab of 12 Proxmox VMs, using LXC is very convenient but always carries risks when running unfamiliar images from Docker Hub. To solve this problem, Kata Containers is my go-to solution. It wraps each container in a lightweight virtual machine (microVM). As a result, applications have their own isolated kernel for security while maintaining the smooth management experience of traditional Docker.

In other words, Kata Containers provides the secure isolation of a VM while retaining the deployment speed of a Container. Here is how I configure it on Linux.

Hardware Prerequisites

Kata Containers requires hardware virtualization. Your server must support VT-x (Intel) or AMD-V (AMD). If you are running Kata inside another VM (such as Proxmox or AWS EC2), remember to enable Nested Virtualization.

Quickly check with the command:

grep -E 'vmx|svm' /proc/cpuinfo

If you see results, your machine is ready. In this article, I’m using Ubuntu 22.04 as the practice environment.

Detailed Installation Steps for Kata Containers

1. Installing the Static Release

There are several ways to install it, but for production stability, I recommend using the static release from GitHub. This method allows precise version control and avoids system library conflicts.

# Define the version (e.g., version 3.2.0)
export KATA_VERSION="3.2.0"
archive_url="https://github.com/kata-containers/kata-containers/releases/download/${KATA_VERSION}/kata-static-${KATA_VERSION}-x86_64.tar.xz"

# Download and extract directly to root
wget ${archive_url}
sudo tar -xvf kata-static-${KATA_VERSION}-x86_64.tar.xz -C /

The system will place the executables in /opt/kata/bin. You need to create symbolic links so Docker can call the commands:

sudo ln -s /opt/kata/bin/kata-runtime /usr/local/bin/kata-runtime
sudo ln -s /opt/kata/bin/containerd-shim-kata-v2 /usr/local/bin/containerd-shim-kata-v2

2. Checking System Compatibility

Don’t rush to run containers just yet. Use the built-in check tool to confirm if your kernel and hardware fully support microVMs:

kata-runtime check

If every line reports success, your system is ready for action.

Integrating Kata Containers with Docker

By default, Docker uses runc as its runtime. To use Kata, we need to declare this runtime in the daemon.json configuration file.

Open the configuration file:

sudo nano /etc/docker/daemon.json

Add the following JSON snippet:

{
  "runtimes": {
    "kata-runtime": {
      "path": "/usr/local/bin/kata-runtime"
    }
  }
}

Restart Docker to apply the settings:

sudo systemctl restart docker

Hands-on Experience: Comparing Kernels

The difference becomes clear when you check the kernel version. Try running an Ubuntu container with the default runtime:

docker run -it --rm ubuntu uname -a

The result will match the host machine’s kernel version.

Now, switch to Kata:

docker run -it --rm --runtime=kata-runtime ubuntu uname -a

At this point, the returned kernel is a minimal version provided by Kata. Your container is now safely residing inside an isolated microVM.

Choosing a Hypervisor: QEMU or Firecracker?

A major strength of Kata is its flexibility in choosing a Hypervisor. QEMU is the default choice, supporting a full range of features and peripherals. However, if you need to optimize for speed, try Firecracker.

Firecracker (developed by AWS) can boot a microVM in less than 150ms. It is extremely resource-efficient but limited in complex disk mounting capabilities. To change it, edit the configuration.toml file at /etc/kata-containers/, find the line hypervisor = "qemu" and change it to firecracker.

Resource and Performance Monitoring

Note that when using Kata, container processes will not appear directly in the host’s top output. Instead, you will see qemu-system-x86_64 or virtiofsd processes managing the memory.

Regarding resources, each Kata Container typically consumes an additional 100MB – 200MB of RAM overhead for the microVM itself. This is a figure to consider when planning server resources. To manage the list of running microVMs, use the command:

kata-runtime list

Conclusion

Kata Containers was not born to replace Docker in every situation. If you are only running trusted internal apps, traditional Docker remains the top choice for performance. But if you are building CI/CD systems, SaaS, or running third-party code, Kata is an indispensable security layer. Good luck with your deployment, and may you sleep better at night!

Share: