Instructions to hack up WSL2 on Windows 10 Build 18917 to run k3s (Kubernetes) and rio
https://docs.microsoft.com/en-us/windows/wsl/wsl2-install
I already had Ubuntu-18.04 installed in wsl 1. So I just did wsl --set-version Ubuntu-18.04 2
Using Ubuntu 18.04 (I'm sure any distro will work), inside WSL2 download https://thirdpartysource.microsoft.com/download/Windows%20Subsystem%20for%20Linux%20v2/May%202019/WSLv2-Linux-Kernel-master.zip and extract to a folder. The latest version of the kernel source is available at (https://github.com/microsoft/WSL2-Linux-Kernel)
In the extracted kernel source run
# Install basically "compile kernel" crap
sudo apt install build-essential flex bison libssl-dev libelf-dev
# Setup kernel config
cp Microsoft/config-wsl .config
cat >> .config << EOF
CONFIG_BRIDGE_NETFILTER=y
CONFIG_NETFILTER_XT_MATCH_COMMENT=y
CONFIG_NETFILTER_XT_MATCH_MULTIPORT=y
CONFIG_NETFILTER_XT_MATCH_OWNER=y
CONFIG_NETFILTER_XT_MATCH_PHYSDEV=y
CONFIG_VXLAN=y
CONFIG_GENEVE=y
EOF
make oldconfig
# Compile and drink beverage of choice
make -j $(nproc)
- Copy
arch/x86/boot/bzImage
to somewhere outside WSL2 (/mnt/c/Users/${USER}/Desktop
) - Shutdown WSL2
wsl --shutdown
- Copy bzImage to
c:\Windows\System32\lxss\tools\kernel
. Make sure you backup the existingkernel
file (although the original is still in another location). I had to copy through explorer.exe because of permissions issues.
You can't install k3s using the curl script because there is no supervisor (systemd or openrc) in WSL2.
- Download k3s binary from https://github.com/rancher/k3s/releases/latest
chmod +x k3s
- Run k3s
sudo ./k3s server
- Copy
/etc/rancher/k3s/k3s.yaml
from WSL to your home in Windows to %HOME%.kube\config. Edit the copied file and change the server URL fromhttps://localhost:6443
to the IP of the your WSL2 instance (ip addr show dev eth0
). So something likehttps://192.168.170.170:6443
. - Run kubectl from windows (got to download kubectl.exe from somewhere)
- Download rio-windows-amd64 from https://github.com/rancher/rio/releases/tag/v0.2.0-rc1 to rio.exe
- Run
./rio install
- Start doing stuff with rio :)
Made a little script to make the install somewhat easier. It creates a brand new wsl2 named liifi-k3s to avoid collisions. It uses the official docker image to create the WSL2 distro
rancher/k3s:v1.0.0
If you run the following on the latest wsl2 enabled windows 10 (make sure you have it set as the default), you should get k3s with rio on it, inside WSL2. It will also add k3s and rio cli using scoop.
Here is a README with more details.
Also, you can point VSCode to //wsl$/liifi-k3s/etc/rancher/k3s/k3s.yaml but there is a caveat (you must first modify the file to use localhost instead of 127.0.0.1, the above script will take care of it)