使用 Minikube 在 macOS 安裝 & 學習的筆記。
除了 minikube,也可以試看看 k3s , Docker Desktop , MicroK8s
在 macOS 安裝 Minikube 安裝 kubectl 安裝 kubectl
for macOS: https://kubernetes.io/docs/tasks/tools/install-kubectl/
1 2 3 4 ~ curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/darwin/amd64/kubectl ~ chmod +x ./kubectl ~ sudo mv ./kubectl /usr/local/bin/kubectl
安裝 virtualbox and minikube
安裝 VirtualBox: https://www.virtualbox.org/wiki/Downloads
安裝 minikube: brew cask install minikube
1 2 3 4 5 6 7 8 9 10 11 12 ~ brew install minikube ==> Satisfying dependencies All Formula dependencies satisfied. ==> Downloading https://storage.googleapis.com/minikube/releases/v1.4.0/minikube-darwin-amd64 Already downloaded: /Users/rick/Library/Caches/Homebrew/downloads/33746757457a7cbfeecb9411a4eabfd65bfbdf8b8b0e4eeec1f623464cf976c3--minikube-darwin-amd64 ==> Verifying SHA-256 checksum for Cask 'minikube' . ==> Uninstalling Cask minikube ==> Purging files for version 1.4.0 of Cask minikube ==> Installing Cask minikube ==> Linking Binary 'minikube-darwin-amd64' to '/usr/local/bin/minikube' . 🍺 minikube was successfully installed! ~
啟動 啟動 Minikube 第一次跑要等一下,他會在 virtualbox
建立新的 vm instance
指令:minikube start
1 2 3 4 5 6 7 8 9 10 11 12 13 ~ minikube start --vm-driver=virtualbox 😄 minikube v1.4.0 on Darwin 10.14.2 💿 Downloading VM boot image ... > minikube-v1.4.0.iso.sha256: 65 B / 65 B [--------------] 100.00% ? p/s 0s > minikube-v1.4.0.iso: 135.73 MiB / 135.73 MiB [-] 100.00% 6.03 MiB p/s 23s 🔥 Creating virtualbox VM (CPUs=2, Memory=2000MB, Disk=20000MB) ... 🐳 Preparing Kubernetes v1.16.0 on Docker 18.09.9 ... 💾 Downloading kubelet v1.16.0 💾 Downloading kubeadm v1.16.0 🚜 Pulling images ... 🚀 Launching Kubernetes ... ⌛ Waiting for : apiserver proxy etcd scheduler controller dns 🏄 Done! kubectl is now configured to use "minikube"
指定 VM driver: minikube start --vm-driver=virtualbox
如果無法正常啟動,先清除: minikube delete
設定記憶體與 cpu: minikube start --memory=16384 --cpus=4 --kubernetes-version=v1.14.2
指定 vm-driver:
brew install docker-machine-driver-vmware
minikube start –driver=vmware –memory=16384 –cpus=4
minikube config set driver vmware
取得狀態 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 ~ minikube status host: Running kubelet: Running apiserver: Running kubectl: Correctly Configured: pointing to minikube-vm at 192.168.99.100 ~ kubectl cluster-info Kubernetes master is running at https://192.168.99.100:8443 KubeDNS is running at https://192.168.99.100:8443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy To further debug and diagnose cluster problems, use 'kubectl cluster-info dump' . ~ kubectl version Client Version: version.Info{Major:"1" , Minor:"14+" , GitVersion:"v1.14.6-eks-5047ed" , GitCommit:"5047edce664593832e9b889e447ac75ab104f527" , GitTreeState:"clean" , BuildDate:"2019-08-22T06:44:59Z" , GoVersion:"go1.12.9" , Compiler:"gc" , Platform:"darwin/amd64" } Server Version: version.Info{Major:"1" , Minor:"16" , GitVersion:"v1.16.0" , GitCommit:"2bd9643cee5b3b3a5ecbd3af49d09018f0773c77" , GitTreeState:"clean" , BuildDate:"2019-09-18T14:27:17Z" , GoVersion:"go1.12.9" , Compiler:"gc" , Platform:"linux/amd64" } ~ kubectl get no -o wide NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME minikube Ready master 31m v1.16.0 10.0.2.15 <none> Buildroot 2018.05.3 4.15.0 docker://18.9.9 ~ kubectl get po --all-namespaces NAMESPACE NAME READY STATUS RESTARTS AGE kube-system coredns-5644d7b6d9-m25bv 1/1 Running 1 30m kube-system coredns-5644d7b6d9-s7jmt 1/1 Running 1 30m kube-system etcd-minikube 1/1 Running 1 28m kube-system kube-addon-manager-minikube 1/1 Running 1 28m kube-system kube-apiserver-minikube 1/1 Running 1 29m kube-system kube-controller-manager-minikube 1/1 Running 1 28m kube-system kube-proxy-nms9l 1/1 Running 1 30m kube-system kube-scheduler-minikube 1/1 Running 1 28m kube-system storage-provisioner 1/1 Running 2 29m kubernetes-dashboard dashboard-metrics-scraper-76585494d8-wdrdx 1/1 Running 1 29m kubernetes-dashboard kubernetes-dashboard-57f4cb4545-w298w 1/1 Running 2 29m
版本資訊 1 2 3 ~ minikube version minikube version: v1.4.0 commit: 7969c25a98a018b94ea87d949350f3271e9d64b6
Run “Hello” App 啟動 echoserver
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 ~ kubectl run hello-minikube \ --image=gcr.io/google_containers/echoserver:1.4 \ --port=8080 deployment "hello-minikube" created ~ kubectl get pod NAME READY STATUS RESTARTS AGE hello-minikube-938614450-50h7g 1/1 Running 0 3m 11:15:05 gtcafe-dev.rickhwang-dev minikube ~ kubectl expose deployment \ hello-minikube --type =NodePort service "hello-minikube" exposed ~ curl $(minikube service hello-minikube --url) CLIENT VALUES: client_address=172.17.0.1 command =GETreal path=/ query=nil request_version=1.1 request_uri=http://192.168.99.100:8080/ SERVER VALUES: server_version=nginx: 1.10.0 - lua: 10001 HEADERS RECEIVED: accept=*/* host=192.168.99.100:30459 user-agent=curl/7.51.0 BODY: -no body in request-
Uninstall minikube or upgrade K8s version 如果想要升級 k8s 版本、或者升級 minikube,最簡單的方法就是直接重新安裝。底下是在 macOS 從重新安裝 minikube 開始:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ~$ minikube delete 🔥 Deleting "minikube" in vmware ... 💀 Removed all traces of the "minikube" cluster. ~$ rm -rf /usr/local/bin/minikube brew update brew reinstall minikube
延伸閱讀 站內文章
參考資料
學習資源
更新紀錄