Kubernetes is an open-source system for automating deployment, scaling, and management of containerized applications.
Kubernetes is often abbreviated to k8s.
Kubernetes groups containers that make up an application into logical units for easy management and discovery. It builds upon 15 years of experience of running production workloads at Google, combined with best-of-breed ideas and practices from the community.
This tutorial will turn your BigBoards Hex or Cube into a Kubernetes cluster using kubeadm to create a cluster.
We will be doing this tutorial from the commandline of the master node of your BigBoards device. All commands have to be run from a shell via
- Install a secure Kubernetes cluster on your BigBoards device
- Install a pod networking on the cluster so that application components (pods) can talk to each other
- Install a sample application on the cluster
To complete the tutorial, there are some prerequisites:
- Since the BigBoards firmware runs on top of Ubuntu 14.04 which is not supported by Kubernetes, you have to install an alternative Linux operating system. We prefer Ubuntu LTS releases.
- Make a short list of the host names of your BigBoards device, with the network MAC addresses and product_uuids
cat /sys/class/dmi/id/product_uuid. Here's an example for 1 of our Cubes Jill.
Designing the cluster layout
In this guide we will keep the cluster simple:
- We will be running the Ubuntu 16.04 LTS version.
- Kubernetes has a distinctive networking model which is, on the 1 hand, conceptually simple from deployment perspective (everything has its own IP address), but, on the other hand, complex from the operations perspective to ensure every address is routable. To keep installation simple, we'll be deploying Flannel which is a simple overlay network. We get the ease of software defined networking at the cost of slight loss in performance.
- Each node of your BigBoards device will be a Kubernetes node, incl. the master node.
- The 1st node of you BigBoards device will be the master of the Kubernetes cluster.
Installing kubernetes and initializing the master node
We have automated the installation of Kubernetes on your BigBoards device using Ansible.
Check the installation instructions to get the latest version installed on your personal computer.
You can also install Ansible on the master node of you cluster and run all the playbooks underneath from the shell there.
- Checkout the GitHub repository
- Change directory to the folder with the local repository
- Add an inventory
./inventories/<hex-name>.ymlwith the layout of your BigBoards device. Look at
jill.ymlas an example.
$ ansible-playbook -vv -i inventories/<hex-name>.yml install.yml
Check that all deployed system pods start properly, especially
$ kubectl get pods --all-namespaces
Join worker nodes
The final output of the playbook will be the command to join the worker nodes to the Kubernetes cluster.
$ ansible host-workers -s -i inventories/<hex-name>.yml -m shell -a 'kubeadm join --token <token> <master-ip>:<master-port> --discovery-token-ca-cert-hash sha256:<hash>'
Kubernetes Dashboard is a general purpose, web-based UI for Kubernetes clusters. It allows users to manage applications running in the cluster and troubleshoot them, as well as manage the cluster itself.
$ kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml
Deploy sample application
Now it is time to take your new cluster for a test drive.
Sock Shop is a sample microservices application that shows how to run and connect a set of services on Kubernetes.
To learn more about the sample microservices app, see the GitHub README.
Note that the Sock Shop demo only works on
$ kubectl create namespace sock-shop $ kubectl apply -n sock-shop -f "https://github.com/microservices-demo/microservices-demo/blob/master/deploy/kubernetes/complete-demo.yaml?raw=true"
You can then find out the port for the front-end service by running:
$ kubectl -n sock-shop get svc front-end NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE front-end 10.110.250.153 <none> 80:30001/TCP 59s
It takes several minutes to download and start all the containers.
Watch the output of
kubectl get pods -n sock-shop to see when they’re all up and running.
Then go to the IP address of your cluster’s master node in your browser, and specify the given port.
So for example,
http://<master_ip>:<port>. In the example above, this was
http://10.110.250.153:30001, but it may be a different port for you.
Uninstall sampe application
To uninstall the socks shop, run this on the master.
$ kubectl delete namespace sock-shop
To undo what kubeadm did, you should first drain the node and make sure that the node is empty before shutting it down. Talking to the master with the appropriate credentials, run:
$ kubectl drain <node name> --delete-local-data --force --ignore-daemonsets $ kubectl delete node <node name>
Then, on the node being removed, reset all kubeadm installed state:
$ kubeadm reset
If you wish to start over simply run
kubeadm init or
kubeadm join with the appropriate arguments.