This documentation is to have configure a WSL2 Debian 11 image with microk8s installed on the image. This is based on the standard Debian 11 image configured with basic tools like Oh-my-ZSH etc.
I decided to create a separate image simply not to have any conflict with other flavours of K8s. Microk8s uses snap package and I read somewhere that one of the flavours(I think it was Kind) does not like snap. Maybe those issues are solved, but I already had issues with Kind installtion, so lets continue to have a isolation. Afterall all this containerization is about isolation, right?
The documentation says that it has a very low memory footprint. This is cool as it should help keep some resources free on my laptop.
It was also the image mentioned in one of the Microsoft Tutorails that I followed to learn K8s.
Additionally, it does not seems to need docker to run it. At the moment, I have issues with Kind and Minikube clusters as clusters nodes cannot reach docker repository, even though all other internet sites are accessible! So, it might help me to get going with actual cluster tasks rather than figuring out why I cannot reach docker repository.
Execute below commands to create starting WSL image to develop Microk8s WSL2 image
wsl --import deb11mk8s .\wsl\deb11_mk8s\ .\wsl_backup\deb11_base.tar
One must change name of images and paths based on the specific setup.
Debian uses apt as package manager by default. For some reason MicroK8s is distributed only through SNAP and not by apt. Install SNAP for your distribution using relevant instructions.
-
Install SNAP
sudo apt update sudo apt install snapd
-
Logout and login to the session again
-
Install snap core
$sudo snap install core error: cannot communicate with server: Post "http://localhost/v2/snaps/core": dial unix /run/snapd.socket: connect: no such file or directory
There are many issues raised regarding this. One jsut need to make a simple google search. Different workarounds are proposed with scripts, custom kernels and various package and start scripts
This is way too geeky for my liking. especially now that it also involves being specific to shell and its related script e.g. bash vs zsh! Thankfully I found other articles, that explained similar scripts with proper details
sudo apt remove snapd
3 years since a workaround was developed and yet, no standard solution for WSL2. Below is the article chain that I happend to come across and tried.
-
Deploy MicroK8s on WSL2 by JakeVis. Published 2021
-
It is further based on WSL2 _Microk8s by Nunix which is further based on - published in 2020
-
Running SNAPs on WSL2 - Insiders only for now - published in 2019.
-
This in turn is now abandoned and has been moved to a script maintained at ubuntu wsl2 systemd script
-
I also found an ansible automated script. I did not use because I wanted to have atleast some understanding of what is happening in all those changes.
-
Install required packages for SystemD
sudo apt install -yqq fontconfig daemonize
-
Check ids of user and groups
$id uid=1000(arundeep) gid=1000(arundeep) groups=1000(arundeep),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev)
-
Update
/etc/wsl.conf
with below content. make sure to use Ids from the command above and username is your username. I commented out some entries below as there are default. Also commented out crossDistro as per remark in github 4577 in Sept 2020!. I don't know if other options are also useless/changed now!![automount] #enabled = true # default true options = "metadata,umask=22,fmask=11" #"uid=1000,gid=1000,case=off" these are default #mountFsTab = true # is default true #crossDistro = true [network] generateHosts = false #generateResolvConf = true # default true [interop] #enabled = true # default true #appendWindowsPath = true # default true
-
Create starting script for SystemD
/etc/profile.d/00-wsl2-systemd.sh
. For some reason this script looks much simpler than what the automated script contains. let's see how it goes. Maybe, I would have to use automated script afterallSYSTEMD_PID=$(ps -ef | grep '/lib/systemd/systemd --system-unit=basic.target$' | 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 --system-unit=basic.target SYSTEMD_PID=$(ps -ef | grep '/lib/systemd/systemd --system-unit=basic.target$' | grep -v unshare | awk '{print $2}') fi if [ -n "$SYSTEMD_PID" ] && [ "$SYSTEMD_PID" != "1" ]; then exec sudo /usr/bin/nsenter -t $SYSTEMD_PID -a su - $LOGNAME fi
-
Setup netowork forwarding. Automated script does not set this up
echo 'net.ipv4.conf.all.route_localnet = 1' | sudo tee -a /etc/sysctl.conf sudo sysctl -p /etc/sysctl.conf
-
Restart WSL
-
Install
snap
sudo apt install snapd -y
-
check snap. Fails!!
$snap version snap 2.49-1+deb11u1 snapd unavailable series - $snap list error: cannot list snaps: cannot communicate with server: Get "http://localhost/v2/snaps": dial unix /run/snapd.socket: connect: no such file or directory
-
Clean up above steps
- Remove snap
- remove ip4 forwarding from
/etc/sysctl.conf
- remove
/etc/profile.d/00-wsl2-systemd.sh
file - revert back changes to
/etc/wsl.conf
- remove
fontconfig
anddaemonize
-
Execute below command as per the ansible script github
curl -sf -L https://gist.github.com/ct27stf/77582676a42e2f409ccd227773393623/raw/SetupMicroK8s.sh | sh
That's where I stop! The other script is also setting up some variables in Windows, which I am not sure if apply to all Distros or is there a way to isolate it to a particular WSL distro. As I have other WSL distros running in parallel, I stopped this pursuit. I might try to do that in a VirtualBox VM later!!