【minikube】Docker Desktop for Linux 启动 minikube 时遇到无法连接到 API server 的错误: time out \ Enabling 'default-storageclass' returned an error \ dial tcp 192.168.49.2:8443: i/o timeout
在向 k8s 迈出第一步的时候,你是否遇到了这样的错误:
-
Configuring RBAC rules ...| E0801 15:11:41.476443 26762 start.go:264] Unable to scale down deployment "coredns" in namespace "kube-system" to 1 replica: timed out waiting for the condition
-
Enabling 'default-storageclass' returned an error: running callbacks: [Error making standard the default storage class: Error listing StorageClasses: Get "https://192.168.49.2:8443/apis/storage.k8s.io/v1/storageclasses": dial tcp 192.168.49.2:8443: i/o timeout]
-
Exiting due to GUEST_START: wait 6m0s for node: wait for healthy API server: apiserver healthz never reported healthy: timed out waiting for the condition
问题分析
Docker Desktop for Linux 与 Docker Engine 不同,Desktop 运行于虚拟机,下面是 Docker 文档的一些解释:
其实解决这个问题很简单,minikube 提供了多种 driver,你只需要在启动时指定一种 driver 就可以,不一定非要使用 docker 作为 minikube 的 driver。点击这里查看 minikube 支持的 driver。
比如,我们可以使用 qemu 来当做 minikube 的 driver:
$ minikube start --kubernetes-version=v1.23.3 --driver=qemu --image-mirror-country='cn'
解决步骤
最简单的方法就是安装 Docker Engine,并在 docker client 中将 context 切换到 Docker Engine。
首先清理所有文件和配置
$ minikube delete --purge --all
然后查看 Docker Context,找到 Docker Engine 的 Endpoint
$ docker context ls
NAME TYPE DESCRIPTION DOCKER ENDPOINT KUBERNETES ENDPOINT ORCHESTRATOR
default moby Current DOCKER_HOST based configuration unix:///var/run/docker.sock swarm
desktop-linux * moby unix:///home/joseph/.docker/desktop/docker.sock
选择 default context
$ docker context use default
现在可以重启 minikube 之旅了
minikube start --kubernetes-version=v1.23.3 --driver=docker --image-mirror-country='cn'
😄 Ubuntu 22.04 上的 minikube v1.26.0
✨ 根据用户配置使用 docker 驱动程序
✅ 正在使用镜像存储库 registry.cn-hangzhou.aliyuncs.com/google_containers
📌 Using Docker driver with root privileges
👍 Starting control plane node minikube in cluster minikube
🚜 Pulling base image ...
> registry.cn-hangzhou.aliyun...: 386.00 MiB / 386.00 MiB 100.00% 563.66 K
🔥 Creating docker container (CPUs=2, Memory=15900MB) ...
> kubeadm: 43.12 MiB / 43.12 MiB [-----------] 100.00% 414.33 KiB p/s 1m47s
> kubectl: 44.43 MiB / 44.43 MiB [-----------] 100.00% 396.20 KiB p/s 1m55s
> kubelet: 118.75 MiB / 118.75 MiB [----------] 100.00% 652.18 KiB p/s 3m7s
▪ Generating certificates and keys ...
▪ Booting up control plane ...
▪ Configuring RBAC rules ...
🔎 Verifying Kubernetes components...
▪ Using image registry.cn-hangzhou.aliyuncs.com/google_containers/storage-provisioner:v5
🌟 Enabled addons: storage-provisioner, default-storageclass
💡 kubectl not found. If you need it, try: 'minikube kubectl -- get pods -A'
🏄 Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default