The WSL needs a Linux distribution to work with it. I am familiar with Ubuntu and therefore choose this distribution. Nevertheless, any other distribution does. It is just a matter of taste.
Prepare the Windows Subsystem for Linux environment
The Windows Subsystem for Linux is available from Windows version 1903. A quick look in the control panel confirms, the Windows at hand is even newer. Next, we go to the Microsoft Store to install Ubunto. The purchase is free and takes a little time. During installation, I enter my user name and the password.
Setting up Ubuntu distribution
Installing, this may take a few minutes... Please create a default UNIX user account. The username does not need to match your Windows username. For more information visit: https://aka.ms/wslusers Enter new UNIX username: markus New password: Retype new password: passwd: password updated successfully Installation successful! To run a command as administrator (user "root"), use "sudo <command>". See "man sudo_root" for details. Welcome to Ubuntu 20.04.2 LTS (GNU/Linux 4.4.0-19041-Microsoft x86_64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/advantage System information as of Sat Mar 13 21:52:15 CET 2021 System load: 0.52 Usage of /home: unknown Memory usage: 53% Swap usage: 0% Processes: 7 Users logged in: 0 IPv4 address for eth1: 172.18.96.1 IPv4 address for wifi0: 192.168.178.86 IPv6 address for wifi0: 2001:16b8:141a:8300:a135:ef72:a79b:d6e6 IPv6 address for wifi0: 2001:16b8:141a:8300:ed76:2ea4:3a0b:205a 1 update can be installed immediately. 0 of these updates are security updates. To see these additional updates run: apt list --upgradable The list of available updates is more than a week old. To check for new updates run: sudo apt update This message is shown once a day. To disable it please create the /home/markus/.hushlogin file. markus@enousia:~$
The list option shows a list of available Linux environments. In consequence, I can see the ubuntu distribution. And two more distributions originated from Docker Desktop.
Verify the new distribution is applicable in WSL
PS C:UsersMarkus> wsl -l Windows-Subsystem für Linux-Distributionen: docker-desktop-data (Standard) docker-desktop Ubuntu-20.04
Set Ubuntu as new default and start distribution
PS C:UsersMarkus> wsl --set-default ubuntu-20.04 PS C:UsersMarkus> wsl Welcome to Ubuntu 20.04.2 LTS (GNU/Linux 5.4.72-microsoft-standard-WSL2 x86_64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/advantage System information as of Sun Mar 14 00:23:25 CET 2021 System load: 0.01 Processes: 11 Usage of /: 0.4% of 250.98GB Users logged in: 0 Memory usage: 1% IPv4 address for eth0: 172.19.254.14 Swap usage: 0% 1 update can be installed immediately. 0 of these updates are security updates. To see these additional updates run: apt list --upgradable The list of available updates is more than a week old. To check for new updates run: sudo apt update This message is shown once a day. To disable it please create the /root/.hushlogin file.
In my case, the default user is the root user. I want WSL to use a non-privileged user. In this way, I configure the Linux distribution to use a different user.
Set non root user as default
PS C:UsersMarkus> ubuntu2004.exe config --default-user markus PS C:UsersMarkus> wsl markus@fuchur:/mnt/c/Users/Markus$
I use Minikube for local experiments. And Minikube was installed by Powershell. In this way, the location for .minikube and .kube configuration files is the Windows user’s home directory. Even so, these paths are not compatible with WSL. Given Linux, a drive letter, a colon, and backslashes are not part of a Unix path. Here I need a separate Linux configuration. Consequently, I copy the files to the Linux user’s home directory and fix the path expressions.
First, we must install the Kubernetes client. For installation, we add the repository to the package manager. Next, the package manager update operation discovers the packages. Finally, the kubectl is known and ready to install.
Install the Kubernetes client
sudo apt-get update && sudo apt-get install -y apt-transport-https curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add - echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee -a /etc/apt/sources.list.d/kubernetes.list sudo apt-get update sudo apt-get install -y kubectl
Fix the Kubernetes client configuration
Up to here, the Kubernetes client does not work. The configuration is still missing. In that way, we copy it from the Windows home directory to ~.
Copy configuration from Windows side to Linux
cp -R /mnt/c/Users/Markus/.kube .kube
Unfortunately, this configuration requires some fixes. The Windows path is not compatible with Linux. In this way, we replace the drive letter and, of course, the backslashes. We edit .kube/config with the vi editor and apply substitutions:
VI substitution patterns
The seamless Linux integration is quite lovely. But in fact, using tools that store their configuration in the user’s home directory becomes confusing. Differences in Windows and Linux paths require much manual synchronization. Under those circumstances, synchronization becomes very challenging. As a result, I recommend working only on one of both sides. Therefore I chose the Linux side. So I use tools like minikube, kubectl, or any of the other tools only here. In this way, there is no need to synchronize configuration files between both worlds.