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 via Kubernetes fails to connect remoteContainers [resolved] #7108

Closed
Jackbennett opened this issue Aug 23, 2022 · 5 comments
Assignees
Labels
containers Issue in vscode-remote containers info-needed Issue requires more information from poster

Comments

@Jackbennett
Copy link

Jackbennett commented Aug 23, 2022

  • VSCode Version: 1.70.0
  • Local OS Version: windows 10 x64 19043.1889
  • Remote OS Version: n/a
  • Remote Extension/Connection Type: Kubernetes v1.3.10 attach remote container to Containers hyper-V Talos cluster.
  • Logs: lost log - but the remoteContainers error isn't valid for the actual problem.

Steps to Reproduce:

  • Note: opening PowerShell normally, kubectl finds the working kubeconf and works fine.
  1. Set kubeconfig via command to configure kubernetes plugin
  2. Have System Env of KUBECONFIG %userprofile%\.kube\config
  3. Use "attach to container" and an error from remoteContainers about kubectl config current-context will be thrown

Results in KUBECONFIG C:\WINDOWS\system32\config\systemprofile\.kube\config

Does this issue occur when you try this locally?: Yes
Does this issue occur when you try this locally and all extensions are disabled?: n/a

checking ls Env: finds expected ENV variables with my username. Only KUBECONFIG has the system32 path.

Fix

Remove KUBECONFIG key from System Env. User env is untested, just revert to letting kubectl search default paths itself.

I don't know how vscode launches its terminal to end up with %userprofile% in system32 but I think having the system env kubeconfig a user err on my part lingering from long ago. This issue is reported in case someone else has the same odd error where you can browse the cluster but can't attach code to connect to pods, getting a terminal works.

Secondary, invisible config

It seems vs-kubernetes.kubeconfig isn't used by "attach visual studio code" to container OR it's overwritten by an ENV when ran, which isn't used when browsing the cluster in the sidebar UI.

Command palette: "Configure kuberenetes" sets these keys which aren't visible in the Settings UI viewing @ext:ms-kubernetes-tools.vscode-kubernetes-tools

  "vs-kubernetes": {
    "vs-kubernetes.knownKubeconfigs": ["c:\\Users\\Jack\\.kube\\config"],
    "vs-kubernetes.kubeconfig": "c:\\Users\\Jack\\.kube\\config"
  }

Searching "kubeconfig" has no settings found at all. Maybe this key is ignored as that's a default path anyway and that's a red herring.

@MurzNN
Copy link

MurzNN commented Aug 25, 2022

Thanks for the description of the fix! For me I have this issue only when trying to connect to the Kubernetes pod on VS Code Remote instance (launched via SSH to remote server).

But the provided fix doesn't work for me on Linux. I've made suggested changes, using invisible config:

  "vs-kubernetes": {
    "vs-kubernetes.knownKubeconfigs": ["/home/korepov/.kube/config"],
    "vs-kubernetes.kubeconfig": "/home/korepov/.kube/config"
  },

When I'm setting incorrect path - the cluster is disappearing from the Kubernetes tab, so those settings are working well.

But I still don't see the "Attach Visual Studio Code" menu item:
image

Terminal and other commands are connecting to the pod well.

Maybe you have any other ideas what else can I try?

@chrmarti
Copy link
Contributor

@Jackbennett Maybe %userprofile% in a system environment variable resolves to that system path? (Haven't tried.)

@MurzNN You need the Remote-Containers extension to get that context menu entry. It won't work though when the Kubernetes extension is running remotely as part of Remote-SSH due to #6054.

@chrmarti chrmarti self-assigned this Aug 25, 2022
@chrmarti chrmarti added the info-needed Issue requires more information from poster label Aug 25, 2022
@MurzNN
Copy link

MurzNN commented Aug 25, 2022

I have the Remote-Containers extension installed (v0.245.2) together with Remote-SSH (v0.84.0). So my problem seems exactly related to #6054 - thanks for clarification!

@github-actions
Copy link

Hey @chrmarti, this issue might need further attention.

@Jackbennett, you can help us out by closing this issue if the problem no longer exists, or adding more information.

@Jackbennett
Copy link
Author

Yeh I guess it's closable, I don't think there's an action to resolve. Maybe warning if the resolved profile config is a known system path anyway?

I don't think code was running as admin so wouldn't expect userprofile to actually be something in system32. I'm not sure how to detect vscode and kubectl getting different configs, probably a good amount of time it's intentional.

@github-actions github-actions bot locked and limited conversation to collaborators Feb 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
containers Issue in vscode-remote containers info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

3 participants