如何在 Docker for Windows 和 WSL2 上共享 Minikube 实例?

How to share Minikube instance on both Docker for Windows and WSL2?

如何在 Windows/Windows WSL 之间共享一个 Minikube 实例?

在 Windows WSL minikube start 中失败:

  minikube v1.22.0 on Ubuntu 20.04
✨  Using the docker driver based on existing profile
  Starting control plane node minikube in cluster minikube
  Pulling base image ...
  Updating the running docker "minikube" container ...
  StartHost failed, but will try again: provision: Temporary Error: NewSession: new client: new client: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain
  Updating the running docker "minikube" container ...
  Failed to start docker container. Running "minikube delete" may fix it: provision: Temporary Error: NewSession: new client: new client: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain

❌  Exiting due to IF_SSH_AUTH: Failed to start host: provision: Temporary Error: NewSession: new client: new client: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain
  Suggestion: Your host is failing to route packets to the minikube VM. If you have VPN software, try turning it off or configuring it so that it does not re-route traffic to the VM IP. If not, check your VM environment routing options.
  Documentation: https://minikube.sigs.k8s.io/docs/handbook/vpn_and_proxy/
  Related issue: https://github.com/kubernetes/minikube/issues/3930

以上在Windows中有效:

  minikube v1.17.1 on Microsoft Windows 10 Pro 10.0.19042 Build 19042
  minikube 1.22.0 is available! Download it: https://github.com/kubernetes/minikube/releases/tag/v1.22.0
  To disable this notice, run: 'minikube config set WantUpdateNotification false'

✨  Using the docker driver based on existing profile
  Starting control plane node minikube in cluster minikube
  Updating the running docker "minikube" container ...
  Preparing Kubernetes v1.20.2 on Docker 20.10.2 ...
  Verifying Kubernetes components...
  Enabled addons: storage-provisioner, dashboard, default-storageclass
  Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default

问题:

其次,我想分享一个 Docker 背景。 docker context ls:

Windows: Returns:

NAME                TYPE                DESCRIPTION                               DOCKER ENDPOINT                             KUBERNETES ENDPOINT                 ORCHESTRATOR
default *           moby                Current DOCKER_HOST based configuration   npipe:////./pipe/docker_engine              https://127.0.0.1:53873 (default)   swarm
desktop-linux       moby                                                          npipe:////./pipe/dockerDesktopLinuxEngine

Windows WSL (Ubuntu):

docker context ls
NAME                TYPE                DESCRIPTION                               DOCKER ENDPOINT                             KUBERNETES ENDPOINT                 ORCHESTRATOR
default *           moby                Current DOCKER_HOST based configuration   unix:///var/run/docker.sock                 https://127.0.0.1:51967 (default)   swarm
desktop-linux       moby

问题:

第三,我想分享一个 Kubernetes 上下文。 kubectl config get-contexts:

Windows:

CURRENT   NAME                                       CLUSTER          AUTHINFO                        NAMESPACE
          docker-desktop                             docker-desktop   docker-desktop
          kubernetes/REDACTED   kubernetes       REDACTED
*         minikube                                   minikube         minikube                        default

Windows WSL (Ubuntu):

CURRENT   NAME             CLUSTER          AUTHINFO         NAMESPACE
          docker-desktop   docker-desktop   docker-desktop
*         minikube         minikube         minikube

问题:

我能够通过复制配置文件同步两者 Windows/WSL:

mkdir ~/.kube \ && cp /mnt/c/Users/[USERNAME]/.kube/config ~/.kube
kubectl config use-context docker-for-desktop # Select the Windows context
kubectl cluster-info # Check if it works## Heading ##

参考:https://devkimchi.com/2018/06/05/running-kubernetes-on-wsl/