⚙️

Minikube on M1 Mac without Docker

2022/10/01に公開約8,800字

0. Prerequisite

  • Install Homebrew.
  • Minimum knowledge of Docker and Podman is preferred.

FYI:
https://brew.sh/
https://docs.podman.io/en/latest/
https://www.slideshare.net/AkihiroSuda/dockerpodman

Minikube on M1 Mac with Docker
https://zenn.dev/sbk0716/articles/3e9a8e06ed1268

PC Info

  • Information on the PC used is as follows.
OS: macOS Monterey(v12.6)
Device: MacBook Pro (13-inch, M1, 2020)
Chip: Apple M1
Memory: 16GB

1. Check Homebrew version

% which brew
/opt/homebrew/bin/brew
% brew -v
Homebrew 3.6.2
Homebrew/homebrew-core (git revision 7cb0fad3396; last commit 2022-09-19)
% 

2. Install podman with Homebrew on macOS

% brew install podman
% brew install podman-desktop
% brew list | grep podman
podman
podman-desktop
% 
% which podman
/opt/homebrew/bin/podman
% podman -v
podman version 4.2.1
% 

3. Initialize and start the virtual machine for Podman

  • Podman on MacOS and Windows requires a virtual machine.
  • podman machine init command initializes a new Linux virtual machine where containers are run.
  • podman machine start command starts a Linux virtual machine where containers are run.
% podman machine init --cpus 4 --memory 8192 --rootful
Extracting compressed file
Image resized.
Machine init complete
To start your machine run:

        podman machine start

% 
% podman machine start
Starting machine "podman-machine-default"
...
...
Machine "podman-machine-default" started successfully
% 
% podman machine ls
NAME                    VM TYPE     CREATED        LAST UP            CPUS        MEMORY      DISK SIZE
podman-machine-default  qemu        3 minutes ago  Currently running  4           8.59GB      107.4GB
% 

ERROR: RSRC_INSUFFICIENT_CORES

  • If the number of CPUs is less than 2, the following error occurs.
% podman machine ls
NAME                     VM TYPE     CREATED         LAST UP            CPUS        MEMORY      DISK SIZE
podman-machine-default*  qemu        12 minutes ago  Currently running  1           2.147GB     107.4GB
% 
% minikube start --driver=podman
😄  minikube v1.27.0 on Darwin 12.6 (arm64)
❗  Kubernetes 1.25.0 has a known issue with resolv.conf. minikube is using a workaround that should work for most use cases.
❗  For more information, see: https://github.com/kubernetes/kubernetes/issues/112135
✨  Using the podman (experimental) driver based on user configuration

⛔  Exiting due to RSRC_INSUFFICIENT_CORES: Requested cpu count 2 is greater than the available cpus of 1

% 

4. Install kubectl with Homebrew on macOS

FYI:
https://kubernetes.io/docs/tasks/tools/install-kubectl-macos/#install-with-homebrew-on-macos

% brew install kubectl
...
...
% which kubectl
/opt/homebrew/bin/kubectl
% 

5. Install minikube with Homebrew on macOS

FYI:
https://minikube.sigs.k8s.io/docs/start/

% brew install minikube
...
...
% which minikube
/opt/homebrew/bin/minikube
% minikube version
minikube version: v1.27.0
commit: 4243041b7a72319b9be7842a7d34b6767bbdac2b
% 

If the Docker Service has not been started beforehand, an error will occur when executing the command.

6. minikube start with podman driver

  • If the virtual machine for podman is not running, an error occurs when executing the minikube start command.

FYI:
https://kubernetes.io/ja/docs/setup/learning-environment/minikube/

% minikube start --driver=podman
😄  minikube v1.27.0 on Darwin 12.6 (arm64)
❗  Kubernetes 1.25.0 has a known issue with resolv.conf. minikube is using a workaround that should work for most use cases.
❗  For more information, see: https://github.com/kubernetes/kubernetes/issues/112135
✨  Using the podman (experimental) driver based on user configuration
📌  Using Podman driver with root privileges
👍  Starting control plane node minikube in cluster minikube
🚜  Pulling base image ...
E1002 04:11:17.167893   13357 cache.go:203] Error downloading kic artifacts:  not yet implemented, see issue #8426
🔥  Creating podman container (CPUs=2, Memory=4000MB) ...
🐳  Preparing Kubernetes v1.25.0 on Docker 20.10.17 ...E1002 04:13:08.392703   13357 start.go:129] Unable to get host IP: RoutableHostIPFromInside is currently only implemented for linux

    ▪ 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
% 
% kubectl version --output=yaml
clientVersion:
  buildDate: "2022-09-14T19:40:59Z"
  compiler: gc
  gitCommit: e4d4e1ab7cf1bf15273ef97303551b279f0920a9
  gitTreeState: clean
  gitVersion: v1.25.1
  goVersion: go1.19.1
  major: "1"
  minor: "25"
  platform: darwin/arm64
kustomizeVersion: v4.5.7
serverVersion:
  buildDate: "2022-08-23T17:38:15Z"
  compiler: gc
  gitCommit: a866cbe2e5bbaa01cfd5e969aa3e033f3282a8a2
  gitTreeState: clean
  gitVersion: v1.25.0
  goVersion: go1.19
  major: "1"
  minor: "25"
  platform: linux/arm64

%
% kubectl get namespace
NAME              STATUS   AGE
default           Active   113s
kube-node-lease   Active   115s
kube-public       Active   115s
kube-system       Active   115s
% 
% kubectl get nodes
NAME       STATUS   ROLES           AGE   VERSION
minikube   Ready    control-plane   13m   v1.25.0
% 
% kubectl get pods -A
NAMESPACE     NAME                               READY   STATUS    RESTARTS      AGE
kube-system   coredns-565d847f94-bp4bs           1/1     Running   0             12m
kube-system   etcd-minikube                      1/1     Running   0             13m
kube-system   kube-apiserver-minikube            1/1     Running   0             13m
kube-system   kube-controller-manager-minikube   1/1     Running   0             13m
kube-system   kube-proxy-brggr                   1/1     Running   0             12m
kube-system   kube-scheduler-minikube            1/1     Running   0             13m
kube-system   storage-provisioner                1/1     Running   1 (12m ago)   13m
% 
% kubectl get services -A
NAMESPACE     NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)                  AGE
default       kubernetes   ClusterIP   10.96.0.1    <none>        443/TCP                  13m
kube-system   kube-dns     ClusterIP   10.96.0.10   <none>        53/UDP,53/TCP,9153/TCP   13m
% 
% podman machine ls
NAME                    VM TYPE     CREATED         LAST UP            CPUS        MEMORY      DISK SIZE
podman-machine-default  qemu        32 minutes ago  Currently running  4           8.59GB      107.4GB
% podman ps        
CONTAINER ID  IMAGE                                COMMAND     CREATED         STATUS             PORTS                                                                                                                       NAMES
be9a848a2099  gcr.io/k8s-minikube/kicbase:v0.0.34              28 minutes ago  Up 28 minutes ago  0.0.0.0:44209->22/tcp, 0.0.0.0:34525->2376/tcp, 0.0.0.0:45215->5000/tcp, 0.0.0.0:33109->8443/tcp, 0.0.0.0:39931->32443/tcp  minikube
% podman ps -a
CONTAINER ID  IMAGE                                COMMAND     CREATED         STATUS             PORTS                                                                                                                       NAMES
be9a848a2099  gcr.io/k8s-minikube/kicbase:v0.0.34              29 minutes ago  Up 29 minutes ago  0.0.0.0:44209->22/tcp, 0.0.0.0:34525->2376/tcp, 0.0.0.0:45215->5000/tcp, 0.0.0.0:33109->8443/tcp, 0.0.0.0:39931->32443/tcp  minikube
% 

Screenshot
image1
image2
image3

7. Run a particular image on the minikube cluster

% kubectl run nginx --image=nginx --restart=Never
pod/nginx created
%
% kubectl get pod
NAME    READY   STATUS              RESTARTS   AGE
nginx   0/1     ContainerCreating   0          11s
% 
% kubectl exec -it nginx -- /bin/bash
root@nginx:/# 
root@nginx:/# df -h
Filesystem      Size  Used Avail Use% Mounted on
overlay         100G  4.2G   96G   5% /
tmpfs            64M     0   64M   0% /dev
/dev/vda4       100G  4.2G   96G   5% /etc/hosts
shm              64M     0   64M   0% /dev/shm
tmpfs           7.8G   12K  7.8G   1% /run/secrets/kubernetes.io/serviceaccount
tmpfs           3.9G     0  3.9G   0% /proc/acpi
tmpfs           3.9G     0  3.9G   0% /proc/scsi
tmpfs           3.9G     0  3.9G   0% /sys/firmware
root@nginx:/# 
root@nginx:/# curl -sS http://localhost | grep title
<title>Welcome to nginx!</title>
root@nginx:/# 
root@nginx:/# exit
exit
% 

Discussion

ログインするとコメントできます