Using WSL and Lens

If you have a Windows system with WSL installed and have set up access to a public cloud for connecting to your clusters via kubectl this means you probably have installed the necessary cloud cli tools (such as aws or gcloud) via WSL (on Ubuntu say). So from Ubuntu you can run kubectl commands to access your clusters. You will also want to access your clusters using Lens, and you might be tempted to install and run the Windows version of Lens to do this. However, Lens relies on the same kubeconfig that kubectl uses to access your clusters. This kubeconfig likely references some of the cloud tools that you installed on Ubuntu under WSL. The Windows version of Lens will not be able to access your clusters using the kubeconfig set up in WSL unless you do the same cloud setup in Windows that you did in WSL. But you probably did the cloud set up under WSL because you didn’t want to (or couldn’t) set it up under Windows. One solution is to install the linux version of Lens under WSL.

WSL2 comes with support for GUI apps, and you can confirm this by following this step of this link. The link actually shows how to install WSL and Ubuntu and verify that GUI apps work.

To activate Lens you will need to download an activation token, if your Lens account supports it, or activate via the browser. For the latter you must have a browser installed in your WSL2 setup. Note that if you use the port-forwarding feature in Lens you will also need a browser installed in WSL2. If you don’t already have one under WSL2 there are many options available. One way is to set up chrome on Ubuntu as described here. Once installed, run the browser and make it the default so that Lens will use it for activation and port-forwarding.

The next step is to install Lens. On WSL2 there are a few linux options. To benefit from auto-updates you can download the AppImage version of Lens. First, AppImages require FUSE version 2 to run, follow the instructions here.

Next, install the Lens AppImage according to these instructions (use the WSL2 installed browser to view the instructions and download the AppImage file). Use the chmod instructions to make the file executable, ignore the file manager steps. To start Lens just type the path to the file. For example, in the directory where you downloaded it, enter:

./Lens-2023.5.310801-latest.x86_64.AppImage

The file name is different depending on what version you downloaded.

Alternatively, you can install the repository version of Lens. On Ubuntu first install some required dependencies:

sudo apt update
sudo apt install -y libgbm-dev libasound2

Then follow the instructions here

1 Like

Actually, that’s possible. You just need to create “symlink” from your WSL home dir in your Windows user profile dir.

I think I used (but it may need some tweaks) this command:

export WIN_HOME=`wslpath $(powershell.exe -c "Write-Host \\$env:USERPROFILE")`
ln -sf $WIN_HOME/.kube ~/.kube

I use Lens on Windows with WSL in this way.

Thanks, that’s good to know. That will enable the Windows version of Lens to see clusters (contexts) that were set up in wsl. And you should be able to connect to clusters that have readable authentication data (for the cluster context’s given user). However, if the user authentication requires executing a command, such as with some public cloud configurations, the Windows version of Lens will fail to connect to the cluster unless that command is installed in Windows. For example, a typical user: specification may have an exec: section like this:

  user:
    exec:
      apiVersion: client.authentication.k8s.io/v1beta1
      args:
      - --region
      - us-west-2
      - eks
      - get-token
      - --cluster-name
      - my-cluster
      command: aws

In this case if aws was installed in wsl but not on Windows then the Windows version of Lens will fail to execute aws and thus fail to connect to the cluster my-cluster.

Maybe there’s a way to get wsl aws to work via the Windows version of Lens? Without modifying the kubeconfig?

Yes, I run aws auth in WSL and then I have “symlink” for .aws folder:

ln -sf $WIN_HOME/.aws ~/.aws