Skip to content

Instantly share code, notes, and snippets.

@mangreen
Last active July 2, 2021 03:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mangreen/294bda9f4d9ca98b3d1f99cffe19c78b to your computer and use it in GitHub Desktop.
Save mangreen/294bda9f4d9ca98b3d1f99cffe19c78b to your computer and use it in GitHub Desktop.
Mac 安裝 minikube
https://cloud.tencent.com/developer/article/1047278
https://kubernetes.io/docs/tutorials/hello-minikube/
https://maiyang.me/post/2018-07-31-minikube-guide-in-mac/
使用 minikube
OS:macOS
GitHub:https://github.com/khs1994-docker/minikube
GitHub: https://github.com/kubernetes/minikube
修訂記錄
2018-01-15:請在之前看過我文章的務必按照本文重新安裝配置 minikube
2018-01-15:由於阿里雲的 localkube 出現問題(已反饋給相關人員),暫時只能使用我編譯的 localkube。
鏡像列表
gcr.io/google_containers/kubernetes-dashboard-amd64 v1.8.0 55dbc28356f2 6 weeks ago 119MB
gcr.io/k8s-minikube/storage-provisioner v1.8.1 4689081edb10 2 months ago 80.8MB
gcr.io/google_containers/k8s-dns-sidecar-amd64 1.14.5 fed89e8b4248 3 months ago 41.8MB
gcr.io/google_containers/k8s-dns-kube-dns-amd64 1.14.5 512cd7425a73 3 months ago 49.4MB
gcr.io/google_containers/k8s-dns-dnsmasq-nanny-amd64 1.14.5 459944ce8cc4 3 months ago 41.4MB
gcr.io/google-containers/kube-addon-manager v6.4-beta.2 0a951668696f 7 months ago 79.2MB
gcr.io/google_containers/pause-amd64 3.0 99e59f495ffa 20 months ago 747kB
本人也是初學 minikube,本文基於 minikube 0.24.1 版本。
如果我們直接使用從 https://github.com/kubernetes/minikube 下載的 minikube 你可能會發現根本不能運行成功。
這是因為它要從 gcr.io 拉取鏡像,而國內網絡問題導致鏡像下載不了,當然也就不能啟動了。
知道為什麼成功不了,那我們就替換源碼中的國外鏡像為國內鏡像源(阿里雲)。
具體要變更哪些文件請看 GitHub
我已經把變更過的文件上傳到了 GitHub,本文以這個 git 倉庫為源碼,重新編譯 minikube
安裝 kubectl
注意,由於網絡問題,從官網下載極有可能下載失敗。你可以使用瀏覽器在國內鏡像下載之後移入 PATH https://github.com/khs1994-docker/kubectl-cn-mirror
使用 minikube 必須先安裝好 k8s 命令行工具 kubectl。
macOS
Docker for Mac 17.12+ 啟用 k8s 之後會在 /usr/local/bin 放入 kubectl,所以你無需安裝。
Docker for Mac 自帶的 k8s 會與 minikube 衝突,請以下命令進行切換。
$ kubectl config get-contexts
CURRENT NAME CLUSTER AUTHINFO NAMESPACE
docker-for-desktop docker-for-desktop-cluster docker-for-desktop
* minikube minikube minikube
# 切換到 docker 自帶的 k8s
$ kubectl config use-context docker-for-desktop
# 切換到 minikube
$ kubectl config use-context minikube
如果你沒啟用 k8s 那麼請使用下面的方法。
$ brew install kubectl
curl
或者使用 curl 下載。
bash
# OS X
$ curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/darwin/amd64/kubectl
# Linux
$ curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
# Windows
$ curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/windows/amd64/kubectl.exe
fish
# OS X
$ curl -LO https://storage.googleapis.com/kubernetes-release/release/(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/darwin/amd64/kubectl
# Linux
$ curl -LO https://storage.googleapis.com/kubernetes-release/release/(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
# Windows
$ curl -LO https://storage.googleapis.com/kubernetes-release/release/(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/windows/amd64/kubectl.exe
重新安裝 minikube 國內版
注意:國內從 GitHub 下載文件可能較慢,你可以在國內鏡像下載之後移入 PATH https://code.aliyun.com/khs1994-docker/minikube/tree/v1.8.0
你可以選擇 編譯安裝 或者 下載安裝。為了避免混亂,編譯安裝的方法,放到了文章最後。
直接下載安裝
你可以根據你的操作系統,下載對應的二進制文件。你也可以在命令行使用 curl 下載。
https://github.com/khs1994-docker/minikube/releases
bash
$ curl -LO https://github.com/khs1994-docker/minikube/releases/download/v0.24.1/minikube-`uname -s`-`uname -m`
$ chmod +x minikube-`uname -s`-`uname -m`
$ sudo cp minikube-`uname -s`-`uname -m` /usr/local/bin/minikube
fish
$ curl -LO https://github.com/khs1994-docker/minikube/releases/download/v0.24.1/minikube-(uname -s)-(uname -m)
$ chmod +x minikube-(uname -s)-(uname -m)
$ sudo cp minikube-(uname -s)-(uname -m) /usr/local/bin/minikube
虛擬機驅動
https://github.com/kubernetes/minikube/blob/master/docs/drivers.md
macOS 上默認的驅動是 VirtualBox,但是我們這裡選擇 hyperkit。
注意,你可能看到一些舊教程使用了 xhyve,如果你使用這個驅動,啟動時 minikube 會提示你該驅動已經廢棄。
WARNING: The xhyve driver is now deprecated and support for it will be removed in a future release.
Please consider switching to the hyperkit driver, which is intended to replace the xhyve driver.
$ curl -LO https://github.com/kubernetes/minikube/releases/download/v0.24.1/docker-machine-driver-hyperkit
$ chmod +x docker-machine-driver-hyperkit
$ sudo mv docker-machine-driver-hyperkit /usr/local/bin/
$ sudo chown root:wheel /usr/local/bin/docker-machine-driver-hyperkit
$ sudo chmod u+s /usr/local/bin/docker-machine-driver-hyperkit
這樣我們就安裝好了驅動。
啟動
$ minikube start --vm-driver=hyperkit --alsologtostderr --v 10
選擇一種驅動之後,不要再改變,否則可能會啟動失敗。
錯誤排查
若啟動時出現錯誤,請執行以下命令刪除本地集群,再重新執行啟動命令。
$ minikube delete
如果仍然出現錯誤請刪除 ~/.minikube,再重新執行啟動命令。
使用方法
打開控制面板
$ minikube dashboard
Opening kubernetes dashboard in default browser...
之後會自動打開瀏覽器頁面。
查看 IP
$ minikube ip
192.168.64.12
查看狀態
$ minikube status
minikube: Running
cluster: Running
kubectl: Correctly Configured: pointing to minikube-vm at 192.168.64.12
查看集群
$ kubectl cluster-info
Kubernetes master is running at https://192.168.64.12:8443
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
更多方法請查看後續文章。
關閉
$ minikube stop
附錄
Windows 啟動 minikube
自行在上面提到的 GitHub 或 國內鏡像 下載好 kubectl.exe minikube.exe,並加入 PATH
配置 Hyper-V,具體圖解請查看:https://yq.aliyun.com/articles/221687
$ minikube.exe start --registry-mirror=https://registry.docker-cn.com --vm-driver="hyperv" --memory=4096 --hyperv-virtual-switch="minikube"
編譯安裝 minikube
注意:編譯安裝適用於對 Go 有一定瞭解的人。
安裝 Go
$ brew install go
設置 Go 相關環境變量,自行修改為你自己的路徑。
GOROOT="/usr/local/opt/go/libexec"
GOPATH="/Users/khs1994/go"
編譯安裝
$ git clone -b 0.24.1 --depth=1 git@github.com:khs1994-docker/minikube.git $GOPATH/src/k8s.io/minikube
$ cd $GOPATH/src/k8s.io/minikube
$ make
$ sudo cp out/minikube /usr/local/bin
More Information
https://github.com/kubernetes/minikube
https://github.com/AliyunContainerService/minikube
https://yq.aliyun.com/articles/221687
https://github.com/oucb/minikube
http://wiselyman.iteye.com/blog/2381738
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment