lensapp / lens

Lens - The way the world runs Kubernetes
https://k8slens.dev/
MIT License
22.47k stars 1.46k forks source link

WSL2 + Minikube + Lens (Unable to connect to K8 cluster in WSL2) #5714

Open heyvoon opened 2 years ago

heyvoon commented 2 years ago

Describe the bug Hello Everyone,

My setup:

Windows 10 WSL2 Docker, kubectl, minikube I am trying to get Lens 5 to connect to the minikube cluster inside WSL2 but it won't work. I get the following error when pointing Lens to "\wsl$\Ubuntu\home\MYUSER.kube\config".

Has anyone been able to successfully connect Lens 5 to a K8s cluster inside a WSL2 (w/ Ubuntu 20.04) ?

To Reproduce Steps to reproduce the behavior:

  1. Assuming you have Windows 10 with WSL2 Ubuntu 20.04
  2. Install Docker, kubectl, minikube (In WSL2)
  3. Install Lens 5 (In Windows 10)
  4. Try to connect Lens 5 to the Minikube cluster inside WSL2

Expected behavior Lens 5 should recognize the ".kube/config" and connect to the Minikube cluster.

Screenshots Not applicable

Environment (please complete the following information):

Logs: When you run the application executable from command line you will see some logging output. Please paste them here:

F0623 11:45:49.021116 16520 main.go:74] failed to initialize kubeconfiginvalid configuration: [unable to read client-cert \\wsl$\Ubuntu\home\DevOps\.kube\home\DevOps\.minikube\profiles\minikube\client.crt for minikube due to open \\wsl$\Ubuntu\home\DevOps\.kube\home\DevOps\.minikube\profiles\minikube\client.crt: The system cannot find the path specified., unable to read client-key \\wsl$\Ubuntu\home\DevOps\.kube\home\DevOps\.minikube\profiles\minikube\client.key for minikube due to open \\wsl$\Ubuntu\home\DevOps\.kube\home\DevOps\.minikube\profiles\minikube\client.key: The system cannot find the path specified., unable to read certificate-authority \\wsl$\Ubuntu\home\DevOps\.kube\home\DevOps\.minikube\ca.crt for minikube due to open \\wsl$\Ubuntu\home\DevOps\.kube\home\DevOps\.minikube\ca.crt: The system cannot find the path specified.]
goroutine 1 [running]:
k8s.io/klog/v2.stacks(0x1)
C:/Users/runneradmin/go/pkg/mod/k8s.io/klog/v2@v2.40.1/klog.go:1140 +0x8a
k8s.io/klog/v2.(*loggingT).output(0x2395140, 0x3, 0x0, 0xc0001bac40, 0x1, {0x1b6c0b5, 0x20}, 0x2396020, 0x0)
C:/Users/runneradmin/go/pkg/mod/k8s.io/klog/v2@v2.40.1/klog.go:1088 +0x66f
k8s.io/klog/v2.(*loggingT).printDepth(0xc000142900, 0x6018, 0x0, {0x0, 0x0}, 0x1, {0xc00037a460, 0x2, 0x2})
C:/Users/runneradmin/go/pkg/mod/k8s.io/klog/v2@v2.40.1/klog.go:735 +0x1ae
k8s.io/klog/v2.(*loggingT).print(...)
C:/Users/runneradmin/go/pkg/mod/k8s.io/klog/v2@v2.40.1/klog.go:717
k8s.io/klog/v2.Fatal(...)
C:/Users/runneradmin/go/pkg/mod/k8s.io/klog/v2@v2.40.1/klog.go:1622
main.main()
D:/a/lens-k8s-proxy/lens-k8s-proxy/main.go:74 +0x6a6

goroutine 6 [chan receive]:
k8s.io/klog/v2.(*loggingT).flushDaemon(0x0)
C:/Users/runneradmin/go/pkg/mod/k8s.io/klog/v2@v2.40.1/klog.go:1283 +0x6a
created by k8s.io/klog/v2.init.0
C:/Users/runneradmin/go/pkg/mod/k8s.io/klog/v2@v2.40.1/klog.go:420 +0xfb

goroutine 8 [syscall]:
os/signal.signal_recv()
C:/hostedtoolcache/windows/go/1.17.8/x64/src/runtime/sigqueue.go:169 +0x98
os/signal.loop()
C:/hostedtoolcache/windows/go/1.17.8/x64/src/os/signal/signal_unix.go:24 +0x19
created by os/signal.Notify.func1.1
C:/hostedtoolcache/windows/go/1.17.8/x64/src/os/signal/signal.go:151 +0x2c

proxy exited with code: 255

Kubeconfig: Quite often the problems are caused by malformed kubeconfig which the application tries to load. Please share your kubeconfig, remember to remove any secret and sensitive information.

apiVersion: v1
clusters:
- cluster:
    certificate-authority: /home/myuser/.minikube/ca.crt
    extensions:
    - extension:
        last-update: Thu, 23 Jun 2022 11:09:03 CEST
        provider: minikube.sigs.k8s.io
        version: v1.26.0
      name: cluster_info
    server: https://127.0.0.1:49159
  name: minikube
contexts:
- context:
    cluster: minikube
    extensions:
    - extension:
        last-update: Thu, 23 Jun 2022 11:09:03 CEST
        provider: minikube.sigs.k8s.io
        version: v1.26.0
      name: context_info
    namespace: default
    user: minikube
  name: minikube
current-context: minikube
kind: Config
preferences: {}
users:
- name: minikube
  user:
    client-certificate: /home/myuser/.minikube/profiles/minikube/client.crt
    client-key: /home/myuser/.minikube/profiles/minikube/client.key

Additional context Any help getting Lens 5 to connect to a Minikube cluster inside WSL2 is appreciated. Thank you all in advance.

avimehenwal commented 2 years ago

same issue with me as well. Cannot connect to minikube running on WSL-2 on windows-11-pro

arieller commented 2 years ago

I had two issues, the pathing was messed up in the syntax and the path to the actual client keys was wrong.

I'm running docker on windows 11, starting my minikube from WSL2.

Solution that worked for me: 1) Copy your config from \\wsl.localhost\Ubuntu-22.04\home\${WSL2-HOME}\.kube, I removed anything that was unrelated to minikube. 2) change paths of certificates to the absolute path from your windows machine, you should have something like the following config as the outcome:

apiVersion: v1
clusters:
- cluster:
    certificate-authority: \\wsl.localhost\Ubuntu-22.04\home\${WSL2-HOME}\.minikube\ca.crt
    extensions:
    - extension:
        last-update: Fri, 09 Sep 2022 20:13:40 IDT
        provider: minikube.sigs.k8s.io
        version: v1.26.1
      name: cluster_info
    server: https://127.0.0.1:60299
  name: minikube
contexts:
- context:
    cluster: minikube
    extensions:
    - extension:
        last-update: Fri, 09 Sep 2022 20:13:40 IDT
        provider: minikube.sigs.k8s.io
        version: v1.26.1
      name: context_info
    namespace: default
    user: minikube
  name: minikube
current-context: minikube
kind: Config
preferences: {}
users:
- name: docker-desktop
  user:
    client-certificate-data: (key)
    client-key-data: (key)
- name: minikube
  user:
    client-certificate: \\wsl.localhost\Ubuntu-22.04\home\${WSL2-HOME}\.minikube\profiles\minikube\client.crt
    client-key: \\wsl.localhost\Ubuntu-22.04\home\${WSL2-HOME}\.minikube\profiles\minikube\client.key

3) in Lens, menu in top left > file > add cluster, paste and apply

Shivankur25 commented 1 year ago

I was also having problem and my cluster was not visible on lens : Then I found a solution that we have to add our Cluster manually to the LENS DESKTOP by following ways : 1 . in your WSL command line start the minikube cluster .... by minikube start command

  1. then run kubectl config view your config file will be visible .....
  2. if kubectl is not installed then you have to go manually to config path \\wsl.localhost\Ubuntu-20.04\home\${your username}\.kube\config
  3. then copy that config file and paste in lens ---> add cluster (ctrl+shift+a) .....
  4. edit your config file and add \\wsl.localhost\Ubuntu-{your version}\ before \home at certificate-authority , client-certificate, client-key
  5. after edit the config file : image
  6. add cluster

Your minikube will be visible on lens desktop

NOTE:-

MINIKUBE CLUSTER MUST BE STARTED

pimielowski commented 1 year ago

In my case the problem was with WSL root path. \\wsl.localhost simply don't work, I needed to change this to \\wsl$\Ubuntu\ So whole config looks like this:

apiVersion: v1
clusters:
- cluster:
    certificate-authority: \\wsl$\Ubuntu\home\${WSL2-HOME}\.minikube\ca.crt
    extensions:
    - extension:
        last-update: Sat, 22 Oct 2022 17:28:11 CEST
        provider: minikube.sigs.k8s.io
        version: v1.27.1
      name: cluster_info
    server: https://127.0.0.1:54002
  name: minikube
contexts:
- context:
    cluster: minikube
    extensions:
    - extension:
        last-update: Sat, 22 Oct 2022 17:28:11 CEST
        provider: minikube.sigs.k8s.io
        version: v1.27.1
      name: context_info
    namespace: default
    user: minikube
  name: minikube
current-context: minikube
kind: Config
preferences: {}
users:
- name: minikube
  user:
    client-certificate: \\wsl$\Ubuntu\home\${WSL2-HOME}\.minikube\profiles\minikube\client.crt
    client-key: \\wsl$\Ubuntu\home\${WSL2-HOME}\.minikube\profiles\minikube\client.key
death7700 commented 1 year ago

I was also having problem and my cluster was not visible on lens : Then I found a solution that we have to add our Cluster manually to the LENS DESKTOP by following ways : 1 . in your WSL command line start the minikube cluster .... by minikube start command 2. then run kubectl config view your config file will be visible ..... 3. if kubectl is not installed then you have to go manually to config path \\wsl.localhost\Ubuntu-20.04\home\${your username}\.kube\config 4. then copy that config file and paste in lens ---> add cluster (ctrl+shift+a) ..... 5. edit your config file and add \\wsl.localhost\Ubuntu-{your version}\ before \home at certificate-authority , client-certificate, client-key 6. after edit the config file : image 7. add cluster

Your minikube will be visible on lens desktop

NOTE:-

MINIKUBE CLUSTER MUST BE STARTED

THANKS! It works for me)

Jagan-07 commented 1 year ago

I was also having problem and my cluster was not visible on lens : Then I found a solution that we have to add our Cluster manually to the LENS DESKTOP by following ways : 1 . in your WSL command line start the minikube cluster .... by minikube start command 2. then run kubectl config view your config file will be visible ..... 3. if kubectl is not installed then you have to go manually to config path \\wsl.localhost\Ubuntu-20.04\home\${your username}\.kube\config 4. then copy that config file and paste in lens ---> add cluster (ctrl+shift+a) ..... 5. edit your config file and add \\wsl.localhost\Ubuntu-{your version}\ before \home at certificate-authority , client-certificate, client-key 6. after edit the config file : image 7. add cluster

Your minikube will be visible on lens desktop

NOTE:-

MINIKUBE CLUSTER MUST BE STARTED

Thank you shivankur 🔥 It worked!!! May i know how to sync that path as default manually? cause if i try to sync that via lens it says "you cannot select this location".

46kumarshivam commented 1 year ago

server: https://127.0.0.1:51887 name: minikube contexts:

turikhay commented 10 months ago

For the time being I wanted to share my workaround: https://github.com/turikhay/minikube-lens-k8s-config-rewriter

sv222 commented 9 months ago

The issue is with the configuration paths and certificate paths.

  1. Copy ~/.kube/config from WSL to any directory, e.g. D:\Temp\config
  2. Copy the certificates mentioned in ~/.kube/config to D:\Temp as well.
  3. Change the paths to the certificates inside D:\Temp\config to D:\Temp
  4. Add this new config to lens.
Psychotechnopath commented 7 months ago

For me when I try to apply the above solutions, my LENS get's stuck at "connecting"

image

telebh1 commented 5 months ago

I have the same issue. I followed the steps @Shivankur25 indicated earlier by copying over the contents of .kube/config file in wsl2 to Openlens config file. BTW, I also opened proxy connection in cmd on my windows machine kubectl proxy --port 8001 --reject-paths "^/api/./pods/./attach"

and added the proxy URL 127.0.0.1:800 in Openlens, but now when it connects to the cluster I am getting the following error

image

fgallims commented 1 month ago

To resolve issues with certificate paths:

minikube start --embed-certs

sandeeps29 commented 4 weeks ago

I was also having problem and my cluster was not visible on lens : Then I found a solution that we have to add our Cluster manually to the LENS DESKTOP by following ways : 1 . in your WSL command line start the minikube cluster .... by minikube start command 2. then run kubectl config view your config file will be visible ..... 3. if kubectl is not installed then you have to go manually to config path \\wsl.localhost\Ubuntu-20.04\home\${your username}\.kube\config 4. then copy that config file and paste in lens ---> add cluster (ctrl+shift+a) ..... 5. edit your config file and add \\wsl.localhost\Ubuntu-{your version}\ before \home at certificate-authority , client-certificate, client-key 6. after edit the config file : image 7. add cluster

Your minikube will be visible on lens desktop

NOTE:-

MINIKUBE CLUSTER MUST BE STARTED

thnk u for the help it worked for me reminder : add \\wsl.localhost\Ubuntu\ before \home at certificate-authority , client-certificate, client-key Adding ubuntu version is not necessary