Experience minikube


使用 Minikube 在 macOS 安裝 & 學習的筆記。

在 macOS 安裝 Minikube

安裝 kubectl for macOS: https://kubernetes.io/docs/tasks/tools/install-kubectl/

1
2
3
4
5
curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/darwin/amd64/kubectl
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl

安裝 minikube: brew cask install minikube

1
2
3
4
5
6
7
8
9
10
11
12
~  brew cask install minikube
==> Satisfying dependencies
==> Installing Formula dependencies from Homebrew
kubernetes-cli ... already installed
complete
==> Downloading https://storage.googleapis.com/minikube/releases/v0.20.0/minikube-darwin-amd64
######################################################################## 100.0%
==> Verifying checksum for Cask minikube
==> Installing Cask minikube
==> Linking Binary 'minikube-darwin-amd64' to '/usr/local/bin/minikube'.
🍺 minikube was successfully installed!
~ 

啟動

啟動 Minikube

指令:minikube start
第一次跑要等一下,他會在 virtualbox 建立新的 vm instance:

1
2
3
4
5
6
7
8
9
10
~  minikube start --vm-driver=virtualbox
Starting local Kubernetes v1.6.4 cluster...
Starting VM...
Moving files into cluster...
Setting up certs...
Starting cluster components...
Connecting to cluster...
Setting up kubeconfig...
Kubectl is now configured to use the cluster.
  • 指定 VM driver: minikube start --vm-driver=virtualbox
  • 如果無法正常啟動,先清除: minikube delete

取得狀態

1
2
3
4
~  minikube status
minikube: Running
localkube: Running
kubectl: Correctly Configured: pointing to minikube-vm at 192.168.99.100

版本資訊

1
2
~  minikube version
minikube version: v0.20.0

取得 k8s version

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
~  minikube get-k8s-versions
The following Kubernetes versions are available:
- v1.7.0
- v1.7.0-rc.1
- v1.7.0-alpha.2
- v1.6.4
- v1.6.3
- v1.6.0
- v1.6.0-rc.1
- v1.6.0-beta.4
- v1.6.0-beta.3
- v1.6.0-beta.2
- v1.6.0-alpha.1
- v1.6.0-alpha.0
- v1.5.3
- v1.5.2
- v1.5.1
- v1.4.5
- v1.4.3
- v1.4.2
- v1.4.1
- v1.4.0
- v1.3.7
- v1.3.6

Dashboard

開啟 dashboard: 會直接帶出 browser

1
2
~  minikube dashboard
Opening kubernetes dashboard in default browser...

取得環境變數

1
2
3
4
5
6
7
~  minikube docker-env
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.99.100:2376"
export DOCKER_CERT_PATH="/Users/rick/.minikube/certs"
export DOCKER_API_VERSION="1.23"
# Run this command to configure your shell:
# eval $(minikube docker-env)

停止 Minikube

停止 minikube,實際上是把 virtualbox 的 vm instance 停掉。

1
2
3
~  minikube stop
Stopping local Kubernetes cluster...
Machine stopped.

Run “Hello” App

啟動 echoserver

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
~  kubectl run hello-minikube \
--image=gcr.io/google_containers/echoserver:1.4 \
--port=8080
deployment "hello-minikube" created
~  kubectl expose deployment \
hello-minikube --type=NodePort
service "hello-minikube" exposed
~  kubectl get pod
NAME READY STATUS RESTARTS AGE
hello-minikube-938614450-50h7g 1/1 Running 0 3m
11:15:05 gtcafe-dev.rickhwang-dev minikube 
~  curl $(minikube service hello-minikube --url)
CLIENT VALUES:
client_address=172.17.0.1
command=GET
real path=/
query=nil
request_version=1.1
request_uri=http://192.168.99.100:8080/
SERVER VALUES:
server_version=nginx: 1.10.0 - lua: 10001
HEADERS RECEIVED:
accept=*/*
host=192.168.99.100:30459
user-agent=curl/7.51.0
BODY:
-no body in request-

學習資源

參考資料


Comments