I'm running Docker Desktop for Windows with WSL2 integration. I'm also running minikube. The Docker Desktop GUI correctly shows both known contexts:
I've selected the 'minikube' context because that's the one I want to use.
However when I go into the WSL terminal and run kubectl config get-contexts
, I can only see the docker-desktop context, which is the active one:
admin@RODDY01-PC:/mnt/c/workspace$ kubectl config get-contexts
CURRENT NAME CLUSTER AUTHINFO NAMESPACE
* docker-desktop docker-desktop docker-desktop
Running which kubectl
reveals that I'm using the kubectl that docker-desktop installed when doing the WSL integration:
admin@RODDY01-PC:/mnt/c/workspace$ which kubectl
/usr/local/bin/kubectl
admin@RODDY01-PC:/mnt/c/workspace$ ls -la /usr/local/bin/kubectl
lrwxrwxrwx 1 root root 55 Aug 1 17:49 /usr/local/bin/kubectl -> /mnt/wsl/docker-desktop/cli-tools/usr/local/bin/kubectl
(In Windows, where kubectl is bundled as part of docker at C:\Program Files\Docker\Docker\resources\bin\kubectl.exe
, it correctly shows both contexts and indicates minikube is the active; it's just the Linux/WSL2 kubectl instance that's not updating/recognizing the active and available contexts.)
How can I get Docker Desktop to properly update the kubectl active context in WSL2?
Version info: Docker Desktop 3.5.2; Windows 10 Professional; Debian 10 on WSL2.
The problem turned out to be that I actually had two kube config files.
Windows, which was correctly being updated by the GUI, had a config located at: C:\Users\<username\.kube\config
.
WSL also had one, at ~/.kube/config
. This one was NOT up-to-date, and was actually missing the entire minikube context definition.
I solved this by setting an environment variable in my ~/.bashrc
file to point $KUBECONFIG
to the Windows kube config file. One of my colleagues having a similar issue instead deleted the linux file and created a symlink to the Windows one; both solutions work.
Tangentially related: the minikube configuration include certificates that use Windows-style paths in the config file; it was necessary to embed these certificates into the configuration file in order for them to work properly cross-OS.