Compiling your own WSL2 Kernel for Cilium

Photo by Tadas Sar / Unsplash

Recently I joined Isovalent as a Senior Solution Architect (yay!) and wanted to play with their CNI, Cilium, on my laptop with Kubernetes-in-Docker (KinD). I run Windows 11 with WSL2 (Ubuntu 20.04), where all my code-related stuff happens.

Right away I ran into Linux kernel issues, as Cilium needs some Netfliter things enabled to work in the kernel, which are not enabled by default. Luckily Microsoft makes it pretty easy to compile your own kernel image for WSL2. At the time of this post, these steps worked on the latest kernel image, version

The steps are:

  1. Run a Docker container to build the image
  2. Copy the image out of the container to C:\Users\youruser
  3. Tell WSL to use your new custom kernel image

Run a Docker container to build the image

Open up a PowerShell terminal:

docker run --name wsl-kernel-builder --rm -it [email protected]:9d6a8699fb5c9c39cf08a0871bd6219f0400981c570894cd8cbea30d3424a31f bash

from inside the container (now bash):

apt update && apt install -y git build-essential flex bison libssl-dev libelf-dev bc

mkdir src
cd src
git init
git remote add origin
git config --local 0
git -c protocol.version=2 fetch --no-tags --prune --progress --no-recurse-submodules --depth=1 origin +${WSL_COMMIT_REF}:refs/remotes/origin/build/linux-msft-wsl-5.10.y
git checkout --progress --force -B build/linux-msft-wsl-5.10.y refs/remotes/origin/build/linux-msft-wsl-5.10.y

# adds support for clientIP-based session affinity

# required modules for Cilium
sed -i 's/# CONFIG_NETFILTER_XT_TARGET_CT is not set/CONFIG_NETFILTER_XT_TARGET_CT=y/' Microsoft/config-wsl

# build the kernel
make -j2 KCONFIG_CONFIG=Microsoft/config-wsl

Copy the image out of the container

Open up a new PowerShell terminal:

docker cp wsl-kernel-builder:/src/arch/x86/boot/bzImage .

This should put it in your %UserProfile% directory (C:\Users\youruser). You can exit out of the first container and delete it now. We're done with that.

Tell Windows Subsystem for Linux to use your kernel

Edit C:\Users\something\.wslconfig


Keep the double slashes. Shut down WSL (in PowerShell: wsl --shutdown) and restart Docker Desktop. From there restart everything, start up KinD and install Cilium like the install instructions say. Hooray!

NOTE: this worked for me to install the open source version of Cilium. I'm still working on installing Cilium Enterprise, a product of Isovalent, in a WSL-based KinD cluster. Also of note, none of this is supported by Isovalent or me or anyone.

Credit goes to the TKG Community Edition team for easy-to-follow Windows Subsystem for Linux kernel instructions. Those are here and obviously I cribbed it all for this.

Hart Hoover

Hart Hoover

Hi! I'm Hart and I work as a Sr. Solution Architect at Isovalent. I enjoy cloud and container technologies, puffy tacos, and the first cup of coffee in the morning.
San Antonio, TX