Deploying Microk8s on WSL2

I am running Windows 11, and have enabled WSL2 with Ubuntu via the standard GUI methods (install Ubuntu from the Microsoft Store). However, all credit goes to for the technicals here.

Install Fonts, and set as default for WSL

Seems stupid.. but yes, for things to look ok and everything to render install these:

Once downloaded, double click, install.

Right click on your WSL window, select properties, fonts and set it to Cascadia Mono PL.


Enable SystemD

Install required software (a different user is not required)

apt install -yqq fontconfig daemonize

Create the wsl.conf file

sudo vi /etc/wsl.conf and add this content. Make sure you change the default user to your username (jake for me). Also run id first to make sure 1000 is the correct uid/gid. Exit vi with wq

enabled = true
options = "metadata,uid=1000,gid=1000,umask=22,fmask=11,case=off"
mountFsTab = true
crossDistro = true

generateHosts = false
generateResolvConf = true

enabled = true
appendWindowsPath = true

default = jake

Create the SystemD startup script

vi /etc/profile.d/ And add:

SYSTEMD_PID=$(ps -ef | grep '/lib/systemd/systemd$' | grep -v unshare | awk '{print $2}')

if [ -z "$SYSTEMD_PID" ]; then
   sudo /usr/bin/daemonize /usr/bin/unshare --fork --pid --mount-proc /lib/systemd/systemd
   SYSTEMD_PID=$(ps -ef | grep '/lib/systemd/systemd$' | grep -v unshare | awk '{print $2}')

if [ -n "$SYSTEMD_PID" ] && [ "$SYSTEMD_PID" != "1" ]; then
    exec sudo /usr/bin/nsenter -t $SYSTEMD_PID -a su - $LOGNAME

Optional: set NOPASSWD for sudo

sudo vi /etc/sudoers

Edit line: %sudo ALL=(ALL:ALL) :ALL to read: %sudo ALL=(ALL:ALL) NOPASSWD:ALL (and exit vi with !wq)

Setup forwarding

echo 'net.ipv4.conf.all.route_localnet = 1' | sudo tee -a /etc/sysctl.conf
sudo sysctl -p /etc/sysctl.conf

Restart WSL

From an elevated Powershell terminal

wsl --shutdown

That should close your linux window..

Install Microk8s

You should now be able to execute snap

snap list

check versions:

snap info microk8s

and install latest:

sudo snap install microk8s --classic

After its complete - check its all running:

sudo microk8s.status
sudo microk8s.kubectl version
sudo microk8s.kubectl cluster-info