Your submission was sent successfully! Close

Thank you for contacting us. A member of our team will be in touch shortly. Close

You have successfully unsubscribed! Close

Thank you for signing up for our newsletter!
In these regular emails you will find the latest updates about Ubuntu and upcoming events where you can meet our team.Close

Edge computing monitoring with Kubernetes

This article was last updated 5 years ago.


This blog demonstrates how to easily deploy monitoring tools at the edge using Kubernetes. In IoT scenarios, such a deployment brings the benefits of privacy, latency and minimal bandwidth cost.

Luckily, MicroK8s the single node Kubernetes, caters for such use cases. The beauty of MicroK8s is that deployment can be done in a couple of commands and in under a minute. MicroK8s can even fit on a Raspberry Pi. It is possible to build a monitoring stack on MicroK8s, deployable anywhere, even at the extreme edge. From a technical perspective, this simple solution is created using some of the popular open source components that are delivered out of the box with MicroK8s. These are: 

  • Grafana for the front-end analytics dashboard
  • Prometheus for the back-end time-series database (ideal for sensor data)

To get up and running, follow these steps:

Installing MicroK8s, Grafana and Prometheus

First, install the MicroK8s snap

sudo snap install microk8s --classic

Once installed, it is possible to list all the add-ons that are delivered with MicroK8s.

microk8s.status

(alternatively)

 microk8s.enable --help

None of the MicroK8s add-ons are enabled by default. Therefore Grafana and Prometheus will need to be enabled upon installation. Here is how to launch these applications:

microk8s.enable dashboard prometheus

There is no specific command to enable Grafana. It is launched automatically when the Kubernetes dashboard is enabled.

Accessing the Kubernetes dashboard

For the next steps, the kubectl command will be invoked. It is possible to alias this command because it is namespaced in Microk8s. This step is simple to reverse if it loses convenience.

sudo snap alias microk8s.kubectl kubectl

The access token for the Kubernetes dashboard can then be retrieved by invoking kubectl as shown below:

export TOKEN=$(kubectl describe secret $(kubectl get secret | awk '/^dashboard-token-/{print $1}') | awk '$1=="token:"{print $2}') && echo -e "\n--- Copy and paste this token for dashboard access --\n$TOKEN\n---"

To access the Kubernetes dashboard, it will be necessary to create a secure channel to the cluster with the command below:

kubectl proxy &

The dashboard will then be accessible at:

http://localhost:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/

Copying and pasting the token generated above will grant you access to the web based command interface to your cluster.

Accessing Grafana and Prometheus

As an initial step, we can confirm that Grafana and Prometheus are running on the cluster.

kubectl cluster-info

Once confirmed, you can view these services in the Kubernetes dashboard by selecting ‘monitoring’ under ‘Namespaces’, and then clicking ‘Services’. The list of monitoring services running on the cluster will then be displayed, along with the associated cluster IP addresses, internal endpoints and ports.

The Grafana and Prometheus UIs can then be simply accessed by entering the service IP and ports in the browser, according to the following format:

<cluster IP>:<port>

For Grafana, the username and password will be: admin/admin.

Grafana comes pre-configured with Prometheus as a data source.

The Prometheus UI can be accessed in a similar manner. No username and password will be required.

Going further

Further to this easy setup, it is possible to feed sensor data to the Prometheus database. Prometheus has several client libraries for exporting sensor measurements. Additionally, panels and custom dashboards will be created in Grafana according to the metrics that are tracked for a particular use case.

Resources

MicroK8s

Running Microk8s on Raspberry Pi

Prometheus client libraries

Grafana basic concepts

smart start

IoT as a service

Bring an IoT device to market fast. Focus on your apps, we handle the rest. Canonical offers hardware bring up, app integration, knowledge transfer and engineering support to get your first device to market. App store and security updates guaranteed.

Get your IoT device to market fast ›

smart start logo

IoT app store

Build a platform ecosystem for connected devices to unlock new avenues for revenue generation. Get a secure, hosted and managed multi-tenant app store for your IoT devices.

Build your IoT app ecosystem ›

Newsletter signup

Get the latest Ubuntu news and updates in your inbox.

By submitting this form, I confirm that I have read and agree to Canonical's Privacy Policy.

Related posts

How should a great K8s distro feel? Try the new Canonical Kubernetes, now in beta

Try the new Canonical Kubernetes beta, our new distribution that combines ZeroOps for small clusters and intelligent automation for larger production...

Meet Canonical at KubeCon + CloudNativeCon North America 2024

We are ready to connect with the pioneers of open-source innovation! Canonical, the force behind Ubuntu, is returning as a gold sponsor at KubeCon +...

What is IoT device management?

IoT device management refers to processes or practices used to deploy, monitor and maintain IoT devices. As organizations scale up their IoT efforts, a solid...