Tag: MicroK8s

  • 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.