Skip to content

Instantly share code, notes, and snippets.

@jackylamhk
Created August 20, 2023 14:54
Show Gist options
  • Save jackylamhk/7c94cd76e00cb641a4c1685697156b9e to your computer and use it in GitHub Desktop.
Save jackylamhk/7c94cd76e00cb641a4c1685697156b9e to your computer and use it in GitHub Desktop.
Guide to installing k3s on a Raspberry Pi

Guide to installing k3s on a Raspberry Pi

I'm creating this guide as I cannot find an updated guide anywhere that contains these specific series of steps needed to properly install k3s on a Raspberry Pi. In this case, I'm choosing to go with Ubuntu Server 23.04.

Steps

  1. Flash your microSD card with the Rasperry Pi Imager. Select Ubuntu Server 23.04 (64-bit) under OS.

    The imager also includes a cloud init config via the UI - which can help you set up the hostname and pre-authorize SSH keys. Note: If you confiure wireless LAN here, you will need to manually set up eth0 with netplan.

  2. Boot up your Raspberry Pi and ssh into it.

  3. Enable these OS container features for Docker and Kubernetes to work properly. Reference

    sudo sed -i '$ s/$/ cgroup_enable=cpuset cgroup_enable=memory cgroup_memory=1 swapaccount=1/' /boot/firmware/cmdline.txt
  4. Let's also disable UFW while we're here per SUSE's recommendations.

    sudo ufw disable
  5. Install these extra modules needed for the Raspberry Pi.

    sudo apt upgrade
    sudo apt install linux-modules-extra-raspi
  6. Ubuntu will complain that the kernel is not up to date, so let's reboot to use the updated version and apply our OS container flags with sudo reboot.

  7. Next, install k3s per their quick start guide. I'm choosing to use NGINX instead of traefik here, which we will configure later.

    Note: The flag --no-deploy is deprecated, so we need to use --disable instead.

    curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="server --disable traefik" sh
  8. Get the kube config from cat /etc/rancher/k3s/k3s.yaml and merge the certificate and secrets into your local .kube/config file, so you can connect to the k3s cluster from your device.

  9. Now that you can call the API from your device, switch to that context and run this command to make sure you have access:

    kubectl config use-context $CONTEXT_NAME
    kubectl get all --all-namespaces
  10. Deploy the NGINX ingress via helm.

    helm upgrade --install ingress-nginx ingress-nginx \
        --repo https://kubernetes.github.io/ingress-nginx \
        --namespace ingress-nginx --create-namespace
  11. Optional: Deploy the Kubernetes Dashboard by applying this config:

    kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.7.0/aio/deploy/recommended.yaml

    You can then follow the steps here to access the dashbaord.

  12. That's it! You can also create a demo deployment to make sure it's working.

    kubectl create deployment demo --image=nginx --port=80
    kubectl create ingress demo --class=nginx --rule="$HOSTNAME/*=demo:80"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment