Raspberry Pi Kubernetes Cluster

2017-09-11 | #raspberrypi #kubernetes #arm #docker

Intro

Notes from setting up a three node Raspberry Pi 3 Model B[1] Kubernetes[2] cluster using HypriotOS 64-bit[3].

1: https://www.raspberrypi.org/products/raspberry-pi-3-model-b/

2: https://kubernetes.io

3: https://github.com/DieterReuter/image-builder-rpi64/releases

Originally from Setup Kubernetes on a Raspberry Pi Cluster easily the official way![4] with some additions to fix things I ran into when following the guide. This guide uses a 64-bit version of HypriotOS and only armv8 64-bit Docker images will work.

4: https://blog.hypriot.com/post/setup-kubernetes-raspberry-pi-cluster/

RPI Cluster [IMG]

Installing and Configuring HypriotOS

Flash HypriotOS 64-bit[5] to SD card. By using HypriotOS we can avoid a lot of the issues that comes with installing Docker on ARM.

5: https://github.com/DieterReuter/image-builder-rpi64/releases

You can skip the following steps for updating, setting up the k8s repo, and installing the k8s package using `--userdata` with the flash[6] tool. See this example[7].

6: https://github.com/hypriot/flash

7: https://github.com/ecliptik/rpi/blob/master/hypriot/user-data.yml

To begin, boot the Raspberry Pi to Hypriot, login and update system,

Installing Kubernetes

Install Kubernetes from official package repositories[8] on each node,

8: https://kubernetes.io/docs/setup/independent/install-kubeadm/#installing-kubelet-and-kubeadm

Setup the Master Node

As root, init the cluster with the network CIDR for Flannel,

As of this writing this will install and configure Kubernetes 1.8

As the `pirate` user setup kube config to run kubectl commands as non-root,

Setup Flannel CNI

By default Kubernetes does not configure a Container Network Interface[9] and needs to have one installed. Flannel[10] has an arm64 version available and works reasonably well on the Raspberry Pi 3 and HypriotOS.

9: https://cncf.io/projects/

10: https://github.com/coreos/flannel

Install flannel using arm64 images,

With older versions of flannel, additinoal iptables rules were required, this was fixed in v0.9.1[11] (thanks for the tip Frank!)

11: https://github.com/coreos/flannel/pull/872

Setup Worker Nodes

On each worker node run the `kubeadm join` command that was output after successfully running `kubeadm init` on the master node.

Join the node to the cluster,

Verifying

Show Node Status,

Show Pod Status,

Run A Test Pod

Using Docker Hub Official Multi-Platform Images[12] makes running official Docker hub images on arm64 hardware much easier. Since Docker Hub now understands architecture manifest, no specific architecture tags are required and any official images will work on a Raspberry Pi k8s cluster without a specific tag.

12: https://integratedcode.us/2017/09/13/dockerhub-official-images-go-multi-platform/

Official images based off Alpine Linux currently do not work - see Issue #304[13] for more information.

13: https://github.com/gliderlabs/docker-alpine/issues/304

In this example, we'll run the official nginx image[14] and have it listen on port 80.

14: https://hub.docker.com/_/nginx/

First, deploy a nginx service with 3 replicas,

Expose pods in nginx service on port 80,

Get endpoints for nginx service,

Run curl against an endpoint IP to test,

`curl` should work against all endpoint IPs on all nodes

Tags

docker

arm

kubernetes

raspberrypi

____________________________________________________________________

Home