Raspberry Pi Cluster, Part 4 - Jekyll and Docker

Now I have my Pi’s all set up and ready to go, I’m ready to lose myself down the rabbit hole that is Kubernetes. However, before I can go there, I need to think about what I’m actually going to use the cluster for (apart from a Minecraft server, obvs).

Well, as I mentioned in the first part of this series, my main plan is to host this very website on the cluster, so let’s set that up now.

Even though Raspberry Pi’s are amazing, they do have limitations and I want to squeeze every bit of performance and longevity out of my cluster. This essentially means that the site needs to be as lightweight as possible. While I could just install WordPress or Drupal on the cluster, this means that I would have to install PHP and MySQL, which will add quite a big strain to the Pi’s and their relatively fragile SD cards.

Jekyll

The solution is to keep everything simple, all we want to serve from the site is plain on HTML, without an expensive (in terms or performance) CMS using up all the memory. This is where Jekyll comes in, it’s a static site generator that spits out plain HTML. Ideal.

Jekyll is a ruby gem that has been around for ages and works by compiling markdown templates into a static HTML site. It’s pretty simple to setup, if you are following along, checkout the quick start guide. If everything goes well, you should end up with a HTML site in a folder called _site. We’ll need that next.

Packaging up the website

Kubernetes is an open source container orchestration tool, which is basically means it manages the deployment of virtual machines on clusters of computers. Containers can contain pretty much anything and there many different flavours of containers, but I’m going to use Docker and I’m going to run an Nginx instance within the container to host my shiny new Jekyll website.

It’s actually quite a straight-forward process, in the root of the Jekyll site (i.e the parent folder of _site), create a new file called Dockerfile and add the following:

FROM arm64v8/nginx

COPY _site /usr/share/nginx/html

It’s probably about as simple as a Dockerfile can get. To explain, the first line tells Docker to use nginx, but not just the standard image - as we are deploying this on 64 bit Raspberry Pi’s, we have to use a specific version that is compatible with the Pi’s ARM based processor architecture. This is what the arm64v8 part signifies.

The second line simply copies our Jekyll website to the default root folder of nginx.

Now we need to build our new Docker container. The best way to do this is to install the Docker Desktop app, this will give you access to the CLI. At this point, create an account too, we’ll need this in a sec. Once installed, build the container:

docker build -t <username>/<containername> .

Replace <username> and <containername> with the relevant info. This will take a few seconds, but once finished, we have successfully built our container image that hosts our Jekyll website.

Pushing up to the cloud

I had been toying with the idea of creating my own private docker container repository on the cluster itself. It would fit in with the project ethos of making everything as complicated as possible. But I want to be able to update the site from anywhere in the world and not just on my local network. I could create a VPN, but even by my standards, that is a bit overkill.

A much better solution is to simply push my container image up to DockerHub, which is a cloud based repository specifically for storing Docker images (as the name would suggest).

If you created an account earlier when installing Docker Desktop, it’s quite easy. Make sure you are logged into your account in Docker Desktop, then run:

docker push <username>/<containername>

Et volia, the image is pushed up to the cloud. There is one extra step I took here: I logged into DockerHub and found my repo, I then marked it as private. Each DockerHub account gets one free private repo in the free tier. As this is a cloud based system, it means that any public repos can be found and pulled down by anyone. So technically, if someone found our image, the could spin up their own version of our site pretty quick. This probably isn’t ideal.

If you are following along, excellent work. Now we’re going to setup Kubernetes. Which is proper geeky. You’ll love it.

Next, Part 5 - Installing and configuring Kubernetes