lens icon indicating copy to clipboard operation
lens copied to clipboard

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

Open heyvoon opened this issue 3 years ago • 16 comments

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):

  • Lens Version: 5
  • OS: Windows 10 (WSL2 / Ubuntu 20.04)

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/[email protected]/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/[email protected]/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/[email protected]/klog.go:735 +0x1ae
k8s.io/klog/v2.(*loggingT).print(...)
C:/Users/runneradmin/go/pkg/mod/k8s.io/klog/[email protected]/klog.go:717
k8s.io/klog/v2.Fatal(...)
C:/Users/runneradmin/go/pkg/mod/k8s.io/klog/[email protected]/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/[email protected]/klog.go:1283 +0x6a
created by k8s.io/klog/v2.init.0
C:/Users/runneradmin/go/pkg/mod/k8s.io/klog/[email protected]/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.

heyvoon avatar Jun 23 '22 09:06 heyvoon

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

avimehenwal avatar Jul 07 '22 12:07 avimehenwal

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

  1. in Lens, menu in top left > file > add cluster, paste and apply

arieller avatar Sep 09 '22 17:09 arieller

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

Shivankur25 avatar Oct 10 '22 08:10 Shivankur25

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

pimielowski avatar Oct 22 '22 15:10 pimielowski

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)

death7700 avatar Jan 05 '23 10:01 death7700

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

Jagan-07 avatar Apr 04 '23 03:04 Jagan-07

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

  • context: cluster: docker-desktop user: docker-desktop name: docker-desktop
  • context: cluster: minikube user: minikube name: minikube current-context: minikube kind: Config preferences: {} users:
  • name: docker-desktop user: client-certificate-data: REDACTED client-key-data: REDACTED
  • name: minikube

46kumarshivam avatar Jul 04 '23 21:07 46kumarshivam

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

turikhay avatar Nov 05 '23 22:11 turikhay

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.

sv222 avatar Nov 26 '23 19:11 sv222

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

image

Psychotechnopath avatar Feb 20 '24 11:02 Psychotechnopath

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

telebh1 avatar Apr 04 '24 17:04 telebh1