Using LinuxKit to create a Kubernetes cluster

Using LinuxKit to create a Kubernetes cluster

LinuxKit uses containers to build minimal, immutable Linux operation system image framework, which was introduced and demonstrated previously. If a user is interested, he/she refer to the blog post LinuxKit 入門. This article describes utilize LinuxKit to build Kubernetes image file, and to deploy a simple Kubernetes cluster.

This tutorial will be executed on Mac OS X, and the software to be deployed are listed below:

  • Kubernetes v1.7.2(2017-08-07, Update)
  • Etcd v3
  • Weave
  • Docker v17.06.0-ce


  • Latest up and running Docker
  • Git
  • LinuxKit, Moby, and LinuxKit tool

One can use the following command to build Moby and LinuxKit:

$ git clone $ cd linuxkit $ make $ ./bin/moby version moby version 0.0 commit: c2b081ed8a9f690820cc0c0568238e641848f58f $ ./bin
linuxkit version linuxkit version 0.0 commit: 0e3ca695d07d1c9870eca71fb7dd9ede31a38380

Build Kubernetes System Image

Firstly, a user needs to build a packaged Kubernetes Linux image. He or She need only to use the following official command to build:

$ cd linuxkit/projects/kubernetes/ $ make build-vm-images ... Create outputs: kube-node-kernel kube-node-initrd.img kube-node-cmdline

Build Kubernetes cluster

After finishing the above steps, one can go ahead and boot the Master OS image by using the command shown below, and then obtain the node ip:

$ ./ (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 brd scope global eth0 valid_lft forever preferred_lft forever inet6 fe80::abf0:9fa4:d0f4:8da2/64 scope link valid_lft forever preferred_lft forever

After booting, user can open a new console and use SSH to connect to Master, and use Kubeadm to initialize Master:

$ cd linuxkit/projects/kubernetes/ $ ./ linuxkit-025000000002:/# ... kubeadm join --token 4236d3.29f61af661c49dbf

Once the above steps are finished, he or she will see Token. One shall remember token information. Next, user can open a new console and type the following command to boot node:

console1>$ ./ 1 --token 4236d3.29f61af661c49dbf

P.S. Open node format

./ <n> [<join_args> ...]

And then he/she can open two consoles to add to a cluster:

console2> $ ./ 2 --token 4236d3.29f61af661c49dbf console3> $ ./ 3 --token 4236d3.29f61af661c49dbf

Now, we can go back to master node, and type the following command to view node status:

$ 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

Easy way to deploy Nginx Service

Kubernetes can be chosen to use command to directly create application and services, or edit YAML or JSON file to depict the allocation of application deployment. The following command will create a simply Nginx service:

$ 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 linuxkit-025000000004

Then we are going to create svc (service), in order to provide external network to access application. We use the command listed below:

$ kubectl expose deploy nginx --port=80 --type=NodePort $ kubectl get svc NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes <none> 443/TCP 19m nginx <nodes> 80:31773/TCP 5s

This is not the deployment for physical machines, therefore users use Docker namespace as network. Here one can use ubuntu-desktop-lxde-vnc to view Nginx application:

$ docker run -it --rm -p 6080:80 dorowu/ubuntu-desktop-lxde-vnc

Then he or she can use a browser to connect to HTLM VNC

Finally, user simply types the command shown below to shut down the node:

$ halt [ 1503.034689] reboot: Power down

by 白凱仁 迎棧科技軟體工程師


Select list(s)*