Blogs / Setup your Own Website For Free: Rasberry Pi Tutorial

Setup your Own Website For Free: Rasberry Pi Tutorial

July 23, 2023 • Matthew Duong • Kubernetes;Self Hosting; Software Engineering • 6 min read

Setup your Own Website For Free: Rasberry Pi Tutorial

Introduction

I've created this tutorial especially for those who might not consider themselves to be too technical—marketers, salespeople, recruiters—really, anyone who's ever dreamed of having their own website. You won't need to navigate technical jargon, face hidden costs, or have a degree in computer science to follow along. I've also produced a companion video to supplement this written tutorial. It provides visual, step-by-step instructions to make the process even simpler and more accessible. Direct link to video here: https://www.youtube.com/watch?v=xah1Y4UtJCw

;

Overview

This tutorial is broken up into five sections:

  1. Hardware Requirements
  2. Installing and Configuring the Operating System (OS)
  3. Installing and Configuring Kubernetes
  4. Installing the Content Management System
  5. Configuring the Website for Public Access

1. Hardware Requirements

For this project, you need:

  1. A Raspberry Pi: A compact and potent computer (at least 4gb of ram).
  2. A power supply: To provide the necessary power to the Pi.
  3. An SD card: To handle storage needs (at least 32gb).
  4. An ethernet cable: For connectivity.

Recommendation: The Canakit as it includes all the necessary components.

2. Installing and Configuring the Operating System (OS)

In this tutorial, we'll be using Ubuntu Server(https://ubuntu.com/ ) as our operating system. It's a fantastic choice of Linux distribution due to its widespread support from a vibrant community. It's user-friendly for beginners, and it's also widely used in the industry, which is beneficial if you decide to delve deeper into this field one day. Here's how you can install and set up Ubuntu Server on your Raspberry Pi:

  1. Begin by downloading the Raspberry Pi micro SD imager from their official website https://www.raspberrypi.com/software/
  2. Use this imager to write the Ubuntu Server operating system onto your micro SD card.
  3. During this process, you'll be prompted to create a username and password for your Raspberry Pi. Make sure to remember these details.
  4. Once the OS is loaded onto the micro SD card, insert this card into your Raspberry Pi.
  5. Lastly, connect your Raspberry Pi to your network by using an ethernet cable and power it on.

3. Connecting to the Pi over SSH

SSH is a protocol that allows you to securely access and control your Raspberry Pi (or any other computer) remotely over a network. It's as if you're sitting right in front of it even though you might be on the other side of the world!

After you've installed the OS, you'll need to connect to your Raspberry Pi from your computer. Here's how you can do this:

  1. First, you'll need to find out your Raspberry Pi's IP address. An easy way to do this is by using the Fing app. It scans your Wi-Fi network and provides a list of all connected devices, including your Raspberry Pi. Alternatively you can use the PI’s hostname if you set it up in the raspberry pi imager utility.
  2. With your Raspberry Pi's IP address identified, you can now connect to it using SSH. To do this, you'll need to use the username and password that you set during the OS installation process. Connect to your pi using this command: ssh username@internal-ip-or-hostname

Remember, when you're using SSH, you're replacing 'username' and 'password' with the credentials you've previously set. This ensures a secure connection between your computer and the Raspberry Pi.

4. Installing and configuring Kubernetes

Install the Kubernetes control plane

Kubernetes is a tool that helps manage and scale your website. For the Raspberry Pi, we'll use a lightweight version of Kubernetes called K3s. Here’s what you need to do to install K3s:

  1. Install some of the required dependencies for k3s by running this command: sudo apt install linux-modules-extra-raspi -y These software dependencies are not installed by default on ubuntu so this is a required step (https://github.com/k3s-io/k3s/issues/4234 )
  2. Install k3s using this command: curl -sfL https://get.k3s.io | sh - More information can be found on the official k3s setup guide (https://docs.k3s.io/quick-start )
  3. Wait until kubernetes is in ready state before proceeding by running this command:

sudo k3s kubectl get nodes

NAME          STATUS   ROLES                  AGE   VERSION
thegalah-pi   Ready    control-plane,master   3m   v1.21.7+k3s1

Install kubectl command line tool

kubectl is a command line interface for running commands against Kubernetes clusters. In simple terms, it's the "remote control" that allows you to manage and interact with your Kubernetes cluster. Whether it's deploying applications, inspecting and debugging resources, or even directly managing cluster resources, kubectl is the go-to tool for Kubernetes users. To install run this command:

curl-LO"https://dl.k8s.io/release/$(curl-L-s https://dl.k8s.io/release/stable.txt)/bin/linux/arm64/kubectl"&&sudomv kubectl /usr/bin &&sudochmod +x /usr/bin/kubectl

Configure Kubectl to use our k3s credentials

We then need to configure our kubectl command line tool to connect to our k3s setup using this command:

sudo cp /etc/rancher/k3s/k3s.yaml ~/.kube/config

To confirm that the kubectl cli works with our credentials we can run kubectl get nodes similar to the previous step which should return the same output.

Install helm

Helm(https://helm.sh/ ) is often described as the package manager for Kubernetes. It simplifies the process of managing and deploying applications on a Kubernetes cluster. Think of Helm as a tool that bundles together all the resources needed for a particular application, allowing you to install, upgrade, and manage the app more efficiently. It's a valuable tool to have, especially when you're dealing with complex apps that have many components. To install helm run this command:

sudo snap install helm --classic

5. Installing the Content Management System

Now that we've successfully installed Kubernetes and Helm, it's time to set up your content management system (CMS). For this guide, we will be using Ghost, a free and open-source headless Node.js CMS. It's designed to simplify the process of online publishing for bloggers.

Configure the ghost helm chart

To deploy Ghost, we'll use the Bitnami/ghost Helm chart. In Helm, every chart represents a deployable app, complete with its configurations, which you can override as per your specific needs. The full list of configurable values for this chart can be found here on artifact hub(https://artifacthub.io/packages/helm/bitnami/ghost )

Let's walk through the steps to configure Ghost using Helm:

  1. Download my prepared configurations for the helm chart using this command which saves it to a file called values.yml:
curl -o values.yml https://gist.githubusercontent.com/thegalah/8af4588e9f9a6b405c742ceb388e71ec/raw/6d3befdd87dd3ec29bc7a75b073a3c18b99b0906
  1. Open the file using the nano editor: nano values.yml
  2. Replace the ghostHost value with your public ip address (you can find this by searching “what is my ip”).
  3. Save the file using Control + O
  4. Close the editor using Control + X

Install the CMS

To install the CMS:

  1. Run this command to add the bitnami reference so that helm can use the chart: helm repo add bitnami https://charts.bitnami.com/bitnami
  2. Install the chart using our values configurations in the previous step:
helm install cms bitnami/ghost -version19.3.24 -f values.yml --wait--atomic
  1. Wait for the success confirmation (this can take a few minutes)
  2. Confirm that you can access the ghost installation from your local network by navigating on any connected device in your network to http://internal-hostname-or-ip:30080 Remember to substitute out the internal-hostname-or-ip with your value.

6. Make Your Website Accessible to the World

Now that we have set up our website, the final step is to expose it to the internet. To do this, we will configure your router to direct incoming traffic to our Raspberry Pi. You can think of this like your Raspberry Pi is a house, and your router is the postman, delivering any incoming traffic to your house.

Please note, the steps for configuring port forwarding will depend on your router's brand and model. So, you might need to consult your router’s manual or do a quick online search for specific instructions. Nevertheless, here's the high level steps.

Access Your Router's Admin Interface

Typically, you do this through your web browser using an IP address, often something like 192.168.1.1 or 192.168.0.1.

Add a New Port Forwarding Rule

Here, you will be adding a new rule for port forwarding. You'll need to fill in a few details:

  1. Port number or range: This is usually port 80 for HTTP traffic and port 443 for HTTPS.
  2. IP address of your Raspberry Pi: This is the same address you used when connecting to your Raspberry Pi via SSH.
  3. Protocol: You'll usually need to forward both TCP and UDP traffic for a website.
  4. Save and Exit

And just like that, your website is now accessible to anyone who enters your public IP address into their browser. They'll be directed to your Raspberry Pi, which is hosting your website. Keep in mind that most residential IP addresses change from time to time. You might consider using a dynamic DNS service to assign a static domain name to your IP, but we'll leave that for another tutorial.

And there you have it! You've successfully transformed your Raspberry Pi into a fully functional web server. Now you're ready to share your website with the world. Congratulations on your achievement!

Troubleshooting

If you get stuck or need assistance feel free to reach out to me on my discord channel (https://discord.gg/XUeMPrVq ) and I can help provide support to help you get set up.

© 2023-2024 Matthew Duong