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

Attach Visual Studio Code doesn't work if kubernetes setting is in WSL #5849

Open
mtsmfm opened this issue Nov 10, 2021 · 19 comments
Open

Attach Visual Studio Code doesn't work if kubernetes setting is in WSL #5849

mtsmfm opened this issue Nov 10, 2021 · 19 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug containers Issue in vscode-remote containers kubernetes Dev Container support for Kubernetes upstream Issue identified as 'upstream' component related (exists outside of VS Code Remote)

Comments

@mtsmfm
Copy link

mtsmfm commented Nov 10, 2021

Even if it shown on k8s sidebar, I get No Pod name found error.

image

image

[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
@github-actions github-actions bot added the containers Issue in vscode-remote containers label Nov 10, 2021
@mtsmfm
Copy link
Author

mtsmfm commented Nov 11, 2021

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.

@mtsmfm
Copy link
Author

mtsmfm commented Nov 13, 2021

You can easily reproduce this problem by Rancher Desktop

  1. Install Rancher Desktop https://github.com/rancher-sandbox/rancher-desktop/releases
  2. Run kubectl run foo --image=ubuntu --restart=Never sleep infinity in WSL
  3. Run code . in WSL
  4. Install k8s extension in WSL
  5. Attach Visual Studio Code
    image

@cpbotha
Copy link

cpbotha commented Nov 20, 2021

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?

@mtsmfm
Copy link
Author

mtsmfm commented Nov 21, 2021

@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.

@chrmarti
Copy link
Contributor

Since the Kubernetes extension runs in WSL and uses kubectl there, could you try enabling the 'Remote-Containers: Execute in WSL' user setting?
image

@chrmarti chrmarti self-assigned this Nov 22, 2021
@chrmarti chrmarti added the info-needed Issue requires more information from poster label Nov 22, 2021
@mtsmfm
Copy link
Author

mtsmfm commented Nov 22, 2021

@chrmarti I got the same result.

image

@cpbotha
Copy link

cpbotha commented Nov 22, 2021

@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.

@chrmarti chrmarti added bug Issue identified by VS Code Team member as probable bug and removed info-needed Issue requires more information from poster labels Nov 22, 2021
@chrmarti
Copy link
Contributor

Got it, same cause as #4405.

@CoopTang
Copy link

Still no fix to this? I'm still getting this same issue, and it prevents me from using Windows with WSL2 for my workstation.

@chrmarti
Copy link
Contributor

chrmarti commented Feb 1, 2022

This depends on microsoft/vscode#111238.

@chrmarti chrmarti added the upstream Issue identified as 'upstream' component related (exists outside of VS Code Remote) label Feb 1, 2022
@marklechtermann
Copy link

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.

@calclavia
Copy link

calclavia commented Mar 6, 2023

@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.

@chrmarti chrmarti added the kubernetes Dev Container support for Kubernetes label Mar 8, 2023
@raffaele-capasso
Copy link

Still no fix to this? I'm still getting this same issue.. Thanks in advance for any answers

@hin-fan-alt
Copy link

hin-fan-alt commented Jul 20, 2023

I went into this issue and tried to see if there is truly a workaround. The following is how I got it to work.

  1. Copy ~/.kube from WSL into %userprofile% (windows, outside of WSL) (It is possible use mklink to create a symlink in cmd as admin).
  2. Start vscode-insider (vscode should also work) in windows (not inside WSL)
  3. Add [path/to/%userprofile%]/.kube/config into kubeconfig via vscode
    image
  • you should see docker-desktop by then
    image
  1. 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).

@fedorzh
Copy link

fedorzh commented Nov 21, 2023

@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

@mtsmfm
Copy link
Author

mtsmfm commented Nov 27, 2023

@fedorzh Make sure if you can open the editor with vs-code-remote://k8s-container URL

@haje01
Copy link

haje01 commented Jan 19, 2024

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.

@xgalaxy
Copy link

xgalaxy commented Jan 19, 2024

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.

@kbae1230
Copy link

kbae1230 commented May 2, 2024

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).
image
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug containers Issue in vscode-remote containers kubernetes Dev Container support for Kubernetes upstream Issue identified as 'upstream' component related (exists outside of VS Code Remote)
Projects
None yet
Development

No branches or pull requests