vscode-remote-release
vscode-remote-release copied to clipboard
Attach Visual Studio Code doesn't work if kubernetes setting is in WSL
Even if it shown on k8s sidebar, I get No Pod name found error.
[93 ms] Remote-Containers 0.205.2 in VS Code 1.62.1 (f4af3cbf5a99787542e2a30fe1fd37cd644cc31f).
[90 ms] Start: WSL env probe
[98 ms] Start: Run: wsl -d ubuntu-20.04
[1261 ms] Start: WSL env probe
[1262 ms] Start: Run: wsl -d ubuntu-20.04
[14345 ms] Start: WSL env probe
[14346 ms] Start: Run: wsl -d ubuntu-20.04
[14827 ms] No Pod name found. Pod object:
null
After copying .kube/config from WSL to Windows, it works.
($ cp ~/.kube/config /mnt/c/Users/mtsmfm/.kube/config
in WSL)
It seems Attach Visual Studio Code doesn't consider such a case.
You can easily reproduce this problem by Rancher Desktop
- Install Rancher Desktop https://github.com/rancher-sandbox/rancher-desktop/releases
- Run
kubectl run foo --image=ubuntu --restart=Never sleep infinity
in WSL - Run
code .
in WSL - Install k8s extension in WSL
- Attach Visual Studio Code
I have run into this exact issue in Visual Studio Code 1.62.3 and Kubernetes extension 1.3.4 with Rancher Desktop 0.6.1 on Windows 11 build 22000.348 with WSL 0.50.2.0.
My ~/.kube/config
is symlinked from %USERPROFILE%/.kube/config
as per the rancher desktop installation.
Right-clicking on the pod, and then selecting "terminal" does work (I get a shell on the container in the pod), but attach does not with the "No Pod name found" error.
I would be grateful to hear of any workarounds. @mtsmfm did you make any progress with this?
@cpbotha I've found code
command accepts URIs like the following:
code vscode-remote://k8s-container%2Bcontext%3Drancher-desktop%2Bpodname%3Dthings-5454d95b69-q9c6f%2Bnamespace%3Ddefault%2Bname%3D/workspace/things
I can't find full list of valid params though, it'll be like this:
https://github.com/mtsmfm/vscode-k8s-quick-attach/blob/fc26c521ad4cf66073fc804de8567394a64bfcc5/src/quickAttach.ts#L67-L73
I've released an extension to attach VSCode to pod quickly and easily.
https://marketplace.visualstudio.com/items?itemName=mtsmfm.vscode-k8s-quick-attach
Hopefully it helps.
Since the Kubernetes extension runs in WSL and uses kubectl
there, could you try enabling the 'Remote-Containers: Execute in WSL' user setting?
@chrmarti I got the same result.
@chrmarti Just like @mtsmfm I can confirm that that setting does not help: It gives the same error.
As an additional datapoint, I did confirm earlier today that attaching to the pod with VSCode NOT connected to WSL (i.e. just open on Windows) succeeds.
Got it, same cause as https://github.com/microsoft/vscode-remote-release/issues/4405.
Still no fix to this? I'm still getting this same issue, and it prevents me from using Windows with WSL2 for my workstation.
This depends on https://github.com/microsoft/vscode/issues/111238.
You need to install kubectl
on your Windows system.
Also, kubectl must be able to be found via the $PATH variable.
Additionally I installed the Kubernetes extension in VSCode in Windows (no idea if this is necessary)
If you then copy your .kube/config
file from Linux to Windows, it should work.
Verified in WSL (Ubuntu 22.04) with docker and minikube.
@marklechtermann I tried these steps but it doesn't work - still says "No pod name found". Only workaround is attaching to K8 pods from outside of WSL in non-WSL VSCode.
Still no fix to this? I'm still getting this same issue.. Thanks in advance for any answers
I went into this issue and tried to see if there is truly a workaround. The following is how I got it to work.
- Copy ~/.kube from WSL into %userprofile% (windows, outside of WSL) (It is possible use mklink to create a symlink in cmd as admin).
- Start vscode-insider (vscode should also work) in windows (not inside WSL)
- Add [path/to/%userprofile%]/.kube/config into kubeconfig via vscode
- you should see docker-desktop by then
- The "Attach Visual Studio Code" option worked for me.
-
if docker-desktop doesn't show up under cluster, try to reload windows, repeat step 2-3. If it still doesn't work, sorry.
-
Note that this change will break kubernetes extension inside WSL and "Open dashboard" will not work.
- To fix kubernetes extension inside WSL, change kubeconfig back to home/[username]/.kube/config.
- For dashboard, go into bash of WSL and type
kubectl proxy
(I am not aware of any downside).
@cpbotha I've found
code
command accepts URIs like the following:code vscode-remote://k8s-container%2Bcontext%3Drancher-desktop%2Bpodname%3Dthings-5454d95b69-q9c6f%2Bnamespace%3Ddefault%2Bname%3D/workspace/things
I can't find full list of valid params though, it'll be like this:
https://github.com/mtsmfm/vscode-k8s-quick-attach/blob/fc26c521ad4cf66073fc804de8567394a64bfcc5/src/quickAttach.ts#L67-L73
I've released an extension to attach VSCode to pod quickly and easily.
https://marketplace.visualstudio.com/items?itemName=mtsmfm.vscode-k8s-quick-attach
Hopefully it helps.
@mtsmfm I am actually trying your extension and getting error
Command failed with exit code 1: <linux_path_to_internal_file> k8s create-token --profile=default The system cannot find the path specified.
even though the same line successfully executes in wsl.
Do you know what could go wrong?
also, just copying the config file to the Windows location still produces No Pod name found
for some reason
@fedorzh Make sure if you can open the editor with vs-code-remote://k8s-container
URL
In my minikube in WSL environment I have same problem.
@mtsmfm Simply copying kube config file as you said:
cp ~/.kube/config /mnt/c/Users/mtsmfm/.kube/config
does not work for me, since windows kubectl can not access client-certificate & client-key files. So i prefix \\wsl$\Ubuntu
to the path of cert files, and now windows kubectl can find my pods.
But your extension 'k8s quick attach' raises errors:
UNC host 'wsl$' access is not allowed
Still, I can use 'Terminal' comand like @cpbotha .
Following is the log when i run 'Attach Visual Studio Code' command from the menu, and VS Code raises No Pod name found
[42698 ms] Dev Containers 0.327.0 in VS Code 1.85.2 (8b3775030ed1a69b13e4f4c628c612102e30a681).
[1529412 ms] Start: Run: wsl -d Ubuntu -e /bin/sh -c cd '/home/haje01/works/wai-da' && /bin/sh
[1529420 ms] Start: Run in host: id -un
[1529540 ms] haje01
[1529541 ms]
[1529541 ms] Start: Run in host: (command -v getent >/dev/null 2>&1 && getent passwd 'haje01' || grep -E '^haje01|^[^:]*:[^:]*:haje01:' /etc/passwd || true)
[1529543 ms] Start: Run in host: echo ~
[1529544 ms] /home/haje01
[1529544 ms]
[1529544 ms] Start: Run in host: test -x '/home/haje01/.vscode-remote-containers/bin/8b3775030ed1a69b13e4f4c628c612102e30a681/node'
[1529545 ms]
[1529545 ms]
[1529545 ms] Exit code 1
[1529546 ms] Start: Run in host: test -x '/home/haje01/.vscode-server/bin/8b3775030ed1a69b13e4f4c628c612102e30a681/node'
[1529547 ms]
[1529547 ms]
[1529547 ms] Start: Run in host: test -f '/home/haje01/.vscode-server/bin/8b3775030ed1a69b13e4f4c628c612102e30a681/node_modules/node-pty/package.json'
[1529548 ms]
[1529548 ms]
[1529548 ms] Start: Run in host: test -f '/home/haje01/.vscode-remote-containers/dist/vscode-remote-containers-server-0.327.0.js'
[1529549 ms]
[1529550 ms]
[1529551 ms] userEnvProbe: loginInteractiveShell (default)
[1529551 ms] userEnvProbe: not found in cache
[1529551 ms] userEnvProbe shell: /bin/bash
[1531007 ms] userEnvProbe PATHs:
Probe: '/home/haje01/.pyenv/shims:/home/haje01/.local/bin:/home/haje01/.sdkman/candidates/gradle/current/bin:/home/haje01/.npm-global/bin:/usr/local/cuda-12.2/bin:~/.local/apache-maven-3.9.3/bin:/home/haje01/.local/bin:/home/haje01/.bun/bin:/home/haje01/.krew/bin:/home/haje01/.pyenv/plugins/pyenv-virtualenv/shims:/home/haje01/.pyenv/bin:/usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/wsl/lib:/mnt/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.2/bin:/mnt/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.2/libnvvp:/mnt/c/Windows/system32:/mnt/c/Windows:/mnt/c/Windows/System32/Wbem:/mnt/c/Windows/System32/WindowsPowerShell/v1.0/:/mnt/c/Windows/System32/OpenSSH/:/mnt/c/Program Files/Bandizip/:/mnt/c/Program Files (x86)/NVIDIA Corporation/PhysX/Common:/mnt/c/Program Files/dotnet/:/mnt/c/ProgramData/chocolatey/bin:/mnt/c/Program Files/NVIDIA Corporation/Nsight Compute 2023.2.2/:/mnt/c/Program Files/NVIDIA Corporation/NVIDIA NvDLISR:/mnt/c/Program Files/Git/cmd:/mnt/c/Users/haje01/AppData/Local/Microsoft/WindowsApps:/mnt/c/Users/haje01/AppData/Local/Programs/Microsoft VS Code/bin:/snap/bin:/home/haje01/.fzf/bin'
Container: None
[1531060 ms] No Pod name found. Pod object:
null
[1651396 ms] No Pod name found. Pod object:
null
Interestingly enough, when i run 'Copy Name' command from the menu, It successfuly copy the right pod name.
This is a pretty common workflow now that people want to avoid the Docker Desktop mess. It would be nice to see this get supported.
I tried as you instructed, but I still get the 'No Pod name found. Pod object: null' error in WSL. Instead, it works fine when I open it with k8s extensions in Windows (PowerShell) instead of WSL (Ubuntu 20.04).