mac 配置阿里雲鏡像安裝minikube

一 官網安裝

 官網: https://minikube.sigs.k8s.io/

搜了下網上如何通過Mac 安裝看網上文章很多,但是受限於國內網絡環境,很多都不行,各種下載失敗。如果你有VPN,那麼官方的步驟就容易走通:

$ brew install kubectl    
$ brew install minikube     
$ brew install docker-machine-driver-hyperkit
$ sudo chown root:wheel /usr/local/opt/docker-machine-driver-hyperkit/bin/docker-machine-driver-hyperkit
$ sudo chmod u+s /usr/local/opt/docker-machine-driver-hyperkit/bin/docker-machine-driver-hyperkit
$ minikube start --vm-driver hyperkit

注意點:

  • xhyve 已經不支持了。提示:darwin 不支持驅動程序“xhyve”
  • 舊文檔的brew cask install minikube  不推薦了,

    報錯:Cask 'minikube' is unavailable: No Cask with this name exists.   去掉cask直接安裝。

brew 本質是也是一整拉取Git的方式,所以還是想用不適用proxy的情況下如何安裝k8s.

我們需要安裝三樣東西:Kubernetes 的命令行客戶端 kubctl、一個可以在本地跑起來的 Kubernetes 環境 Minikube、以及給 Minikube 使用的虛擬化引擎hyperkit.

二  安裝步驟:

  

安裝minikube

curl -Lo minikube https://github.com/kubernetes/minikube/releases/download/v1.6.2/minikube-darwin-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/
這是阿里雲版本:
curl -Lo minikube http://kubernetes.oss-cn-hangzhou.aliyuncs.com/minikube/releases/v0.30.0/minikube-darwin-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/

輸出版本號:minikube version

minikube version: v1.6.2
commit: 54f28ac5d3a815d1196cd5d57d707439ee4bb392

安裝 hyperkit

curl -LO https://storage.googleapis.com/minikube/releases/latest/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

 安裝kubectl

brew install kubectl
brew install docker-machine-driver-hyperkit

輸出kubectl --help 信息就OK

三 啓動

   這個也很關鍵,網上默認的啓動報錯:

Darwin 10.14.6 上的 minikube v1.6.2

  Selecting 'hyperkit' driver from user configuration (alternates: [])

  正在下載驅動 docker-machine-driver-hyperkit:

    > docker-machine-driver-hyperkit.sha256: 65 B / 65 B [---] 100.00% ? p/s 0s

    > docker-machine-driver-hyperkit: 628.54 KiB / 10.81 MiB  5.68% 1.71 KiB p/

  Unable to update hyperkit driver: download failed: https://github.com/kubernetes/minikube/releases/download/v1.6.2/docker-machine-driver-hyperkit?checksum=file:https://github.com/kubernetes/minikube/releases/download/v1.6.2/docker-machine-driver-hyperkit.sha256: read tcp 192.168.16.30:58130->52.216.142.4:443: read: connection reset by peer

  正在創建 hyperkit 虛擬機(CPUs=2,Memory=2000MB, Disk=20000MB)...

panic: runtime error: invalid memory address or nil pointer dereference

[signal SIGSEGV: segmentation violation code=0x1 addr=0x28 pc=0x4ecd70f]

 

goroutine 150 [running]:

github.com/google/go-containerregistry/pkg/v1/tarball.Write(0x0, 0xc0006b2780, 0xa, 0xc0006b278b, 0xe, 0xc0006b279a, 0x7, 0x0, 0x0, 0xc000871c68, ...)

 /private/tmp/minikube-20191220-77113-wmp8w9/.brew_home/go/pkg/mod/github.com/google/[email protected]/pkg/v1/tarball/write.go:57 +0x12f

k8s.io/minikube/pkg/minikube/machine.CacheImage(0xc0006b2780, 0x21, 0xc0006f59f0, 0x45, 0x0, 0x0)

 /private/tmp/minikube-20191220-77113-wmp8w9/pkg/minikube/machine/cache_images.go:395 +0x5df

k8s.io/minikube/pkg/minikube/machine.CacheImages.func1(0xc000028f68, 0x0)

 /private/tmp/minikube-20191220-77113-wmp8w9/pkg/minikube/machine/cache_images.go:85 +0x124

golang.org/x/sync/errgroup.(*Group).Go.func1(0xc000728fc0, 0xc000729020)

 /private/tmp/minikube-20191220-77113-wmp8w9/.brew_home/go/pkg/mod/golang.org/x/[email protected]/errgroup/errgroup.go:57 +0x64

created by golang.org/x/sync/errgroup.(*Group).Go

 /private/tmp/minikube-20191220-77113-wmp8w9/.brew_home/go/pkg/mod/golang.org/x/[email protected]/errgroup/errgroup.go:54 +0x66

這裏需要在阿里雲有賬戶,開通鏡像加速。

minikube start --image-mirror-country=cn   --iso-url=https://kubernetes.oss-cn-hangzhou.aliyuncs.com/minikube/iso/minikube-v1.6.2.iso  --registry-mirror=https://XXXX.mirror.aliyuncs.com  --image-repository=registry.cn-hangzhou.aliyuncs.com/google_containers

參數對應的含義:

  • --image-mirror-country cn 將缺省利用 registry.cn-hangzhou.aliyuncs.com/google_containers 作爲安裝Kubernetes的容器鏡像倉庫,
  • --iso-url=*** 利用阿里雲的鏡像地址下載相應的 .iso 文件
  • --registry-mirror= 就是你在阿里雲的鏡像加速地址,必須的,不然很慢。
  • --image-repository=  不選擇會提示VM is unable to access k8s.gcr.io, you may need to configure a proxy or set --image-repository

😄  Darwin 10.14.6 上的 minikube v1.6.2
✨  Selecting 'hyperkit' driver from existing profile (alternates: [])
✅  正在使用映像存儲庫 registry.cn-hangzhou.aliyuncs.com/google_containers
💿  正在下載 VM boot image...

💣  緩存ISO 時失敗: https://kubernetes.oss-cn-hangzhou.aliyuncs.com/minikube/iso/minikube-v1.6.2.iso: bad response code: 404

😿  minikube is exiting due to an error. If the above message is not useful, open an issue:
👉  https://github.com/kubernetes/minikube/issues/new/choose
benmuMacBook-Pro:Homebrew benmu$ minikube start --image-mirror-country=cn   --iso-url=https://kubernetes.oss-cn-hangzhou.aliyuncs.com/minikube/iso/minikube-v1.6.0.iso  --registry-mirror=https://7icj7z92.mirror.aliyuncs.com  --image-repository=registry.cn-hangzhou.aliyuncs.com/google_containers
😄  Darwin 10.14.6 上的 minikube v1.6.2
✨  Selecting 'hyperkit' driver from existing profile (alternates: [])
✅  正在使用映像存儲庫 registry.cn-hangzhou.aliyuncs.com/google_containers
💡  Tip: Use 'minikube start -p <name>' to create a new cluster, or 'minikube delete' to delete this one.
🏃  Using the running hyperkit "minikube" VM ...
⌛  Waiting for the host to be provisioned ...
🐳  正在 Docker '19.03.5' 中準備 Kubernetes v1.17.0…
E0117 16:48:18.733289   68071 cache_images.go:86] CacheImage registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.4.3-0 -> /Users/benmu/.minikube/cache/images/registry.cn-hangzhou.aliyuncs.com/google_containers/etcd_3.4.3-0 failed: write: UNAUTHORIZED: "authentication required"
E0117 16:48:18.736915   68071 start.go:839] Error caching images:  Caching images for kubeadm: caching images: caching image /Users/benmu/.minikube/cache/images/registry.cn-hangzhou.aliyuncs.com/google_containers/etcd_3.4.3-0: write: UNAUTHORIZED: "authentication required"
❌  Unable to load cached images: loading cached images: stat /Users/benmu/.minikube/cache/images/registry.cn-hangzhou.aliyuncs.com/google_containers/etcd_3.4.3-0: no such file or directory
🚀  正在啓動 Kubernetes ... 
🏄  完成!kubectl 已經配置至 "minikube"

minikube status

host: Running
kubelet: Running
apiserver: Running
kubeconfig: Configured

打開控制檯:

minikube dashboard

🔌  正在開啓 dashboard ...
🤔  Verifying dashboard health ...
🚀  Launching proxy ...
🤔  Verifying proxy health ...
🎉  Opening http://127.0.0.1:49155/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/ in your default browser...

 

新手記錄下自己搭建過程,主要是

minikube star

這裏一開始沒用對參數,各種報錯,然後刪除 ~/.minikube 再加上參數重試。

最後,引用下阿里雲的圖:Minikube利用本地虛擬機環境部署Kubernetes,其基本架構如下圖所示。

4

好了,開始你的k8s之旅吧。 

 

參考:

https://yq.aliyun.com/articles/221687

發佈了505 篇原創文章 · 獲贊 84 · 訪問量 53萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章