'Unable to start minikube on Mac M1 with docker

I'm trying to start minikube on a Mac M1 (macOs Monterey V12.0.1) after installing minikube with homebrew (brew install minikube) but I am getting an error after running minikube start.

The error in the logs is this one:

💢  initialization failed, will try again: wait: /bin/bash -c "sudo env PATH="/var/lib/minikube/binaries/v1.22.3:$PATH" kubeadm init --config /var/tmp/minikube/kubeadm.yaml  --ignore-preflight-errors=DirAvailable--etc-kubernetes-manifests,DirAvailable--var-lib-minikube,DirAvailable--var-lib-minikube-etcd,FileAvailable--etc-kubernetes-manifests-kube-scheduler.yaml,FileAvailable--etc-kubernetes-manifests-kube-apiserver.yaml,FileAvailable--etc-kubernetes-manifests-kube-controller-manager.yaml,FileAvailable--etc-kubernetes-manifests-etcd.yaml,Port-10250,Swap,Mem,SystemVerification,FileContent--proc-sys-net-bridge-bridge-nf-call-iptables": Process exited with status 1
stdout:
[init] Using Kubernetes version: v1.22.3
[preflight] Running pre-flight checks

stderr:
    [WARNING Swap]: running with swap on is not supported. Please disable swap
    [WARNING Service-Kubelet]: kubelet service is not enabled, please run 'systemctl enable kubelet.service'
error execution phase preflight: [preflight] Some fatal errors occurred:
    [ERROR KubeletVersion]: couldn't get kubelet version: cannot execute 'kubelet --version': exit status 255
[preflight] If you know what you are doing, you can make a check non-fatal with `--ignore-preflight-errors=...`
To see the stack trace of this error execute with --v=5 or higher


💣  Error starting cluster: wait: /bin/bash -c "sudo env PATH="/var/lib/minikube/binaries/v1.22.3:$PATH" kubeadm init --config /var/tmp/minikube/kubeadm.yaml  --ignore-preflight-errors=DirAvailable--etc-kubernetes-manifests,DirAvailable--var-lib-minikube,DirAvailable--var-lib-minikube-etcd,FileAvailable--etc-kubernetes-manifests-kube-scheduler.yaml,FileAvailable--etc-kubernetes-manifests-kube-apiserver.yaml,FileAvailable--etc-kubernetes-manifests-kube-controller-manager.yaml,FileAvailable--etc-kubernetes-manifests-etcd.yaml,Port-10250,Swap,Mem,SystemVerification,FileContent--proc-sys-net-bridge-bridge-nf-call-iptables": Process exited with status 1
stdout:
[init] Using Kubernetes version: v1.22.3
[preflight] Running pre-flight checks

stderr:
    [WARNING Swap]: running with swap on is not supported. Please disable swap
    [WARNING Service-Kubelet]: kubelet service is not enabled, please run 'systemctl enable kubelet.service'
error execution phase preflight: [preflight] Some fatal errors occurred:
    [ERROR KubeletVersion]: couldn't get kubelet version: cannot execute 'kubelet --version': exit status 255
[preflight] If you know what you are doing, you can make a check non-fatal with `--ignore-preflight-errors=...`
To see the stack trace of this error execute with --v=5 or higher


╭───────────────────────────────────────────────────────────────────────────────────────────╮
│                                                                                           │
│    😿  If the above advice does not help, please let us know:                             │
│    👉  https://github.com/kubernetes/minikube/issues/new/choose                           │
│                                                                                           │
│    Please run `minikube logs --file=logs.txt` and attach logs.txt to the GitHub issue.    │
│                                                                                           │
╰───────────────────────────────────────────────────────────────────────────────────────────╯

❌  Exiting due to GUEST_START: wait: /bin/bash -c "sudo env PATH="/var/lib/minikube/binaries/v1.22.3:$PATH" kubeadm init --config /var/tmp/minikube/kubeadm.yaml  --ignore-preflight-errors=DirAvailable--etc-kubernetes-manifests,DirAvailable--var-lib-minikube,DirAvailable--var-lib-minikube-etcd,FileAvailable--etc-kubernetes-manifests-kube-scheduler.yaml,FileAvailable--etc-kubernetes-manifests-kube-apiserver.yaml,FileAvailable--etc-kubernetes-manifests-kube-controller-manager.yaml,FileAvailable--etc-kubernetes-manifests-etcd.yaml,Port-10250,Swap,Mem,SystemVerification,FileContent--proc-sys-net-bridge-bridge-nf-call-iptables": Process exited with status 1
stdout:
[init] Using Kubernetes version: v1.22.3
[preflight] Running pre-flight checks

stderr:
    [WARNING Swap]: running with swap on is not supported. Please disable swap
    [WARNING Service-Kubelet]: kubelet service is not enabled, please run 'systemctl enable kubelet.service'
error execution phase preflight: [preflight] Some fatal errors occurred:
    [ERROR KubeletVersion]: couldn't get kubelet version: cannot execute 'kubelet --version': exit status 255
[preflight] If you know what you are doing, you can make a check non-fatal with `--ignore-preflight-errors=...`
To see the stack trace of this error execute with --v=5 or higher


╭───────────────────────────────────────────────────────────────────────────────────────────╮
│                                                                                           │
│    😿  If the above advice does not help, please let us know:                             │
│    👉  https://github.com/kubernetes/minikube/issues/new/choose                           │
│                                                                                           │
│    Please run `minikube logs --file=logs.txt` and attach logs.txt to the GitHub issue.    │
│                                                                                           │
╰───────────────────────────────────────────────────────────────────────────────────────────╯

I have tried enabling kubelet.service by running sysctl enable kubelet.service but didn't change anything. I have also kubeclt version 1.22 installed.



Solution 1:[1]

I was able to find the solution to my problem, although, I'm not really sure what was the main issue, it seems that it was related to old configurations in the .minikube folder in the users' home directory.

To fix it, first I had to enabled Kubernetes in docker desktop, and then I had to stop and delete minikube cluster, and finally delete the directory. Then running the command again was successful.

To fix:

$ minikube stop
$ minikube delete
$ rm -rf ~/.minikube/
$ minikube start

?  minikube v1.24.0 on Darwin 12.0.1 (arm64)
?  Automatically selected the docker driver
?  Starting control plane node minikube in cluster minikube
?  Pulling base image ...
?  Creating docker container (CPUs=2, Memory=1988MB) ...
    > kubectl.sha256: 64 B / 64 B [--------------------------] 100.00% ? p/s 0s
    > kubelet.sha256: 64 B / 64 B [--------------------------] 100.00% ? p/s 0s
    > kubeadm.sha256: 64 B / 64 B [--------------------------] 100.00% ? p/s 0s
    > kubeadm: 40.50 MiB / 40.50 MiB [-------------] 100.00% 29.75 MiB p/s 1.6s
    > kubectl: 41.44 MiB / 41.44 MiB [-------------] 100.00% 21.39 MiB p/s 2.1s
    > kubelet: 107.26 MiB / 107.26 MiB [-----------] 100.00% 27.70 MiB p/s 4.1s

    ? Generating certificates and keys ...
    ? Booting up control plane ...
    ? Configuring RBAC rules ...
?  Verifying Kubernetes components...
    ? Using image gcr.io/k8s-minikube/storage-provisioner:v5
?  Enabled addons: storage-provisioner, default-storageclass
?  Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default

Solution 2:[2]

First the Mac Machine is enabling swap by default. You have to disable swap then retry to start minikube

Steps to disable swap in MacBook:

  • 1. Disable SIP:

  • Power-off MacBook first,

  • hold Command (?) and R, and then start-up the MacBook. (For M1 chip based MacBook, hold the power button until seeing “Loading startup options”). You should see a macOS utilities window.

  • From the utilities menu, select “Terminal” then, Run csrutil disable the screen should display a message that SIP is already disabled. enter image description here

  • From the ? menu, press restart to restart MacBook.

  • 2. Disable swap

  • open The macbook terminal

  • check the current mode that system manages memory, type sysctl -a vm.compressor_mode in terminal.

  • The default mode is 4, which represents compressing memory and using swap. To disable swap, we should change the mode from 4 to 2, which means compressing memory only.

  • modify vm.compressor_mode, type sudo nvram boot-args="vm_compressor=2". The mode won’t be changed until reboot. -reboot

Again, anyone running computer without swap file should monitor memory usage carefully to avoid kernel panic!

  • 3. Minikube start:

$ minikube stop
$ minikube delete
$ rm -rf ~/.minikube/
$ minikube start

Solution 3:[3]

To anyone coming across this problem:

  1. Make sure you're using the arm64 binary of minikube
  2. Run minikube delete --all --purge
  3. Try starting minikube again

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Cesar Flores
Solution 2 Ahmed Badawy
Solution 3 eliarms