Tag: ubuntu

  • Kubernetes on Raspberry Pi

    Kubernetes on Raspberry Pi

    The goal of this project is to update a single node instance of MicroK8s running on a Raspberry Pi . Having recently updated the Raspberry Pi with the latest LTS version of Ubuntu, the decision was taken to refresh the existing instance of MicroK8s, and at the same time transition from the deprecated Kubernetes Dashboard to a Grafana/Portainer based solution.

    This article documents the steps taken to update the MicroK8s instance and configure network access for Grafana and Portainer CE on the refreshed instance.

    For context I should reiterate the health warning on the projects main page and point out the following;

    1. The Microk8s instance is a development environment not a production environment, so not business critical.
    2. It is a single node instance, not a cluster.
    3. It is not currently running any workloads.
    4. The steps as described worked at the time but past experience of Microk8s would tend to indicate that change is inevitable and as a consequence, things break.

    You are welcome to replicate what you see here but you should ensure that the configuration and security measures taken are sufficient for your needs and adjust them to suit your circumstances.

    Installing MicroK8s/Kubernetes on Raspberry Pi

    This project starts from the base of having an instance of MicroK8s installed on Ubuntu version 26.04 LTS, If you don’t have MicroK8s installed it can be installed via a snap using these instructions.

    Notes for installation…

    At the time of writing the installation instructions were over a year old and there were some differences between the Canonical installation instructions and what was installed for this project.

    • The step to edit cgroups identifies the path /boot/firmware/cmdline.txt. As a result of the Ubuntu’s A/B (tryboot) kernel update scheme the cmdline.txt file was found at /boot/firmware/cmdline.txt.
    • The installation command installs v1.30 of the MicroK8s snap, the latest stable version and the one used in this project is version 1.36. If you are following this starting with a clean MicroK8s installation I would recommend installing at least v1.36 as the upgrade procedure is laborious.

    Refresh MicroK8s

    As there were no workloads running on the instance, the instance was reset to a clean install with the following command.

    This will remove any addons installed and reset the instance to a default state. Uninstalling all addons may seem drastic but upgrading MicroK8s does not upgrade the addons at the same time. This would mean that unsupported addons and deprecated addons would be being disabled with each upgrade step. It seemed cleaner to uninstall all addons from the start, upgrade MicroK8s through all the versions and then reinstall supported addons on the current version.

    Upgrade MicroK8s

    Upgrading MicroK8s is only supported one point at a time i.e. it is inadvisable to skip versions in the upgrade path.

    Install the Addons

    There is some guesswork involved here but the dns and hostpath-storage addons are recommended in the MicroK8s getting started documentation and the MetalLB load balancer and Ingress addons will be required to make the Grafana and Portainer instances available outside the host machine.

    MetalLB installation…

    The Metallb installation prompts for an address pool on the host network. In our case the range 192.168.1.201-192.168.1.250 was selected.

    The configured IP address pool be checked with the following command:

    This is just a basic set of core addons, more addons (cert-manager, observability, portainer) are added later.

    The list of installed and available addons can be confirmed with the following command.

    A review of the running pods and services revealed that the metallb controller and speaker applications were in a crash loop. A search of the logs showed that they were failing due to this known issue of missing RBAC details for configurationstates.

    The following patches were applied:

    1. Create a patch file.
    1. Apply the patch to the controller and the speaker.
    1. Restart the Applications.

    Note: In the issue report the user suggests that there might be a similar problem with servicebgpstatuses. I did not encounter any errors associated with servicebgpstatuses because in this case, its a single instance node (no BGP peers), so I’ve not attempted to fix them here, YMMV.

    Add the Cert-Manager

    The cert-manager addon installs Cert-Manager which provides certificate management services for the cluster. In this case we’ll only be providing self-signed certificates because a lets-encrypt based solution requires a cluster with a public IP address and that isn’t the case here.

    Enable the addon with the command below:

    At this point I created an ingress service but I’m not certain why – could have been a mistake or a test.

    1. Create an ingress service description file
    1. Add the following content.
    apiVersion: v1
    kind: Service
    metadata:
      name: ingress
      namespace: ingress
    spec:
      selector:
        app: ingress
      type: LoadBalancer
      # loadBalancerIP is optional. MetalLB will automatically allocate an IP 
      # from its pool if not specified. You can also specify one manually.
      # loadBalancerIP: x.y.z.a
      ports:
        - name: http
          protocol: TCP
          port: 80
          targetPort: 80
        - name: https
          protocol: TCP
          port: 443
          targetPort: 443
    1. Create the service / apply the yaml.
    1. Check Ingress Service created

    Create the ClusterIssuer (self-sign)

    1. Create a cluster issuer description file
    1. Add the following content.
    apiVersion:  cert-manager.io/v1
    kind: ClusterIssuer
    metadata:
      name: selfsigned
    spec:
      selfSigned: {}
    A Lets Encrypt configuration…

    A configuration for a Lets Encrypt based solution can be found in the official documentation.

    1. Create the ClusterIssuer / apply the yaml.
    1. Confirm the ClusterIssuer has been created.

    Add the Observability Addon.

    At the time of writing there is no documentation for the Observability addon but it is a core addon.

    The observability addon installs a Prometheus / Grafana stack for logs, traces and metrics.

    Enable the addon with the following command.

    Confirm the observability stack has been installed.

    Create a Grafana ingress description file.

    Add the following content.

    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      annotations:
        cert-manager.io/cluster-issuer: selfsigned
      name: grafana-ingress
      namespace:  observability
    spec:
      ingressClassName: public
      tls:
        - hosts:
            - grafana.<hostname>.local
          secretName: grafana-tls
      rules:
      - host: grafana.<hostname>.local
        http:
          paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: kube-prom-stack-grafana
                port: 
                  number: 80
    host(s) key values…

    The value for the host and hosts keys can be any value; domain or subdomain, as long as they are consistent but but should be memorable as they determine how the web address for service, when accessed from the network.

    Create the Grafana ingress / apply the yaml.

    Confirm that the Grafana Ingress has been created and that Certificates are being issued.

    Note the IP Address for the Grafana website.

    The Grafana ingress details above shows the external address for the Grafana website which is required for the hosts file entry below.

    The network does not have a configurable DNS service, so in order to make the services discoverable on the network its necessary to edit the hosts file on each machine that will be accessing the services.

    Add the DNS record to the hosts file /etc/hosts on the client machine.

    # MicroK8s public services on <hostname>.local
    192.168.1.201   grafana.<hostname>.local

    The IP address should match the external IP address of the ingress and the host name should match the host(s) entry in the ingress-grafana.yml file.

    It should be possible to access the Grafana website from the client with either http://grafana.<hostname>.local or https://grafana.<hostname>.local. Note that its not possible to access the website with the external IP address as traefik routing relies on the host header values.

    Grafana website credentials…

    The default Grafana credentials are:

    User name : admin

    The admin default password can be retrieved with the following command.

    Screenshot of a newly installed Grafana dashboard
    Grafana dashboard installed and accessible from the local network.

    Add the Portainer Addon.

    Enable the addon with the following command.

    Confirm the observability stack has been installed.

    Create a Portainer ingress description file.

    Add the following content.

    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      name: portainer-ingress
      namespace: portainer
      annotations:
        cert-manager.io/cluster-issuer: selfsigned
    spec:
      ingressClassName: public
      tls:
      - hosts:
        - portainer.<hostname>.local
        secretName: portainer-tls
      rules:
      - host: portainer.<hostname>.local
        http:
          paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: portainer
                port:
                  number: 9000
    

    Create the Portainer ingress / apply the yaml.

    Confirm that the Portainer Ingress has been created and that Certificates are being issued.

    Note the IP Address for the Portainer website.

    The Portainer ingress details above shows the external address for the Portainer website which is required for the hosts file entry below.

    Note: It will be the same as the Grafana

    Add the DNS record to the hosts file /etc/hosts on the client machine.

    # MicroK8s public services on <hostname>.local
    192.168.1.201   portainer.<hostname>.local

    The IP address should match the external IP address of the ingress and the host name should match the host(s) entry in the ingress-portainer.yml file.

    It should be possible to access the Portainer website from the client with either http://portainer.<hostname>.local or https://portainer.<hostname>.local. Note that its not possible to access the website with the external IP address as Traefik routing relies on the host header values.

    Portainer initial setup requires the initial setup token in order to create the first user.

    The user name defaults to admin but can be changed. The setup token can be obtained with the following command.

    Portainer setup token expiry…

    The Portainer setup token or initial setup page can expire in which case it is a simple matter of redeploying the application to refresh the token.

    Screenshot Portainer dashboard
    Portainer dashboard installed and accessible from the local network.

    With Grafana and Portainer installed and accessible from the network, all that remains is to deploy workloads to the MicroK8s instance and learn how to create dashboards in Grafana so that they can be monitored.

  • Raspberry PI Upgrades

    Raspberry PI Upgrades

    Over the years we have amassed a sizable fleet of Raspberry Pi Computers; each one built and configured, at the time, with a specific purpose in mind, using the current version of Pi OS.

    The only recommended way of updating a Pi OS/Raspbian image is to do a clean install and then re-install apps and copy across files. This is neither a trivial or risk free task and inevitably was never done or resulted in a drift of archived micro SD cards. With the advent of M.2 SSDs as a storage solution for Raspberry Pi Computers a clean re-install looks even less appealing.

    The result is a fleet of Raspberry Pi Computers on different, mostly unsupported, versions of Linux going back to Pi OS Wheezy (probably) and including Ubuntu.

    The aim of this project is to update the fleet to the latest Pi OS (Trixie) or the latest LTS Ubuntu ( 26.0.4.1).

    The first wave of updates are:

    No.TypeOSRelease FromRelease ToDone
    1Pi 4Pi OSBullseye?
    2Pi 4Ubuntu22.04.526.04.1✓
    3Pi 400Pi OSBookwormTrixie✓
    4Pi 5Pi OSBookwormTrixie✓

    Bookworm to Trixie

    The official line from Raspberry Pi Towers is that upgrading a Debian image by major versions is not recommended however this recent post in the Raspberry Pi forums by a Raspberry Pi engineer indicates that although it’s is not recommended, it is possible and here are the commands necessary to achieve it.

    The forum post is heavily caveated and references an article in the Debian documentation which goes into more detail on the upgrade process. The article also includes diagnostic and recovery information in the event that the process encounters errors or fails.

    Below simply walks through the steps described in the original forum post. Additional notes have been added for clarity, but all credit belongs to spI23

    Paying attention to some of the Caveats:

    • We’re not relying on these machines.
    • Any important code is uploaded to GitHub.
    • Any important documents are archived.
    • What’s the worst that can happen: Clean Install and the opportunity to recreate/refresh previous projects.

    Starting with a Bookworm image running desktop under labwc.

    If the Pi is not running under labwc, check to make sure, follow the steps in the dropdown…

    Use the Raspberry Pi Configuration Tool, click on Advanced Options and confirm Wayland (Labwc) is selected, then restart the Pi if the setting changed.

    In a terminal window run the following set of steps:-

    1. Ensure the image is up to date with all recent changes.
    1. Update the apt configuration for Trixie. In the file /etc/apt/sources.list change every reference to “bookworm” to “trixie”.

      Do the same for every file in /etc/apt/sources.list.d in practise, this just means the file raspi.list. Files ending .list and .sources are for third party repositories; Ubuntu, Debian, Docker etc. Files ending with .orig, .save and .bak are ignored by apt so can safely be ignored here.

      Updating these files is easily achieved with nano, refer to the shortcuts listed at the bottom of the nano editor window for Replace, Write, and Exit.
    1. Run apt update to refresh the local package index with the list of Trixie packages.
    1. Remove obsolete Bookworm code.
    1. Upgrade Bookworm packages to Trixie.
    This command is critical – ensure it’s identical and the punctuation is correct.

    It is safest to copy and paste this command line, even refer to the original RPi forum post to ensure it is correct.

    At this point it’s best to leave it running – time for a brew. There are a couple of prompts, at least. One regarding restarting services and another regarding files changed/updated. In each case “yes” is the recommended, correct answer (probably). It worked on my machine. So although there is time to make a brew don’t leave the machine completely and expect it to have finished when you get back; audience participation is required.

    1. Install two new Trixie packages.

    If all has gone well and the process completed without errors then all that is required is a reboot. Before rebooting ensure that the file system has cleared all it’s caches by running the sync command.

    7. Ensure the upgrade process has finished writing to storage and reboot.

    1. After the reboot, confirm that the Pi is running Trixie with the command.

    For the full taskbar based Trixie desktop experience follow the guide published here…

    Ubuntu 22.0.4.5 to 26.04.1

    Ubuntu has a built in command to upgrade to the next release, so in that respect it is relatively easy. But the upgrade is only to the next LTS release so this upgrade will have to be executed in two stages 22.x.x -> 24.x.x then 24.x.x -> 26.x.x. The steps below do not specify the releases to upgrade so they can be used to upgrade any release to the next equivalent major.

    1. Ensure the Pi is up to date with all the latest changes by opening a terminal window and doing.

    2. Update the RPi eeprom to the latest for this release.

    Note if the upgrade is being executed remotely from an ssh session…

    If running remotely/headless, the upgrade process at step 3 below will warn against it because in the event of a failure its harder to see what has happened and harder to recover.

    In this case it might be preferable to shutdown rather than reboot the Pi after the eeprom update/check and then take the opportunity to attach a keyboard and screen.

    The release upgrade process does provide the opportunity to continue or bale out at the point of warning .

    Explanation
    CommandReason
    echo $BOOTFSCheck the BOOTFS env variable hasn’t been set
    mount | grep boot Confirm mount point for firmware
    export BOOTFS=/boot/firmwareSet the BOOTFS env variable
    sudo rpi-eeprom-update Check current version of Rpi eeprom
    sudo rpi-eeprom-update -a Update the rpi-eeprom
    sudo rebootReboot to update, Update will be applied during reboot.

    3. Update the Ubuntu release.

    The release upgrade takes a while, time for a brew, there are a couple of prompts to respond to saying “yes” seems to be the recommended/safest option.

    4. Assuming that the process completed with no errors, ensure the file system caches are empty and reboot.

    This should get you to Ubuntu 24.x.x. From checking the state of the Pi after reboot, the RPi eeprom was already up to date but to be sure check using the following command:

    To complete the journey to LTS release 26.x.x repeat the steps 1,3 and 4 above (assuming that the eeprom is up to date).

    Bullseye to Bookworm or Trixie

    Confirmed by an AI query; the only recommended way to do this is via a clean install. The method above for Bookworm to Trixie will not work due to the differences in architecture between the two releases.

    The AI provides a set of manual steps and there is a clue (perhaps) in the Debian documentation on the subject. As yet this upgrade path remains on the backlog, to do.