Minikube is a tool that makes it easy to run Kubernetes locally. Minikube runs a single-node Kubernetes cluster inside a VM on your laptop for users looking to try out Kubernetes or develop with it day-to-day.
根據(jù)介紹,我認(rèn)為在本地嘗試 Kubernetes 的話(huà),Minikube 會(huì)是一個(gè)非常推薦的途徑,遂用之。
初步探索 Minikube
Minikube 的相關(guān)內(nèi)容以及簡(jiǎn)介均來(lái)自于這里。
事先準(zhǔn)備:
安裝和事先配置都不是特別的復(fù)雜,這里就不再一一贅述,如需獲得更多信息請(qǐng)移至這里。
在沒(méi)有安裝 Minikube 之前,kubectl version 并不能獲得 Server 的信息:
$ kubectl version
Client Version: version.Info{Major:"1", Minor:"9", GitVersion:"v1.9.0", GitCommit:"925c127ec6b946659ad0fd596fa959be43f0cc05", GitTreeState:"clean", BuildDate:"2017-12-15T21:07:38Z", GoVersion:"go1.9.2", Compiler:"gc", Platform:"windows/amd64"}
Unable to connect to the server: ${ERROR_MESSAGE}
所以我們需要運(yùn)行 minikube start 來(lái)創(chuàng)建 Minikube 這一虛擬 Kubernetes 服務(wù)器:
$ minikube start
Starting local Kubernetes v1.9.0 cluster...
再次運(yùn)行 kubectl version 便可以得到同時(shí) client 和 server 這兩組信息。
我們可以執(zhí)行 kubectl get nodes 來(lái)獲取 Node 的信息(因?yàn)?Minikube 是單節(jié)點(diǎn)的集群,所以只有一個(gè) Node):

如果覺(jué)得 command line 不夠直觀的了解已經(jīng)瀏覽 Kubernetes 的框架結(jié)構(gòu),也可以使用 Kubernetes 原生的 Dashboard 來(lái)視覺(jué)化的瀏覽 Kubernetes 概況:

接下來(lái)我們實(shí)踐一個(gè)最簡(jiǎn)單的例子 hello-minikube:

這是直接使用 command line 來(lái)執(zhí)行的,大多數(shù)時(shí)候 Kubernetes 會(huì)使用 config 文件來(lái)配置,例如 .yaml,.yml。
kubectl run:Run a particular image on the cluster(在集群中運(yùn)行某一個(gè)特定的鏡像)。
hello-minikube:deployment 的名稱(chēng)。
--image=k8s.gcr.io/echoserver:1.4:所使用的鏡像。
--port=8080:容器將 expose 的 Port。
由于 Kubernetes 中的 Pods 是動(dòng)態(tài)存在的,所以縱使 Container 已經(jīng) expose 了 Port,我們?nèi)匀徊荒苤苯釉L(fǎng)問(wèn),而是需要一個(gè) Service,所以需要執(zhí)行如下:

kubectl expose:Take a replication controller, service or pod and expose it as a new Kubernetes Service。
hello-minikube:Service 的名稱(chēng)。
--type:定義 Service 的 Type,在這里是 NodePort(把這個(gè) Service 的 Port expose 到 Node 上)。別的 Type 還有 ClusterIP(只能在集群內(nèi)部被訪(fǎng)問(wèn)),LoadBalancer(通過(guò)一個(gè) LoadBalancer expose 到外部)等等。
可以在 Dashboard 中查看:


因?yàn)?Service 的 Type 是 NodePort,圖上的 32160 即是該 Service 可以通過(guò) Node 的 IP 被訪(fǎng)問(wèn)的 Port。所以我們可以通過(guò) ${MINIKUBE_IP}:${SERVICE_PORT} 進(jìn)行訪(fǎng)問(wèn),本文中的例子便是:

隨后我們可以進(jìn)行 Cleanup,分別是 delete services,delete deployment,minikube stop:
$ kubectl delete services hello-minikube
service "hello-minikube" deleted
$ kubectl delete deployment hello-minikube
deployment "hello-minikube" deleted
$ minikube stop
Stopping "minikube"...
接下來(lái)的一篇文章我將介紹如何在 Kubernetes 里面簡(jiǎn)單的實(shí)現(xiàn) Git Server。