for-win
for-win copied to clipboard
Cannot connect from WSL2 to Docker Desktop Kubernetes via kubectl
- [x] I have tried with the latest version of Docker Desktop
- [x] I have tried disabling enabled experimental features
- [x] I have uploaded Diagnostics
- Diagnostics ID: D7D6AD08-4AEE-4ED1-804A-460EC61D577A/20230414085504
Actual behavior
I cannot connect from WSL 2 (Ubuntu) to Docker Desktop Kubernnetes via kubectl. I can connect via kubectl from PowerShell.
Expected behavior
I should be able to connect via kubectl from WSL2 as well as from PowerShell.
Information
-
Is it reproducible? Yes
-
Is the problem new? Yes, it worked before
-
Did the problem appear with an update? Possibly, since it worked before
-
Windows Version: Windows 11 Home 22H2 22621.1555
-
Docker Desktop Version: 4.18.0
-
WSL2 or Hyper-V backend? WSL2
-
Are you running inside a virtualized Windows e.g. on a cloud server or a VM: not a virtualized Windows
Output of & "C:\Program Files\Docker\Docker\resources\com.docker.diagnose.exe" check
I have provided the Diagnostics ID, the information should be in that report.
Steps to reproduce the behavior
Docker & Kubernetes on Docker Desktop are working correctly. The problem is to connect via kubectl from WSL2. Example:
$ kubectl cluster-info
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
The connection to the server kubernetes.docker.internal:6443 was refused - did you specify the right host or port?
The same command issued from PowerShell works:
PS kubectl cluster-info
Kubernetes control plane is running at https://kubernetes.docker.internal:6443
CoreDNS is running at https://kubernetes.docker.internal:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
When I uninstall Docker for Windows correctly, remove all .cache folders & kubeconfigs, after fresh install the connection is working. However, after the computer restart, the problem reappears.
Edit: I am providing full information on the versions of WSL, Docker and Kubernetes (mine are the same as those provided by @BarclayHill in the comments below):
PS C:\> wsl --version
WSL version: 1.2.0.0
Kernel version: 5.15.90.1
WSLg version: 1.0.51
MSRDC version: 1.2.3770
Direct3D version: 1.608.2-61064218
DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows version: 10.0.22621.1555
PS C:\> docker --version
Docker version 20.10.24, build 297e128
PS C:\> kubectl version --short
Client Version: v1.25.4
Kustomize Version: v4.5.7
Server Version: v1.25.4