$ git clone https://github.com/linuxkit/linuxkit.git
$ cd linuxkit
$ make
$ ./bin/moby version
moby version 0.0
commit: c2b081ed8a9f690820cc0c0568238e641848f58f
$ ./bin/linuxkit version
linuxkit version 0.0
commit: 0e3ca695d07d1c9870eca71fb7dd9ede31a38380
建構 Kubernetes 系統映像檔
首先要建立一個打包好 Kubernetes 的 Linux 系統,而官方已經有做好範例,利用以下方式即可建構:
$ cd linuxkit/projects/kubernetes/
$ make build-vm-images
...
Create outputs:
kube-node-kernel kube-node-initrd.img kube-node-cmdline
部署 Kubernetes cluster
完成建構映像檔後,就可以透過以下指令來啓動 Master OS,然後獲取節點 IP:
$ ./boot.sh
(ns: getty) linuxkit-025000000002:~\# ip addr show dev eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 02:50:00:00:00:02 brd ff:ff:ff:ff:ff:ff
inet 192.168.65.3/24 brd 192.168.65.255 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::abf0:9fa4:d0f4:8da2/64 scope link
valid_lft forever preferred_lft forever
$ kubectl get no
NAME STATUS AGE VERSION
linuxkit-025000000002 Ready 16m v1.7.2
linuxkit-025000000003 Ready 6m v1.7.2
linuxkit-025000000004 Ready 1m v1.7.2
linuxkit-025000000005 Ready 1m v1.7.2
$ kubectl run nginx --image=nginx --replicas=1 --port=80
$ kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE
nginx-1423793266-v0hpb 1/1 Running 0 38s 10.42.0.1 linuxkit-025000000004
完成後要接着建立 svc(Service),來提供外部網絡存取應用:
$ kubectl expose deploy nginx --port=80 --type=NodePort
$ kubectl get svc
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes 10.96.0.1 <none> 443/TCP 19m
nginx 10.108.41.230 <nodes> 80:31773/TCP 5s