2023年9月3日 星期日

Kubernetes/k8s 開發筆記 - 在 Macbook M1 Pro 安裝 minikube, qemu, socket_vmnet @ macOS 13.5.1


之前略知 Apple M1 架構,對於使用一些軟體服務會卡卡,終於來體驗一下。原先在考慮依照官網的簡介:


後來決定都靠 Homebrew 來管理,安裝流程:

% sw_vers
ProductName: macOS
ProductVersion: 13.5.1
BuildVersion: 22G90

% brew --version
Homebrew 4.1.7

% brew install qemu socket_vmnet minikube
Error: Cannot install in Homebrew on ARM processor in Intel default prefix (/usr/local)!
Please create a new installation in /opt/homebrew using one of the
"Alternative Installs" from:
  https://docs.brew.sh/Installation
You can migrate your previously installed formula list with:
  brew bundle dump

% eval "$(/opt/homebrew/bin/brew shellenv)"

% brew install qemu socket_vmnet  minikube

...
socket_vmnet requires root privileges so you will need to run
  `sudo /opt/homebrew/opt/socket_vmnet/socket_vmnet` or `sudo brew services start socket_vmnet`.
You should be certain that you trust any software you grant root privileges.

socket_vmnet is keg-only, which means it was not symlinked into /opt/homebrew,
because Homebrew's bin directory is often writable by a non-admin user.

If you need to have socket_vmnet first in your PATH, run:
  echo 'export PATH="/opt/homebrew/opt/socket_vmnet/bin:$PATH"' >> ~/.zshrc

To start socket_vmnet now and restart at startup:
  sudo brew services start socket_vmnet
Or, if you don't want/need a background service you can just run:
  /opt/homebrew/opt/socket_vmnet/bin/socket_vmnet --vmnet-gateway\=192.168.105.1 /opt/homebrew/var/run/socket_vmnet
...

% sudo brew services start socket_vmnet
Service `socket_vmnet` already started, use `brew services restart socket_vmnet` to restart.

% minikube start --driver=qemu --network socket_vmnet
😄  minikube v1.31.2 on Darwin 13.5.1 (arm64)
✨  Using the qemu2 driver based on user configuration
👍  Starting control plane node minikube in cluster minikube
🔥  Creating qemu2 VM (CPUs=2, Memory=6000MB, Disk=20000MB) ...
🐳  Preparing Kubernetes v1.27.4 on Docker 24.0.4 ...
    ▪ Generating certificates and keys ...
    ▪ Booting up control plane ...
    ▪ Configuring RBAC rules ...
🔗  Configuring bridge CNI (Container Networking Interface) ...
    ▪ Using image gcr.io/k8s-minikube/storage-provisioner:v5
🔎  Verifying Kubernetes components...
🌟  Enabled addons: default-storageclass, storage-provisioner
🏄  Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default

% minikube status
minikube
type: Control Plane
host: Running
kubelet: Running
apiserver: Running
kubeconfig: Configured

% minikube stop  
✋  Stopping node "minikube"  ...
🛑  1 node stopped.

% minikube status
minikube
type: Control Plane
host: Stopped
kubelet: Stopped
apiserver: Stopped
kubeconfig: Stopped

然後重開機後,進入 zsh 環境時,需要重新做一點設定,就看個人的習慣要不要安置自動化了:

% minikube status
zsh: command not found: minikube
% eval "$(/opt/homebrew/bin/brew shellenv)"
% minikube status
🤷  Profile "minikube" not found. Run "minikube profile list" to view all profiles.
👉  To start a cluster, run: "minikube start"

% minikube start --driver=qemu --network socket_vmnet
😄  minikube v1.31.2 on Darwin 13.5.1 (arm64)
✨  Using the qemu2 driver based on user configuration
👍  Starting control plane node minikube in cluster minikube
🔥  Creating qemu2 VM (CPUs=2, Memory=6000MB, Disk=20000MB) ...\ OUTPUT: 
ERROR: Failed to connect to "/opt/homebrew/var/run/socket_vmnet": Connection refused


🔥  Deleting "minikube" in qemu2 ...
🤦  StartHost failed, but will try again: creating host: create: creating: Failed to connect to "/opt/homebrew/var/run/socket_vmnet": Connection refused: exit status 1
🔥  Creating qemu2 VM (CPUs=2, Memory=6000MB, Disk=20000MB) ...\ OUTPUT: 
ERROR: Failed to connect to "/opt/homebrew/var/run/socket_vmnet": Connection refused


😿  Failed to start qemu2 VM. Running "minikube delete" may fix it: creating host: create: creating: Failed to connect to "/opt/homebrew/var/run/socket_vmnet": Connection refused: exit status 1

❌  Exiting due to GUEST_PROVISION: error provisioning guest: Failed to start host: creating host: create: creating: Failed to connect to "/opt/homebrew/var/run/socket_vmnet": Connection refused: exit status 1

╭───────────────────────────────────────────────────────────────────────────────────────────╮
│                                                                                           │
│    😿  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.    │
│                                                                                           │
╰───────────────────────────────────────────────────────────────────────────────────────────╯

% sudo brew services restart socket_vmnet
Password:
Stopping `socket_vmnet`... (might take a while)
==> Successfully stopped `socket_vmnet` (label: homebrew.mxcl.socket_vmnet)
Warning: Taking root:admin ownership of some socket_vmnet paths:
  /opt/homebrew/Cellar/socket_vmnet/1.1.2/bin
  /opt/homebrew/Cellar/socket_vmnet/1.1.2/bin/socket_vmnet
  /opt/homebrew/opt/socket_vmnet
  /opt/homebrew/opt/socket_vmnet/bin
This will require manual removal of these paths using `sudo rm` on
brew upgrade/reinstall/uninstall.
==> Successfully started `socket_vmnet` (label: homebrew.mxcl.socket_vmnet)

% minikube delete

% minikube start --driver=qemu --network socket_vmnet
😄  minikube v1.31.2 on Darwin 13.5.1 (arm64)
✨  Using the qemu2 driver based on user configuration
👍  Starting control plane node minikube in cluster minikube
🔥  Creating qemu2 VM (CPUs=2, Memory=6000MB, Disk=20000MB) ...
🐳  Preparing Kubernetes v1.27.4 on Docker 24.0.4 ...
    ▪ Generating certificates and keys ...
    ▪ Booting up control plane ...
    ▪ Configuring RBAC rules ...
🔗  Configuring bridge CNI (Container Networking Interface) ...
    ▪ Using image gcr.io/k8s-minikube/storage-provisioner:v5
🔎  Verifying Kubernetes components...
🌟  Enabled addons: storage-provisioner, default-storageclass
🏄  Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default

% minikube status
minikube
type: Control Plane
host: Running
kubelet: Running
apiserver: Running
kubeconfig: Configured

上述是因為筆電重啟後時,碰到 socket_vmnet 問題,最後就先試著把整套環境刪除 (minikube delete) 而重來,而後續常規的用法:

% eval "$(/opt/homebrew/bin/brew shellenv)"

% sudo brew services restart socket_vmnet  
Warning: Taking root:admin ownership of some socket_vmnet paths:
  /opt/homebrew/Cellar/socket_vmnet/1.1.2/bin
  /opt/homebrew/Cellar/socket_vmnet/1.1.2/bin/socket_vmnet
  /opt/homebrew/opt/socket_vmnet
  /opt/homebrew/opt/socket_vmnet/bin
This will require manual removal of these paths using `sudo rm` on
brew upgrade/reinstall/uninstall.
==> Successfully started `socket_vmnet` (label: homebrew.mxcl.socket_vmnet)

% minikube start --driver=qemu --network socket_vmnet
😄  minikube v1.31.2 on Darwin 13.5.1 (arm64)
✨  Using the qemu2 driver based on existing profile
👍  Starting control plane node minikube in cluster minikube
🔄  Restarting existing qemu2 VM for "minikube" ...
🐳  Preparing Kubernetes v1.27.4 on Docker 24.0.4 ...
🔗  Configuring bridge CNI (Container Networking Interface) ...
🔎  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

% minikube status
minikube
type: Control Plane
host: Running
kubelet: Running
apiserver: Running
kubeconfig: Configured

沒有留言:

張貼留言