Kubernetes in Docker for Mac Beta小記
OS: Mac EI Capitan 10.11.6
Docker: 17.12.0-cd-mac45
這一次的 Docker for Mac 被提示有加入 Kubernetes, 所以就順手升級他了
首先觀察 about docker 來看這次的版本
接下來點選 工具列上 docker 圖案 -- > Preferences
點選 Kubernetes 圖案 -- > 勾選 Enable Kubernetes
接下來會提示要安裝 Kubernetes cluster -- > 點選 Install
系統會進行 Cluster 的安裝
安裝完成之後就會告知, 右下角也會看到 Kubernetes is running -- > 點選 Close
嘗試於終端機進行 kubectl 操作
$ kubectl get pods
Unable to connect to the server: dial tcp: lookup openshift-master.chicago.openshift3roadshow.com on 192.168.0.1:53: no such host
$ kubectl get cluster-info
Unable to connect to the server: dial tcp: lookup openshift-master.chicago.openshift3roadshow.com on 192.168.0.1:53: no such host
觀察了一下, 發現之前在芝加哥的時候有參加 openshit3 的 roadshow, 設定還在, 產生的錯誤
$ cat ~/.kube/config
apiVersion: v1
clusters:
- cluster:
insecure-skip-tls-verify: true
server: https://localhost:6443
name: docker-for-desktop-cluster
- cluster:
insecure-skip-tls-verify: true
server: https://openshift-master.chicago.openshift3roadshow.com:8443
name: openshift-master-chicago-openshift3roadshow-com:8443
contexts:
- context:
cluster: docker-for-desktop-cluster
user: docker-for-desktop
name: docker-for-desktop
把現在的設定檔案備份起來
$ mv ~/.kube/config ~/.kube/config.bak
觀察資訊
$ ls ~/.kube/
config.bak
嘗試看看可不可以用 kubectl 操作
$ kubectl get pods
The connection to the server localhost:8080 was refused - did you specify the right host or port?
接下來嘗試個大絕招 ~ 把 docker 關掉重新再開 :)
重新啟動 docker 之後再次觀察 ~/.kube
$ ls ~/.kube/
config config.bak
觀察 ~/.kube/config
$ cat ~/.kube/config
apiVersion: v1
clusters:
- cluster:
insecure-skip-tls-verify: true
server: https://localhost:6443
name: docker-for-desktop-cluster
contexts:
- context:
cluster: docker-for-desktop-cluster
user: docker-for-desktop
name: docker-for-desktop
current-context: docker-for-desktop
kind: Config
preferences: {}
users:
- name: docker-for-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RWSzNMVzlrcDc3MDcKUkJXUWJldXZqa0dsdzBYajlTMENRRExpMUV0THJaU3pFT2pJMHBuUS9FdUxrWDk3SnpoVGZibk9RZmdvSlUzTgp6MWsvY2MvUmppM2plSW5HeHltOXNPZlpMbU1rU2ZoSk9ScktxWGdaZk1VPQotLS0tLUVORCBSU0EgUFJJVkFURSBLRVktLS0tLQo=
這邊有看到是在 port 6443 listen
在 Mac 上面觀察一下
$ netstat -an -p tcp | grep LIST
tcp6 0 0 ::1.6443 *.* LISTEN
tcp4 0 0 *.6443 *.* LISTEN
tcp4 0 0 127.0.0.1.17603 *.* LISTEN
tcp4 0 0 127.0.0.1.17600 *.* LISTEN
tcp4 0 0 *.17500 *.* LISTEN
tcp6 0 0 *.17500 *.* LISTEN
tcp4 0 0 127.0.0.1.44320 *.* LISTEN
再次嘗試操作
$ kubectl get pods
No resources found.
$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
docker-for-desktop Ready master 40m v1.8.2
$ kubectl get deployment
No resources found.
$ kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 42m
接下來觀察 docker 這邊
首先會看到因為裝了 kubernetes, 所以多了很多 docker images
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker/kube-compose-controller v0.1.2 6480f70f7ac6 2 months ago 37.9MB
opensuse latest c98336369400 2 months ago 108MB
sakanaacr.azurecr.io/opensuse latest c98336369400 2 months ago 108MB
gcr.io/google_containers/kube-apiserver-amd64 v1.8.2 6278a1092d08 2 months ago 194MB
gcr.io/google_containers/kube-controller-manager-amd64 v1.8.2 5eabb0eae58b 2 months ago 129MB
gcr.io/google_containers/kube-scheduler-amd64 v1.8.2 b48970f8473e 2 months ago 54.9MB
gcr.io/google_containers/kube-proxy-amd64 v1.8.2 88e2c85d3d02 2 months ago 93.1MB
gcr.io/google_containers/k8s-dns-sidecar-amd64 1.14.5 fed89e8b4248 3 months ago 41.8MB
gcr.io/google_containers/k8s-dns-kube-dns-amd64 1.14.5 512cd7425a73 3 months ago 49.4MB
gcr.io/google_containers/k8s-dns-dnsmasq-nanny-amd64 1.14.5 459944ce8cc4 3 months ago 41.4MB
gcr.io/google_containers/etcd-amd64 3.0.17 243830dae7dd 11 months ago 169MB
gcr.io/google_containers/pause-amd64 3.0 99e59f495ffa 20 months ago 747kB
透過 docker version 觀察目前的 Orchestrator 為 kubernetes
$ docker version
Client:
Version: 17.12-kube_beta
API version: 1.35
Go version: go1.9.2
Git commit: ca0c9dbcb219048a1a61fbf82a2e69f1b9795023
Built: Fri Dec 15 10:20:47 2017
OS/Arch: darwin/amd64
Orchestrator: kubernetes
Server:
Engine:
Version: 17.12.0-ce
API version: 1.35 (minimum version 1.12)
Go version: go1.9.2
Git commit: c97c6d6
Built: Wed Dec 27 20:12:29 2017
OS/Arch: linux/amd64
Experimental: true
參考 “3 Minutes to Single Node Kubernetes cluster on Docker for Mac Platform” [1]
建立一個 webdemo.yml
觀察一下他的內容
$ cat webdome.yml
apiVersion: v1
kind: Pod
metadata:
name: collabweb
spec:
containers:
- name: webnix
image: ajeetraina/webdemo
ports:
- containerPort: 8080
先觀察資訊
$ kubectl get pods
No resources found.
利用 webdemo.yml 建立 pod
$ kubectl create -f webdemo.yml
pod "collabweb" created
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
collabweb 0/1 ContainerCreating 0 1m
需要一點時間下載, 再次觀察
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
collabweb 1/1 Running 0 6m
觀察相關資訊
$ kubectl describe pod collabweb
Name: collabweb
Namespace: default
Node: docker-for-desktop/192.168.65.3
Start Time: Sat, 20 Jan 2018 18:08:33 +0800
Labels: <none>
Annotations: <none>
Status: Running
IP: 10.1.0.6
Containers:
webnix:
Container ID: docker://f193117c966b2c89fcb12e6ca81f135f20cc3dfe5ccf53c1b9873301d9648101
Image: ajeetraina/webdemo
Image ID: docker-pullable://ajeetraina/webdemo@sha256:5fddb01a372b02ec2d49465a920eda0f864b9b71ac75032fcbeeba028764bcd8
Port: 8080/TCP
State: Running
Started: Sat, 20 Jan 2018 18:13:09 +0800
Ready: True
Restart Count: 0
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-dwzlr (ro)
Conditions:
Type Status
Initialized True
Ready True
PodScheduled True
Volumes:
default-token-dwzlr:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-dwzlr
Optional: false
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.alpha.kubernetes.io/notReady:NoExecute for 300s
node.alpha.kubernetes.io/unreachable:NoExecute for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 7m default-scheduler Successfully assigned collabweb to docker-for-desktop
Normal SuccessfulMountVolume 7m kubelet, docker-for-desktop MountVolume.SetUp succeeded for volume "default-token-dwzlr"
Normal Pulling 7m kubelet, docker-for-desktop pulling image "ajeetraina/webdemo"
Normal Pulled 3m kubelet, docker-for-desktop Successfully pulled image "ajeetraina/webdemo"
Normal Created 3m kubelet, docker-for-desktop Created container
Normal Started 3m kubelet, docker-for-desktop Started container
按照網頁上面的做法, 但是卻得不到 deployment, 已經留言還有 twitter 詢問了
$ kubectl get deployment -o wide
No resources found.
姑且使用 kubectl run 來試試看
$ kubectl run webdemo --image=ajeetraina/webdemo --port=8080
deployment "webdemo" created
再次觀察
$ kubectl get deployment -o wide
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
webdemo 1 1 1 1 1m webdemo ajeetraina/webdemo run=webdemo
在 expose 之前先觀察 services
$ kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 3h
進行 expose
$ kubectl expose deployment webdemo --port=8080 --type=NodePort
service "webdemo" exposed
再次觀察
$ kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 3h
webdemo NodePort 10.103.123.186 <none> 8080:30797/TCP 51s
進行相關測試
可以用 curl 或是開啟瀏覽器, 按照上面給的 port 來連線, 例如我這次是 :30797/TCP 就是 localhost:30797
最後來刪除 deployment
先觀察資訊
$ kubectl get deployment
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
webdemo 1 1 1 1 11m
使用 kubectl delete 刪除
$ kubectl delete deployment webdemo
deployment "webdemo" deleted
$ kubectl get deployment
No resources found.
$ kubectl delete pod collabweb
pod "collabweb" deleted
搞定 :)
接下來可以在 Mac 進行 kubectl 練習了
Reference
~ enjoy it
沒有留言:
張貼留言