今天讓我們在日常使用的 windows 桌機上安裝 minikube 吧!
minikube start
啟動 k8s cluster先大致說明一下我的桌機配備:
https://minikube.sigs.k8s.io/docs/start/?arch=/macos/arm64/stable/binary+download
參考 minikube 的官方文件,windows 有提供三種方法安裝,則一即可
我是使用最基本的安裝指令:
# 安裝 minikube
New-Item -Path 'c:\' -Name 'minikube' -ItemType Directory -Force
Invoke-WebRequest -OutFile 'c:\minikube\minikube.exe' -Uri 'https://github.com/kubernetes/minikube/releases/latest/download/minikube-windows-amd64.exe' -UseBasicParsing
# 設定環境變數,這步驟要使用 系統管理員 身分來執行
$oldPath = [Environment]::GetEnvironmentVariable('Path', [EnvironmentVariableTarget]::Machine)
if ($oldPath.Split(';') -inotcontains 'C:\minikube'){
[Environment]::SetEnvironmentVariable('Path', $('{0};C:\minikube' -f $oldPath), [EnvironmentVariableTarget]::Machine)
}
設定好之後,就可以使用 minikube
指令囉
PS C:\Users\user> minikube
minikube provisions and manages local Kubernetes clusters optimized for development workflows.
Basic Commands:
start Starts a local Kubernetes cluster
status Gets the status of a local Kubernetes cluster
stop Stops a running local Kubernetes cluster
delete Deletes a local Kubernetes cluster
dashboard Access the Kubernetes dashboard running within the minikube cluster
pause pause Kubernetes
unpause unpause Kubernetes
....
直接執行 minikube start
試試看…
這邊因為我的桌機還沒下載過 docker,因此可以發現抓預設 driver 時出錯了
PS C:\Users\user> minikube start
😄 minikube v1.33.1 on Microsoft Windows 11 Pro 10.0.22631.4037 Build 22631.4037
👎 Unable to pick a default driver. Here is what was considered, in preference order:
💡 Alternatively you could install one of these drivers:
▪ docker: Not installed: exec: "docker": executable file not found in %PATH%
▪ hyperv: Not installed: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -NonInteractive @(Get-CimInstance Win32_ComputerSystem).HypervisorPresent returned "False\r\n"
▪ virtualbox: Not installed: unable to find VBoxManage in $PATH
▪ podman: Not installed: exec: "podman": executable file not found in %PATH%
❌ Exiting due to DRV_NOT_DETECTED: No possible driver was detected. Try specifying --driver, or see https://minikube.sigs.k8s.io/docs/start/
https://docs.docker.com/desktop/install/windows-install/
安裝 docker 的步驟稍微簡述一下:
就以我目前時間安裝的版本 (2024/8) 來說,為 docker 27.1.1 版:
PS C:\Users\user> docker version
Client:
Version: 27.1.1
API version: 1.46
Go version: go1.21.12
Git commit: 6312585
Built: Tue Jul 23 19:57:57 2024
OS/Arch: windows/amd64
Context: desktop-linux
再測試執行一次 minikube start
,可以發現這次就成功了,且大約跑不到2分鐘就可以了
PS C:\Users\user> minikube start
😄 minikube v1.33.1 on Microsoft Windows 11 Pro 10.0.22631.4037 Build 22631.4037
✨ Automatically selected the docker driver. Other choices: ssh, qemu2 (experimental)
📌 Using Docker Desktop driver with root privileges
👍 Starting "minikube" primary control-plane node in "minikube" cluster
🚜 Pulling base image v0.0.44 ...
💾 Downloading Kubernetes v1.30.0 preload ...
> preloaded-images-k8s-v18-v1...: 342.90 MiB / 342.90 MiB 100.00% 5.09 Mi
> gcr.io/k8s-minikube/kicbase...: 481.58 MiB / 481.58 MiB 100.00% 5.41 Mi
🔥 Creating docker container (CPUs=2, Memory=16300MB) ...
🐳 Preparing Kubernetes v1.30.0 on Docker 26.1.1 ...
▪ Generating certificates and keys ...
▪ Booting up control plane ...
▪ Configuring RBAC rules ...
🔗 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
直接使用 kubectl
觀察看看 (這邊的 kubectl
指令是 docker desktop 預設裝的):
PS C:\Users\user> kubectl get no -o wide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
minikube Ready control-plane 15m v1.30.0 192.168.49.2 <none> Ubuntu 22.04.4 LTS 5.15.153.1-microsoft-standard-WSL2 docker://26.1.1
可以看到節點是使用 k8s 1.30.0, ubuntu 22.04
💡 比較讓人意外的是 CRI 的部分是直接使用
docker
,而非cri-dockerd
,印象中 k8s 官方文件在 v1.24 的時候特別強調後續不支援docker
了,若要繼續使用docker
當作底層就會需要掛cri-dockerd
當作 CRI 使用
這個部份我會看看有沒有相關的資訊…
直接使用 kubectl run 指令測試跑看看一個 pods
PS C:\Users\user> kubectl run test --image=nginx
pod/test created
PS C:\Users\user> kubectl get po -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
test 1/1 Running 0 6m18s 10.244.0.3 minikube <none> <none>
看起來很正常,透過 nodeport
連線看看
PS C:\Users\user> kubectl expose pod test --type=NodePort --port=80
service/test exposed
PS C:\Users\user> kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 24m
test NodePort 10.110.102.214 <none> 80:32543/TCP 2s
PS C:\Users\user> curl 192.168.49.2:32543
# 卡住了
PS C:\Users\user>
看起來我的 windows 主機沒辦法直接透過 IP 連線到 minikube 的節點上minikube
有提供 ssh
指令,試試看:
PS C:\Users\user> minikube ssh
# 進到 minikube 的環境內,可注意到 User 的變化
docker@minikube:~$ curl 192.168.49.2:32543 2> /dev/null | head -n 4
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
這樣我就可以成功連線到剛剛部署的 nginx 測試 container 囉 ~
💡 這裡其實如果有仔細看 minikube 的文件,會發現在 https://minikube.sigs.k8s.io/docs/handbook/accessing/ 這篇裡面有提到
minikube service
這個指令,在上面的例子使用後會直接在 windows 上打開一個 port,並且會直接開啟瀏覽器,就可以看到 nginx 的介紹頁面了
文件... 真的要仔細看啊!! (汗)
礙於篇幅的關係,明天會再介紹一些 minikube 的有趣功能。
透過 minikube 工具,可以很快速的在各平台上面建立一個測試用的 k8s cluster
https://docs.docker.com/desktop/install/windows-install/
https://minikube.sigs.k8s.io/docs/start/?arch=/macos/arm64/stable/binary+download