場景
聽說Minikube中的k8s比docker中k8s更加接近真實環境,打算在本地安裝一波minikube,官網地址如下:
https://minikube.sigs.k8s.io/docs/
步驟
現在本機的mac上面的docker中啓用了k8s,先要禁用掉docker中k8s,並調小一下docker中的cpu和內存均爲2(具體設置根據你的資源來配)。
安裝kubectl
ALL_PROXY=socks5://127.0.0.1:7891 brew install kubectl
驗證:
kubectl version --client
Client Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.0", GitCommit:"9e991415386e4cf155a24b1da15becaa390438d8", GitTreeState:"clean", BuildDate:"2020-03-26T06:16:15Z", GoVersion:"go1.14", Compiler:"gc", Platform:"darwin/amd64"}
安裝Hypervisor
ALL_PROXY=socks5://127.0.0.1:7891 brew install hyperkit
brew install docker-machine-driver-hyperkit
驗證:
hyperkit -v
hyperkit: 0.20200224
Homepage: https://github.com/docker/hyperkit
License: BSD
安裝minikube
ALL_PROXY=socks5://127.0.0.1:7891 brew install minikube
驗證:
minikube version
minikube version: v1.9.2
commit: 93af9c1e43cab9618e301bc9fa720c63d5efa393
啓動minikube
proxychains4 minikube start --cpus=4 --memory="6000mb"
proxychains] config file found: /usr/local/etc/proxychains.conf
[proxychains] preloading /usr/local/Cellar/proxychains-ng/4.14/lib/libproxychains4.dylib
[proxychains] DLL init: proxychains-ng 4.14
[proxychains] Strict chain ... 127.0.0.1:7891 ... storage.googleapis.com:443 ... OK
😄 minikube v1.9.2 on Darwin 10.15.4
✨ Automatically selected the hyperkit driver
❗ 'hyperkit' driver reported an issue: hyperkit version check failed:
parse date: parsing time "14" as "20060102": cannot parse "14" as "2006"
💡 Suggestion:
📘 Documentation: https://minikube.sigs.k8s.io/docs/reference/drivers/hyperkit/
💾 Downloading driver docker-machine-driver-hyperkit:
[proxychains] Strict chain ... 127.0.0.1:7891 ... github.com:443 ... OK
[proxychains] Strict chain ... 127.0.0.1:7891 ... github-production-release-asset-2e65be.s3.amazonaws.com:443 ... OK
[proxychains] Strict chain ... 127.0.0.1:7891 ... github.com:443 ... OK
[proxychains] Strict chain ... 127.0.0.1:7891 ... github-production-release-asset-2e65be.s3.amazonaws.com:443 ... OK
> docker-machine-driver-hyperkit.sha256: 65 B / 65 B [---] 100.00% ? p/s 0s
[proxychains] Strict chain ... 127.0.0.1:7891 ... github.com:443 ... OK
[proxychains] Strict chain ... 127.0.0.1:7891 ... github-production-release-asset-2e65be.s3.amazonaws.com:443 ... OK
[proxychains] Strict chain ... 127.0.0.1:7891 ... github.com:443 ... OK
[proxychains] Strict chain ... 127.0.0.1:7891 ... github-production-release-asset-2e65be.s3.amazonaws.com:443 ... OK
> docker-machine-driver-hyperkit: 10.90 MiB / 10.90 MiB 100.00% 4.92 MiB p
🔑 The 'hyperkit' driver requires elevated permissions. The following commands will be executed:
$ sudo chown root:wheel /Users/zhangyalin/.minikube/bin/docker-machine-driver-hyperkit
$ sudo chmod u+s /Users/zhangyalin/.minikube/bin/docker-machine-driver-hyperkit
Password:
💿 Downloading VM boot image ...
[proxychains] Strict chain ... 127.0.0.1:7891 ... storage.googleapis.com:443 ... OK
[proxychains] Strict chain ... 127.0.0.1:7891 ... storage.googleapis.com:443 ... OK
> minikube-v1.9.0.iso.sha256: 65 B / 65 B [--------------] 100.00% ? p/s 0s
[proxychains] Strict chain ... 127.0.0.1:7891 ... storage.googleapis.com:443 ... OK
[proxychains] Strict chain ... 127.0.0.1:7891 ... storage.googleapis.com:443 ... OK
> minikube-v1.9.0.iso: 174.93 MiB / 174.93 MiB [] 100.00% 10.78 MiB p/s 17s
👍 Starting control plane node m01 in cluster minikube
💾 Downloading Kubernetes v1.18.0 preload ...
[proxychains] Strict chain ... 127.0.0.1:7891 ... storage.googleapis.com:443 ... OK
[proxychains] Strict chain ... 127.0.0.1:7891 ... storage.googleapis.com:443 ... OK
> preloaded-images-k8s-v2-v1.18.0-docker-overlay2-amd64.tar.lz4: 542.91 MiB
[proxychains] Strict chain ... 127.0.0.1:7891 ... www.googleapis.com:443 ... OK
🔥 Creating hyperkit VM (CPUs=4, Memory=6000MB, Disk=20000MB) ...
[proxychains] Strict chain ... 127.0.0.1:7891 ... 127.0.0.1:60260 ... OK
[proxychains] Strict chain ... 127.0.0.1:7891 ... 192.168.64.29:22 ... OK
[proxychains] Strict chain ... 127.0.0.1:7891 ... 192.168.64.29:22 ... OK
[proxychains] Strict chain ... 127.0.0.1:7891 ... 192.168.64.29:22 ... OK
[proxychains] Strict chain ... 127.0.0.1:7891 ... 192.168.64.29:22 ... OK
[proxychains] Strict chain ... 127.0.0.1:7891 ... 192.168.64.29:22 ... OK
[proxychains] Strict chain ... 127.0.0.1:7891 ... 192.168.64.29:22 ... OK
[proxychains] Strict chain ... 127.0.0.1:7891 ... 192.168.64.29:22 ... OK
[proxychains] Strict chain ... 127.0.0.1:7891 ... 192.168.64.29:22 ... OK
[proxychains] Strict chain ... 127.0.0.1:7891 ... 192.168.64.29:22 ... OK
[proxychains] Strict chain ... 127.0.0.1:7891 ... 192.168.64.29:22 ... OK
[proxychains] Strict chain ... 127.0.0.1:7891 ... 192.168.64.29:22 ... OK
[proxychains] Strict chain ... 127.0.0.1:7891 ... 192.168.64.29:22 ... OK
[proxychains] Strict chain ... 127.0.0.1:7891 ... 192.168.64.29:22 ... OK
[proxychains] Strict chain ... 127.0.0.1:7891 ... 192.168.64.29:22 ... OK
[proxychains] Strict chain ... 127.0.0.1:7891 ... 192.168.64.29:22 ... OK
[proxychains] Strict chain ... 127.0.0.1:7891 ... 192.168.64.29:22 ... OK
[proxychains] Strict chain ... 127.0.0.1:7891 ... 192.168.64.29:22 ... OK
[proxychains] Strict chain ... 127.0.0.1:7891 ... 192.168.64.29:22 ... OK
[proxychains] Strict chain ... 127.0.0.1:7891 ... 192.168.64.29:22 ... OK
❗ This VM is having trouble accessing https://k8s.gcr.io
💡 To pull new external images, you may need to configure a proxy: https://minikube.sigs.k8s.io/docs/reference/networking/proxy/
🐳 Preparing Kubernetes v1.18.0 on Docker 19.03.8 ...
[proxychains] Strict chain ... 127.0.0.1:7891 ... 127.0.0.1:60397 ... OK
[proxychains] Strict chain ... 127.0.0.1:7891 ... 192.168.64.29:22 ... OK
🌟 Enabling addons: default-storageclass, storage-provisioner
[proxychains] Strict chain ... 127.0.0.1:7891 ... 127.0.0.1:60420 ... OK
[proxychains] Strict chain ... 127.0.0.1:7891 ... 192.168.64.29:8443 ... OK
[proxychains] Strict chain ... 127.0.0.1:7891 ... 127.0.0.1:60427 ... OK
[proxychains] Strict chain ... 127.0.0.1:7891 ... 127.0.0.1:60432 ... OK
[proxychains] Strict chain ... 127.0.0.1:7891 ... 192.168.64.29:22 ... OK
[proxychains] Strict chain ... 127.0.0.1:7891 ... 127.0.0.1:60439 ... OK
[proxychains] Strict chain ... 127.0.0.1:7891 ... 127.0.0.1:60444 ... OK
[proxychains] Strict chain ... 127.0.0.1:7891 ... 192.168.64.29:22 ... OK
[proxychains] Strict chain ... 127.0.0.1:7891 ... 192.168.64.29:8443 ... OK
🏄 Done! kubectl is now configured to use "minikube"
這裏使用proxychains4
對命令進行代理,這個過程中需要輸入一次管理員密碼,主要就是爲了給安裝好的軟件進行授權;這個過程中有兩個警告,第一個警告是對本地的hyperkit軟件解析版本名發生了錯誤,這個可以忽略;第二個警告(開源軟件內嵌谷歌雲廣告)是說虛擬機無法訪問google雲的k8s Docker 容器映像,這個其實也可以忽略,因爲本地的docker中已經把k8s的映像pull好了。
驗證minikube
查看狀態命令:
minikube status
查看狀態結果:
m01
host: Running
kubelet: Running
apiserver: Running
kubeconfig: Configured
查看當前配置:
kubectl config current-context
查看版本:
kubectl version
查看集羣狀態:
kubectl cluster-info
查看節點:
kubectl get no
打開dashboard:
minikube dashboard
🔌 Enabling dashboard ...
🤔 Verifying dashboard health ...
🚀 Launching proxy ...
🤔 Verifying proxy health ...
🎉 Opening http://127.0.0.1:60709/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/ in your default browser...
效果:
查看已經安裝的addons:
minikube addons list
|-----------------------------|----------|--------------|
| ADDON NAME | PROFILE | STATUS |
|-----------------------------|----------|--------------|
| dashboard | minikube | enabled ✅ |
| default-storageclass | minikube | enabled ✅ |
| efk | minikube | disabled |
| freshpod | minikube | disabled |
| gvisor | minikube | disabled |
| helm-tiller | minikube | disabled |
| ingress | minikube | disabled |
| ingress-dns | minikube | disabled |
| istio | minikube | disabled |
| istio-provisioner | minikube | disabled |
| logviewer | minikube | disabled |
| metrics-server | minikube | disabled |
| nvidia-driver-installer | minikube | disabled |
| nvidia-gpu-device-plugin | minikube | disabled |
| registry | minikube | disabled |
| registry-aliases | minikube | disabled |
| registry-creds | minikube | disabled |
| storage-provisioner | minikube | enabled ✅ |
| storage-provisioner-gluster | minikube | disabled |
|-----------------------------|----------|--------------|
總結
在啓動的過程中,嘗試過使用阿里雲的鏡像,具體命令如下:
minikube start --cpus=4 --memory="6000mb" --image-mirror-country="cn" --image-repository="registry.cn-hangzhou.aliyuncs.com/google_containers"
但是失敗了,就改使用proxychains4來代理下載。