Minikube 是 K8S 官方爲了開發者能在我的電腦上運行 K8S 而提供的一套工具。實現上是經過 Go 語言編寫,經過調用虛擬化管理程序,建立出一個運行在虛擬機內的單節點集羣。html
注:從這裏也能夠看出,對於 K8S 集羣的基本功能而言,節點數並無什麼限制。只有一個節點一樣能夠建立集羣。node
你們在實際開發和體驗 Kubernetes時,可能會遇到網絡訪問的緣由或者其餘的坑致使不少朋友沒法使用minikube進行實驗。所以我經過撰寫這篇博客,讓你們少走一點彎路。阿里雲提供了一個修改版的Minikube,能夠從阿里雲的鏡像地址來獲取Docker鏡像和配置。linux
unable to cache ISO: connection failed because connected host has failed to respond.git
終端報錯信息:github
minikube start o minikube v0.35.0 on windows (amd64) > Creating virtualbox VM (CPUs=2, Memory=2048MB, Disk=20000MB) ... @ Downloading Minikube ISO ... ! Unable to start VM: unable to cache ISO: https://storage.googleapis.com/minikube/iso/minikube-v0.35.0.iso: failed to download: failed to download to temp file: download failed: 5 error(s) occurred : * Temporary download error: Get https://storage.googleapis.com/minikube/iso/minikube-v0.35.0.iso: dial tcp 216.58.207.144:443: connectex: A connection attempt failed because the connected party did no t properly respond after a period of time, or established connection failed because connected host has failed to respond. * Temporary download error: Get https://storage.googleapis.com/minikube/iso/minikube-v0.35.0.iso: dial tcp 216.58.207.144:443: connectex: A connection attempt failed because the connected party did no t properly respond after a period of time, or established connection failed because connected host has failed to respond. * Temporary download error: Get https://storage.googleapis.com/minikube/iso/minikube-v0.35.0.iso: dial tcp 216.58.207.144:443: connectex: A connection attempt failed because the connected party did no t properly respond after a period of time, or established connection failed because connected host has failed to respond. * Temporary download error: Get https://storage.googleapis.com/minikube/iso/minikube-v0.35.0.iso: dial tcp 216.58.207.144:443: connectex: A connection attempt failed because the connected party did no t properly respond after a period of time, or established connection failed because connected host has failed to respond. * Temporary download error: Get https://storage.googleapis.com/minikube/iso/minikube-v0.35.0.iso: dial tcp 216.58.207.144:443: connectex: A connection attempt failed because the connected party did no t properly respond after a period of time, or established connection failed because connected host has failed to respond.
報錯緣由: 因爲沒法從外網下載Minikube ISO出現如上報錯。web
解決辦法: 修改鏡像地址爲國內資源,解決網絡錯誤。docker
Minikube doesn't run on VirtualBoxjson
終端報錯信息:ubuntu
minikube start 😄 minikube v1.0.1 on linux (amd64) 🤹 Downloading Kubernetes v1.14.1 images in the background ... 🔥 Creating virtualbox VM (CPUs=2, Memory=2048MB, Disk=20000MB) ... 💣 Unable to start VM: create: creating: Unable to start the VM: /usr/bin/VBoxManage startvm minikube --type headless failed: VBoxManage: error: The virtual machine 'minikube' has terminated unexpectedly during startup with exit code 1 (0x1) VBoxManage: error: Details: code NS_ERROR_FAILURE (0x80004005), component MachineWrap, interface IMachine 😿 Sorry that minikube crashed. If this was unexpected, we would love to hear from you: 👉 https://github.com/kubernetes/minikube/issues/new
報錯緣由: VT-x/AMD-v虛擬化在全部CPU中被禁用。windows
解決方法: VT-x/AMD-v虛擬化必須在BIOS中開啓。
參考文檔: https://jingyan.baidu.com/article/fc07f98976710e12ffe519de.html
[MACHINE_DOES_NOT_EXST] Error getting state for host: machine does not exist
終端報錯信息
[sudo] james 的密碼: 😄 minikube v1.2.0 on linux (amd64) ⚠️ Please don't run minikube as root or with 'sudo' privileges. It isn't necessary. ✅ using image repository 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. E0722 14:57:51.637843 5215 start.go:559] StartHost: Error getting state for host: machine does not exist 💣 Unable to start VM ❌ Error: [MACHINE_DOES_NOT_EXST] Error getting state for host: machine does not exist 💡 Advice: Run 'minikube delete' to delete the stale VM ⁉️ Related issues: ▪ https://github.com/kubernetes/minikube/issues/3864 😿 If the above advice does not help, please let us know: 👉 https://github.com/kubernetes/minikube/issues/new
報錯緣由: 已經被使用過VM
解決辦法: minikute delete
注:
本文已更新到 Minikube v1.2.0/Kubernetes v1.15+
如需更新minikube,須要更新 minikube 安裝包
minikube delete
刪除現有虛機,刪除 ~/.minikube
目錄緩存的文件Docker社區版也爲Mac/Windows用戶提供了Kubernetes開發環境的支持 https://yq.aliyun.com/articles/508460,你們也能夠試用
Minikube在不一樣操做系統上支持不一樣的驅動
--vm-driver=none
選項來在本機運行 Kubernetes 組件,這時候須要本機安裝了 Docker。在使用 0.27版本以前的 none 驅動時,在執行 minikube delete
命令時,會移除 /data 目錄,請注意,問題說明;另外 none 驅動會運行一個不安全的API Server,會致使安全隱患,不建議在我的工做環境安裝。注:
咱們提供了最新的Minikube修改版的文件,能夠直接下載使用
Mac OSX
curl -Lo minikube http://kubernetes.oss-cn-hangzhou.aliyuncs.com/minikube/releases/v1.2.0/minikube-darwin-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/
Linux
curl -Lo minikube http://kubernetes.oss-cn-hangzhou.aliyuncs.com/minikube/releases/v1.2.0/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/
Windows
下載 minikube-windows-amd64.exe 文件,並重命名爲 minikube.exe
也能夠從Github上獲取相應的項目自行構建。
注:須要本地已經安裝配置好 Golang 開發環境和Docker引擎
git clone https://github.com/AliyunContainerService/minikube cd minikube git checkout aliyun-v1.2.0 make sudo cp out/minikube /usr/local/bin/
缺省Minikube使用VirtualBox驅動來建立Kubernetes本地環境
minikube start --registry-mirror=https://registry.docker-cn.com 😄 minikube v1.2.0 on linux (amd64) ⚠️ Please don't run minikube as root or with 'sudo' privileges. It isn't necessary. ✅ using image repository registry.cn-hangzhou.aliyuncs.com/google_containers 🔥 Creating virtualbox VM (CPUs=2, Memory=2048MB, Disk=20000MB) ... 🐳 Configuring environment for Kubernetes v1.15.0 on Docker 18.09.6 🚜 Pulling images ... 🚀 Launching Kubernetes ... ⌛ Verifying: apiserver proxy etcd scheduler controller dns 🏄 Done! kubectl is now configured to use "minikube"
支持不一樣的Kubernetes版本
# 安裝Kubernetes v1.12.1 minikube start --registry-mirror=https://registry.docker-cn.com --kubernetes-version v1.12.1
打開Kubernetes控制檯
minikube dashboard
對於使用Hyper-V環境的用戶,首先應該打開Hyper-V管理器建立一個外部虛擬交換機,
以後,咱們能夠用以下命令來建立基於Hyper-V的Kubernetes測試環境
.\minikube.exe start --registry-mirror=https://registry.docker-cn.com --vm-driver="hyperv" --memory=4096 --hyperv-virtual-switch="MinikubeSwitch"
注:須要管理員權限來建立Hyper-V虛擬機
檢測集羣狀態,運行:
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'.
Ubuntu下,Minikube的配置文件在以下路徑
~/.minikube/machines/minikube/config.json
查看配置文件內容:
kubectl config view apiVersion: v1 clusters: - cluster: certificate-authority: /home/james/.minikube/ca.crt server: https://192.168.99.100:8443 name: minikube contexts: - context: cluster: minikube user: minikube name: minikube current-context: minikube kind: Config preferences: {} users: - name: minikube user: client-certificate: /home/james/.minikube/client.crt client-key: /home/james/.minikube/client.key
檢驗Node狀態:
kubectl get nodes NAME STATUS ROLES AGE VERSION minikube Ready master 11m v1.15.0
使用ssh進入Minikube虛機:
sudo minikube ssh
_ _ _ _ ( ) ( ) ___ ___ (_) ___ (_)| |/') _ _ | |_ __ /' _ ` _ `\| |/' _ `\| || , < ( ) ( )| '_`\ /'__`\ | ( ) ( ) || || ( ) || || |\`\ | (_) || |_) )( ___/ (_) (_) (_)(_)(_) (_)(_)(_) (_)`\___/'(_,__/'`\____) $
中止運行中的kubernetes集羣:
$ minikube stop
刪除本地的kubernetes集羣:
$ minikube delete
Kubernete附帶一個web,容許您在不與命令行交互的狀況下管理集羣。在minikube上默認安裝並啓用儀表板插件
$ minikube addons list - addon-manager: enabled - coredns: disabled - dashboard: enabled - default-storageclass: enabled - efk: disabled - freshpod: disabled - heapster: disabled - ingress: disabled - kube-dns: enabled - metrics-server: disabled - registry: disabled - registry-creds: disabled - storage-provisioner: enabled
要直接在默認瀏覽器上打開,請使用:
$ minikube dashboard
獲取儀表板的URL
$ minikube dashboard --url http://192.168.39.117:30000
經過打開您最喜歡的瀏覽器上的URL訪問Kubernetes Dashboard。進一步閱讀,請查看:
你好Minikube系列: https://kubernetes.io/docs/tutorials/stateless-application/hello-minikube/
minkube新手指南: https://kubernetes.io/docs/getting-started-guides/minikube/
Minikube利用本地虛擬機環境部署Kubernetes,其基本架構以下圖所示。
用戶使用Minikube CLI管理虛擬機上的Kubernetes環境,好比:啓動,中止,刪除,獲取狀態等。一旦Minikube虛擬機啓動,用戶就可使用熟悉的Kubectl CLI在Kubernetes集羣上執行操做。
好了,開始探索Kubernetes的世界吧!:-)
參考鏈接: