Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terminal : Support for Windows Subsystem for Linux #179

Closed
fjudith opened this issue Mar 31, 2020 · 55 comments
Closed

Terminal : Support for Windows Subsystem for Linux #179

fjudith opened this issue Mar 31, 2020 · 55 comments
Labels
enhancement New feature or request

Comments

@fjudith
Copy link

fjudith commented Mar 31, 2020

What would you like to be added:

Add an option in the Preference page allowing to select the shell used by the terminal similarly to Visual Studio Code.

Why is this needed:

Windows Subsystem for Linux is commonly used by Kubernetes administrator running on Windows. Today Lens seems to only support Git Bash

Environment you are Lens application on:

  • Kubernetes distribution: Any
  • Desktop OS: Windows
@fjudith fjudith added the enhancement New feature or request label Mar 31, 2020
@RobertDiPaolo
Copy link

I've found lens to be a breath of fresh air after struggling with the kubernetes dashboard for some time. The UX is excellent and the UI very fast, etc, kudos to all involved. Being able to use the WSL terminal as well would mean I could do all k8s admin in a single app.

Also when connecting to AWS EKS clusters, the aws cli needs to be invoked to verify iam credentials. Running those commands in WSL would also be helpful, as I don't normally install all the aws tools in windows (though can work around that).

@LaysDragon
Copy link

LaysDragon commented Oct 19, 2020

Since I need to use some kubectl plugin only available under Linux, so I bump into this issue too. I trying to figure out if I can solve problem manually and have some conclusion.

  1. the env of KUBECONFIG won't pass directly into wsl2 bash

Evening I manually enter bash shell in Lens Terminal. The KUBECONFIG env won't pass directly to bash. I have trying to fix the env problem though WSLENV to share the KUBECONFIG to WSL2 bash.

set WSLENV=KUBECONFIG/pu
  1. wsl2 network problem

Now, another problem is that in WSL2 cannot access to windows localhost network directly. So kubectl will simply get rejected on 127.0.0.1 address since there is no service listening in WSL2.
At least I can set up script in .bashrc to auto fetch host's ip and replace it in kube config. I trying to do some test, fetch the host's ip. Then replace the ip in the kube config manually. It actually work.

  1. Lens security restriction

Then I head into next problem is that looks like lens create a localhost api proxy for it own terminal and restrict to local access only. But as WSL2 environment is a virtual machine have it own ip, so kubectl can only get the default response From lens still failed.

I1020 00:23:57.265435    5900 round_trippers.go:420] GET http://172.23.208.1:53937/02f71990-ec55-4309-9aa0-45d731dcf08e/api?timeout=32s
I1020 00:23:57.266435    5900 round_trippers.go:427] Request Headers:
I1020 00:23:57.266435    5900 round_trippers.go:431]     Accept: application/json, */*
I1020 00:23:57.266435    5900 round_trippers.go:431]     User-Agent: kubectl/v1.17.11 (windows/amd64) kubernetes/ea5f00d
I1020 00:23:57.269436    5900 round_trippers.go:446] Response Status: 200 OK in 3 milliseconds
I1020 00:23:57.269436    5900 round_trippers.go:449] Response Headers:
I1020 00:23:57.269436    5900 round_trippers.go:452]     Content-Type: text/html
I1020 00:23:57.269436    5900 round_trippers.go:452]     Date: Mon, 19 Oct 2020 16:23:57 GMT
I1020 00:23:57.270436    5900 round_trippers.go:452]     Connection: keep-alive
I1020 00:23:57.270436    5900 request.go:1017] Response Body: <!doctype html><html lang="en"><head><meta charset="UTF-8"><title>Lens - The Kubernetes IDE</title><link href="/build/Lens.css" rel="stylesheet"></head><body><div id="app"></div>
<script src="/build/Lens.js"></script></body></html>
I1020 00:23:57.271435    5900 cached_discovery.go:121] skipped caching discovery info due to couldn't get version/kind; json parse error: json: cannot unmarshal string into Go value of type struct { APIVersion string "json:\"apiVersion,omit
empty\""; Kind string "json:\"kind,omitempty\"" }
F1020 00:23:57.272435    5900 helpers.go:114] error: couldn't get version/kind; json parse error: json: cannot unmarshal string into Go value of type struct { APIVersion string "json:\"apiVersion,omitempty\""; Kind string "json:\"kind,omite
mpty\"" }

Lens have no option to remove or add ip white list to its proxy server, so it still head into another dead end. Unless I setup another port forwarding to pass though such problem, but it still inconvenience.

For support WSL2 in Lens I guess we need to implement these function:

  1. Auto fetch real Host ip in WSL2 to setup specified kubeconfig for WSL2
  2. Auto fetch WSL2's virtual IP to setup IP whitelist in Lens's API proxy server
  3. Setup specified KUBECONFIG for WSL2

@jasonnance
Copy link

I got this working by running Lens in my WSL2 Ubuntu distro with the AppImage release (snap install didn't work) and using X11 forwarding (VcXsrv) to show the app in my Windows desktop. There are a bunch of guides lying around for using X11 forwarding to access Linux GUI apps on your Windows host -- here's an example: https://stackoverflow.com/questions/61110603/how-to-set-up-working-x11-forwarding-on-wsl2

Seems to be working fine, and as a bonus, it used the AWS CLI in my Ubuntu distro to authenticate to my EKS cluster out of the box.

@LaysDragon
Copy link

I got this working by running Lens in my WSL2 Ubuntu distro with the AppImage release (snap install didn't work) and using X11 forwarding (VcXsrv) to show the app in my Windows desktop. There are a bunch of guides lying around for using X11 forwarding to access Linux GUI apps on your Windows host -- here's an example: https://stackoverflow.com/questions/61110603/how-to-set-up-working-x11-forwarding-on-wsl2

Seems to be working fine, and as a bonus, it used the AWS CLI in my Ubuntu distro to authenticate to my EKS cluster out of the box.

That sounds really crazy to use WSL as ubuntu desktop, too bad most of my work still done on windows side, this is not suitable for my situation, but still kind of interesting.

@xrubick
Copy link

xrubick commented Apr 18, 2021

I got this working by running Lens in my WSL2 Ubuntu distro with the AppImage release (snap install didn't work) and using X11 forwarding (VcXsrv) to show the app in my Windows desktop. There are a bunch of guides lying around for using X11 forwarding to access Linux GUI apps on your Windows host -- here's an example: https://stackoverflow.com/questions/61110603/how-to-set-up-working-x11-forwarding-on-wsl2

Seems to be working fine, and as a bonus, it used the AWS CLI in my Ubuntu distro to authenticate to my EKS cluster out of the box.

emmm,It can't work by running Lens in my WSL,and got some desc:
$ kontena-lens
Failed to move to new namespace: PID namespaces supported, Network namespace supported, but failed: errno = Permission denied
[1] 648 trace trap (core dumped) kontena-lens
$ sudo kontena-lens
[660:0418/110114.492723:FATAL:electron_main_delegate.cc(254)] Running as root without --no-sandbox is not supported. .
[1] 659 trace trap (core dumped) sudo kontena-lens

Help,pls!

@vildek
Copy link

vildek commented Apr 30, 2021

Found a way to run Lens with WSL1. Automatic context switching and access to pod shell also works. To do that, you need to install WSL manually.

  1. Download wsl appx file for your favorite OS (i use Ubuntu18.04) - https://docs.microsoft.com/en-us/windows/wsl/install-manual
  2. Extract the appx with 7zip, go inside the extracted directory and run the installation, in my case Ubuntu1804.exe. Once you configure wsl, download kubectl, install it as in regular linux os - https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/#install-kubectl-binary-with-curl-on-linux
  3. Run Lens, go File>Preferences and set Terminal shell - C:\Users<User>\Documents\UbuntuWSL\ubuntu1804.exe
  4. Have fun

@black-snow
Copy link

All my thumbs for this one. I know PS can be great once you get to know it but all my tooling lives inside the WSL.

@nevalla
Copy link
Contributor

nevalla commented Jul 2, 2021

Seems that WSL is supported on terminal, so closing this now. Please re-open if you still find this an issue.

@nevalla nevalla closed this as completed Jul 2, 2021
@LaysDragon
Copy link

LaysDragon commented Jul 2, 2021

@nevalla So Lens still not directly support WSL? Right? vildek's method can only work on WSL1 with manually configured…

@black-snow
Copy link

@nevalla Hi, what do you mean by that? What terminal?

@nevalla
Copy link
Contributor

nevalla commented Jul 3, 2021

Maybe I've understood the issue wrong, but if I set Terminal Shell Path, for example, as wsl.exe in App settings:
image

Then install manually kubectl binary on Ubuntu box.

Lens opens then wsl on embedded terminal and I'm able to use kubectl there as well:
image

@LaysDragon
Copy link

LaysDragon commented Jul 3, 2021

@nevalla hmmmm until you post the screenshot, I didn't realized that Lens have already release the 5.0.0 version several day ago(I didn't received the 5.0.0 update notification on 4.x latest version), We finally can set the terminal we want. So I upgrade and test it. The KUBECONFIG env automated pass in wsl2 bash looks good.
But there is still a problem after I try, as I known lens seems use a proxy to deal with connection ,but WSL2's network structure
still make it can't access host's service directly. Did I miss something?
image

@nevalla
Copy link
Contributor

nevalla commented Jul 3, 2021

Alright, it seems that this is issue on WSL (found multiple open issues). You can try to run wsl --shutdown on PowerShell and then open Lens terminal.

@LaysDragon
Copy link

LaysDragon commented Jul 3, 2021

That didn't work. :(
It is the problem about how network work under WSL2. It seems won't be the problem under WSL1,I didn't test it. But as I known
that WSL2 is a virtual machine and bridge the network to the windows host, so it can't directly access localhost service under windows like WSL1. microsoft/WSL#4619 (comment)
It need to do serval tweak on the KUBECONFIG env and proxy server to configure the right ip under wsl2 environment. I feeling that there might have confusion between wsl1 and wsl2 here.

@nevalla
Copy link
Contributor

nevalla commented Jul 3, 2021

Someone hinted that disabling Fast Start-Up might fix the issue but I haven't tested this since I'm able to connect fine.

https://stephenreescarter.net/wsl2-network-issues-and-win-10-fast-start-up/

@LaysDragon
Copy link

That post it talking about the problem that windows can't access WSL2's service directly via localhost. That is the opposite of the situation here.(windows can accesss wsl2 service directly via localhost)(Here is wsl2 kubectl need to access the Lens's proxy service on windows side from WSL2). I'm wondering what version of you wsl versrion? if you are in WSL1 then it makes sense 🤔

@LaysDragon
Copy link

LaysDragon commented Jul 6, 2021

Ok,I have to point out that it just still not support WSL2 as terminal directly with kubectl due to network structure of WSL2,not WSL1. 😐 This issue should reopen.

@MartinGolding515
Copy link

wsl.exe as terminal works for the terminal window. However, as other have said, when using the pod shell command it shows windows folders and it is not possible to get to the container's folder structure

@WLun001
Copy link

WLun001 commented Aug 10, 2021

Please support WSL 2

Getting Connecting ... when configure with WSL 2

@Ajay250496
Copy link

Ajay250496 commented Aug 16, 2021

Maybe I've understood the issue wrong, but if I set Terminal Shell Path, for example, as wsl.exe in App settings:
image

Then install manually kubectl binary on Ubuntu box.

Lens opens then wsl on embedded terminal and I'm able to use kubectl there as well:
image

So I have two clusters. I set my terminal as wsl.exe and configure my kubeconfig like below. One of my clusters work perfectly fine, while the other shows "Invalid Credentials". Looking through the logs show "401: Unauthorized" however I have this exact config (other than the wsl in the command section) working on that same bash with no issue. Even have it working on another VM. Trying to find more verbose logs but doesnt seem to provide more info on that. Any idea what I can check to fix this? I think even more verbose logs can help solve it. Tried DEBUG=TRUE after lens.exe but no difference

Error
image

�[31merror�[39m: Failed to connect cluster "cluster-1": StatusCodeError: 401 - {"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"Unauthorized","reason":"Unauthorized","code":401}

Config

clusters:
- cluster:
    certificate-authority-data: very long base64 output
    server: super secret endpoint
  name: cluster-1
- cluster:
    certificate-authority-data: very long base64 output
    server: suprt secret endpoint
  name: cluster-2
contexts:
- context:
    cluster: cluster-2
    user: cluster-2
  name: sssp-staging
- context:
    cluster: cluster-1
    user: cluster-1
  name: sssp-prod
current-context: sssp-prod
kind: Config
preferences: {}
users:
- name: cluster-1
  user:
    exec:
      apiVersion: client.authentication.k8s.io/v1alpha1
      args:
      - aws
      - eks
      - get-token
      - --region
      - ca-central-1
      - --cluster-name
      - sssp-prod
      command: wsl
      env:
      - name: AWS_PROFILE
        value: production
- name: cluster-2
  user:
    exec:
      apiVersion: client.authentication.k8s.io/v1alpha1
      args:
      - aws
      - eks
      - get-token
      - --region
      - ca-central-1
      - --cluster-name
      - sssp-staging-eks
      command: wsl
      env:
      - name: AWS_PROFILE
        value: staging

EDIT

Realized this is due to the AWS_PROFILE variable. It was using the credentials in the "default" profile. Unsure what to do to fix this. I've tried passing environment variables with WSLENV and setting AWS_DEFAULT_PROFILE in kubeconfig.

@davekats
Copy link

davekats commented Aug 17, 2021

Maybe I've understood the issue wrong, but if I set Terminal Shell Path, for example, as wsl.exe in App settings:
image

Then install manually kubectl binary on Ubuntu box.

Lens opens then wsl on embedded terminal and I'm able to use kubectl there as well:
image

@nevalla I am new to Lens and I'm trying to get the program set up by adding clusters from my WSL2 kubeconfig file. I set the terminal shell path to wsl.exe as you showed, but it doesn't seem to be working. In the "Add clusters from kubeconfig" screen it gives me an error User Exec command "aws" not found on host which makes me think that it is still trying to look on Windows for running the command instead of using WSL2.

@jvandervelden
Copy link

Maybe I've understood the issue wrong, but if I set Terminal Shell Path, for example, as wsl.exe in App settings:
image
Then install manually kubectl binary on Ubuntu box.
Lens opens then wsl on embedded terminal and I'm able to use kubectl there as well:
image

@nevalla I am new to Lens and I'm trying to get the program set up by adding clusters from my WSL2 kubeconfig file. I set the terminal shell path to wsl.exe as you showed, but it doesn't seem to be working. In the "Add clusters from kubeconfig" screen it gives me an error User Exec command "aws" not found on host which makes me think that it is still trying to look on Windows for running the command instead of using WSL2.

I too am seeing this except with gcp's gcloud:

error executing access token command "/usr/lib/google-cloud-sdk/bin/gcloud config config-helper --format=json": err=exec: "/usr/lib/google-cloud-sdk/bin/gcloud": file does not exist output= stderr=

My preferences -> terminal is wsl.exe

@jvandervelden
Copy link

This is very naïve but it seems like the auth proxy here: https://github.com/lensapp/lens/blob/master/src/main/kube-auth-proxy.ts#L89 needs to be spawned within the context of the specified terminal preferences. Likely will cause other issues with the kubectl location since I noticed it's always using a bundled version. Maybe adding a preference to use the installed kubectl rather than bundled.

@XFNeo
Copy link

XFNeo commented Oct 26, 2021

  1. wsl2 network problem

Now, another problem is that in WSL2 cannot access to windows localhost network directly. So kubectl will simply get rejected on 127.0.0.1 address since there is no service listening in WSL2. At least I can set up script in .bashrc to auto fetch host's ip and replace it in kube config. I trying to do some test, fetch the host's ip. Then replace the ip in the kube config manually. It actually work.

I have wrote the script to replace the IP

if [ -n "${KUBECONFIG}" ] && grep -q "user: proxy" < "${KUBECONFIG}"; then
  WSL_WINDOWS_HOST=$(grep nameserver < /etc/resolv.conf | cut -d ' ' -f 2)
  sed -i "s/127.0.0.1/${WSL_WINDOWS_HOST}/" "$KUBECONFIG"
fi

And it is still not working because my windows host listening port on 127.0.0.1 and I cant connect through wsl network.
@LaysDragon how did you manage to get this to work?

@LaysDragon
Copy link

LaysDragon commented Oct 26, 2021

  1. wsl2 network problem

Now, another problem is that in WSL2 cannot access to windows localhost network directly. So kubectl will simply get rejected on 127.0.0.1 address since there is no service listening in WSL2. At least I can set up script in .bashrc to auto fetch host's ip and replace it in kube config. I trying to do some test, fetch the host's ip. Then replace the ip in the kube config manually. It actually work.

I have wrote the script to replace the IP

if [ -n "${KUBECONFIG}" ] && grep -q "user: proxy" < "${KUBECONFIG}"; then
  WSL_WINDOWS_HOST=$(grep nameserver < /etc/resolv.conf | cut -d ' ' -f 2)
  sed -i "s/127.0.0.1/${WSL_WINDOWS_HOST}/" "$KUBECONFIG"
fi

And it is still not working because my windows host listening port on 127.0.0.1 and I cant connect through wsl network. @LaysDragon how did you manage to get this to work?

ohhh I didn't make it clear,I mean I can get the right ip of the host. The next line is about I also bump into this problem. :(
Unless we setup another a port forwarding to allow access connection from wsl. But its just too troublesome. :(

@davekats
Copy link

Now that Windows 11 is released, I was able to run Lens from WSL2 and see the GUI. You can follow this guide to get it set up: https://docs.microsoft.com/en-us/windows/wsl/tutorials/gui-apps

@LaysDragon
Copy link

LaysDragon commented Oct 26, 2021

yeah but windows 11 still need some time to go. its still good to have a alternative way to use lens. at least it more easy to use gui app in wsl2 on windows 11 then now.

@XFNeo
Copy link

XFNeo commented Oct 26, 2021

@nevalla Please reopen ticket to fix issue with wsl2
#4224

@jc-roman
Copy link

jc-roman commented Jan 17, 2022

I made it work with wsl.exe by configuring the "path of the kubectl binary" to the wsl path of the kubectl.exe included with Lens installed on Windows. How-to:

  1. In the 'Application' tab, set the Terminal Shell Path to wsl.exe
    image

2, In the Kubernetes Tab, disable 'Kubectl Binary Download'
image

  1. Take note of the kubectl.exe path in Lens. Usually:
    C:\Users\my-user\AppData\Local\Programs\Lens\resources\x64\kubectl.exe
    and translate from a Windows path to a WSL path. From a wsl terminal you can use wslpath :
# The Windows path should be within quotes

$ wslpath "C:\Users\my-user\AppData\Local\Programs\Lens\resources\x64\kubectl.exe"
/mnt/c/Users/my-user/AppData/Local/Programs/Lens/resources/x64/kubectl.exe
  1. Copy the WSL path you got from the previous step and paste it in Lens at 'Path to kubecl Binary'
    image

The terminal, port-forwarding or exec'ing into containers now work without issues for me.

@pduchnovsky
Copy link

I made it work with wsl.exe by configuring the "path of the kubectl binary" to the wsl path of the kubectl.exe included with Lens installed on Windows. How-to:

  1. In the 'Application' tab, set the Terminal Shell Path to wsl.exe
    image

2, In the Kubernetes Tab, disable 'Kubectl Binary Download' image

  1. Take note of the kubectl.exe path in Lens. Usually:
    C:\Users\my-user\AppData\Local\Programs\Lens\resources\x64\kubectl.exe
    and translate from a Windows path to a WSL path. From a wsl terminal you can use wslpath :
# The Windows path should be within quotes

$ wslpath "C:\Users\my-user\AppData\Local\Programs\Lens\resources\x64\kubectl.exe"
/mnt/c/Users/my-user/AppData/Local/Programs/Lens/resources/x64/kubectl.exe
  1. Copy the WSL path you got from the previous step and paste it in Lens at 'Path to kubecl Binary'
    image

The terminal, port-forwarding or exec'ing into containers now work without issues for me.

This gives me:
image

@Bafff
Copy link

Bafff commented Jan 27, 2022

@jc-roman

hi!
Are you using wsl1 or wsl2?

@philipp1992
Copy link

getting this error
image

@pkerschbaum
Copy link

I think I found a more simple approach based on #2079 (comment).
The idea is to delegate any kubectl usage in Windows to kubectlin WSL.

  1. Create a file "kubectl.bat" somewhere in the Windows file system (e.g. in C:\scripts) and include this code:
    @echo off
    echo.
    wsl kubectl %*
  2. Add the folder (e.g. C:\scripts) to your PATH environment variable (using the Windows environment variables control panel).
  3. Start a new command line or PowerShell and type where kubectl. The first entry should be C:\scripts\kubectl.bat.
    • If this entry is not present, restart your computer.
    • If it is not the first entry in the list, you have to move the folder C:\scripts higher up for the PATH environment variable (this can be done in the Windows environment variables control panel).
  4. Start Lens

Finally, you might have to add your kube config from WSL. In my case, I had to add this folder using "Sync folder(s)": \\wsl.localhost\Ubuntu\home\pkerschbaum\.kube.

@Bafff
Copy link

Bafff commented Mar 10, 2022

@pkerschbaum hi!

I'll try your solution now, but one question - I see problem that there would be only one kubectl binary for al clusters, so if you have very old (unsupported) and very new clusters you could have issues

@pkerschbaum
Copy link

@Bafff that's true, I think this limitation applies also to the approach suggested by @jc-roman (#179 (comment)).
I don't know how to handle that...

@Bafff
Copy link

Bafff commented Mar 10, 2022

@pkerschbaum anyway thanks for sharing! How long are you using this? Does it work well, any issues or need-to-know things maybe?

@pkerschbaum
Copy link

@Bafff I shared the solution just after I got it working, it seems to work very well (can connect into containers etc).

@Bafff
Copy link

Bafff commented Mar 10, 2022

And what are your setting on the Kubernetes settings Tab in Lens? @pkerschbaum

@pkerschbaum
Copy link

@Bafff

image

@hpzzz
Copy link

hpzzz commented Mar 10, 2022

@pkerschbaum Hey, I followed Your instructions and am getting following errors:
image
any way to fix these path issues?

@Bafff
Copy link

Bafff commented Mar 10, 2022

@hpzzz you can try this workaround instead
ln -sf "/mnt/c/users/$windowsUser/.kube/config" ~/.kube/config
where $windowsUser is your Windows (not WSL) username

@pkerschbaum
Copy link

For me, there was also more to do regarding authentication for GCP:

For my cluster, gcloud is the authprovider.
If I did not use Lens for a while and then started it again, this error happened:

image

Running kubectl get pods once in WSL would refresh the access token and thus, Lens would work again - but this is of course annoying.

I "fixed" this issue in a similar way as I did for kubectl:

  1. Created gcloud.bat in C:\scripts:
    @echo off
    echo.
    wsl /usr/lib/google-cloud-sdk/bin/gcloud %*
  2. Edited ~/.kube/config in WSL:
    users:
    - name: ...
      user:
        auth-provider:
          config:
            ...
            cmd-path: gcloud # instead of /usr/lib/google-cloud-sdk/bin/gcloud

@PePoDev
Copy link

PePoDev commented Mar 19, 2022

I have created aws.bat to try with AWS

@echo off
echo.
wsl aws %*

I got this error message

Unable to locate credentials. You can configure credentials by running "aws configure".

E0319 20:27:45.776919 19308 proxy_server.go:147] Error while proxying request: getting credentials: exec: executable aws failed with exit code 253

getting credentials: exec: executable aws failed with exit code 253

@jvandervelden
Copy link

Try adding --user <wsl username>. Looks like it might be staring the wsl terminal not as the required user.

@PePoDev
Copy link

PePoDev commented Mar 19, 2022

Try adding --user <wsl username>. Looks like it might be staring the wsl terminal not as the required user.

@jvandervelden Hi, Thanks for the workaround.

I have tried to patch aws.bat to the below script, But not working.

@echo off
echo.
wsl --user <wsl-username> aws %*

But with option --profile <aws-profile> it's worked!

I don't know why 🤔

@ZILosoft
Copy link

workaround
in lens powershell terminal run wsl.exe
after
alias kubectl="kubectl.exe"

@romubaron
Copy link

I just was able to fix this issue by changing the default WSL default Distribution to Debian.
My setup was originally:

>wsl --list
Windows Subsystem for Linux Distributions:
docker-desktop-data (Default)
docker-desktop
Debian

And by setting up Debian as my default WSL, it has fixed my issue:

>wsl --set-default Debian
>wsl --list
Windows Subsystem for Linux Distributions:
Debian (Default)
docker-desktop
docker-desktop-data

Source: https://klaushofrichter.medium.com/using-windows-subsystem-for-linux-for-kubernetes-8bd1f5468531

@pureliumy
Copy link

pureliumy commented Sep 22, 2022

@hpzzz Try to edit the certs paths in your .kube/config to a relative path, such as ../.minikube/ca.crt. That works for me.

@kobethuwis
Copy link

kobethuwis commented Oct 21, 2022

I have created aws.bat to try with AWS

@echo off
echo.
wsl aws %*

I got this error message

Unable to locate credentials. You can configure credentials by running "aws configure".

E0319 20:27:45.776919 19308 proxy_server.go:147] Error while proxying request: getting credentials: exec: executable aws failed with exit code 253

getting credentials: exec: executable aws failed with exit code 253

@PePoDev I fixed this issue by using the solution provided here. Add the aws.bat file to your LocalAppData and the change will be picked up on restarting Lens. Not sure about the user credentials though 🤔

@DzeryCZ
Copy link

DzeryCZ commented Dec 7, 2022

I have created aws.bat to try with AWS

@echo off
echo.
wsl aws %*

I got this error message

Unable to locate credentials. You can configure credentials by running "aws configure".

E0319 20:27:45.776919 19308 proxy_server.go:147] Error while proxying request: getting credentials: exec: executable aws failed with exit code 253

getting credentials: exec: executable aws failed with exit code 253

I'm also using kubectl with aws, but the default aws.bat did not work for me correctly. I had to tune it up a bit so it exports all env variables, etc...

This one starts your shell (bash, zsh, ...) in interactive mode:

@echo off
echo.
wsl "$SHELL" -i -c "aws %*"

@kobethuwis
Copy link

I just was able to fix this issue by changing the default WSL default Distribution to Debian. My setup was originally:

>wsl --list
Windows Subsystem for Linux Distributions:
docker-desktop-data (Default)
docker-desktop
Debian

And by setting up Debian as my default WSL, it has fixed my issue:

>wsl --set-default Debian
>wsl --list
Windows Subsystem for Linux Distributions:
Debian (Default)
docker-desktop
docker-desktop-data

Source: https://klaushofrichter.medium.com/using-windows-subsystem-for-linux-for-kubernetes-8bd1f5468531

I'm also unable to use Lens with WSL2 since changing my default installation to a non-Debian version. (Kali Linux) Did anyone else manage to get it working?

@robertomanfreda
Copy link

I have lost 2 hours of my time but now all it is working fine.
I'll describe the process here:

  1. Install wsl (default is wsl 2) -> wsl --install -d Ubuntu-22.04
  2. Setup you Ubuntu user
  3. Install an app from Ubuntu, for testing if wslg is working (I installed terminator for this test)
  4. Install lens via .deb
    curl -fsSL https://downloads.k8slens.dev/keys/gpg | gpg --dearmor | sudo tee /usr/share/keyrings/lens-archive-keyring.gpg > /dev/null
    echo "deb [arch=amd64 signed-by=/usr/share/keyrings/lens-archive-keyring.gpg] https://downloads.k8slens.dev/apt/debian stable main" | sudo tee /etc/apt/sources.list.d/lens.list > /dev/null
    sudo apt update
    sudo apt install lens
  5. Try running 'lens-desktop', now I got 2 consecutive errors
    5.1 lens-desktop: error while loading shared libraries: libgbm.so.1: cannot open shared object file: No such file or directory
    FIX: sudo apt install libgbm1
    5.2 lens-desktop: error while loading shared libraries: libasound.so.2: cannot open shared object file: No such file or directory
    FIX: sudo apt install libasound2
  6. Now running 'lens-desktop' lens should start on your desktop but here trying to activate the license ID for me it was not working,it requires a browser inside your wsl in order to open link (it was so obvious - not obvious in the beginning)
  7. sudo apt install firefox
  8. Click the activation link on Lens desktop, now you should be redirected to the Lens page and all should work.

As notes you need to install kubectl in your wsl instance and your additional plugins such as oci or aws, just like lens works on native linux-based OSs

@jhonnyll
Copy link

That worked. Thank you!
The only problem I encounter besides the mentioned above was that my lens was off meaning I needed to hover my cursor somewhere above whatever icon/button I intended to click. This is probably a problem with a lens dependency or Linux GUI library. I found a workaround by going to View > "Toggle Full Screen" in the hamburger button on the top left screen of Lens

@MartinGolding515
Copy link

I made it work with wsl.exe by configuring the "path of the kubectl binary" to the wsl path of the kubectl.exe included with Lens installed on Windows. How-to:

  1. In the 'Application' tab, set the Terminal Shell Path to wsl.exe
    image

2, In the Kubernetes Tab, disable 'Kubectl Binary Download' image

  1. Take note of the kubectl.exe path in Lens. Usually:
    C:\Users\my-user\AppData\Local\Programs\Lens\resources\x64\kubectl.exe
    and translate from a Windows path to a WSL path. From a wsl terminal you can use wslpath :
# The Windows path should be within quotes

$ wslpath "C:\Users\my-user\AppData\Local\Programs\Lens\resources\x64\kubectl.exe"
/mnt/c/Users/my-user/AppData/Local/Programs/Lens/resources/x64/kubectl.exe
  1. Copy the WSL path you got from the previous step and paste it in Lens at 'Path to kubecl Binary'
    image

The terminal, port-forwarding or exec'ing into containers now work without issues for me.

I found running lens in wsl a pain due to display scaling issues, so reverted to windows app, but keeping kubeconfig in wsl.
Using ws.exe as the terminal path and the following format for kubectl
image

@wr-jc
Copy link

wr-jc commented Jan 22, 2024

I was able to get this working on Lens 2024.1.170738-latest

  1. In [ preferences -> Kubernetes ], uncheck "KUBECTL BINARY DOWNLOAD" and leave "PATH TO KUBECTL BINARY" unset. This way the terminal doesn't reference kubectl via absolute path and it just tries to run "kubectl"
  2. In [ preferences -> Terminal ], set "TERMINAL SHELL PATH" to wsl.exe

Initially this didn't work because Lens was overriding the KUBECONFIG environment variable to point to a custom kubeconfig in /mnt/c/Users//AppData/Local/Temp/-. I was able to workaround this issue using these steps:

  1. Open powershell and run wsl.exe (this ensures you are using the default wsl instance)
  2. use vi/vim/nano to edit ~/.bashrc file, this file is executed by default when you start a new bash shell
  3. At the end of ~/.bashrc add the following line:
    export KUBECONFIG=
  4. Save the file

Now when you launch a terminal in Lens, the .bashrc file will be sourced and override whatever value is being passed by Lens

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests