This article is part of the series Build your very own self-hosting platform with Raspberry Pi and Kubernetes
- Install Raspbian Operating-System and prepare the system for Kubernetes
- Install and configure a Kubernetes cluster with k3s to self-host applications
- Deploy NextCloud on Kuberbetes: The self-hosted Dropbox
- Self-host your Media Center On Kubernetes with Plex, Sonarr, Radarr, Transmission and Jackett
- Self-host Pi-Hole on Kubernetes and block ads and trackers at the network level
- Self-host your password manager with Bitwarden
- Deploy Prometheus and Grafana to monitor a Kubernetes cluster
Monitoring is an important part of the maintenance of a Kubernetes cluster to gain visibility on the infrastructure and the running applications and consequently detect anomalies and undesirables behaviours (service downtime, errors, slow responses).
Prometheus and Grafana is a common combination of tools to build up a monitoring system where Prometheus acts as a data collector pulling periodically metrics from different systems and Grafana as a dashboard solution to visualise the data.
Specifically for Kubernetes, a great Open-Source project called cluster-monitoring offers a scripts to automate the installation and configuration of Prometheus + Grafana and provides a lot of dashboards for Kubernetes out of the box.
In order to run entirely the tutorial, we will need:
- A running Kubernetes cluster (see previous articles if you haven’t set this up yet)
- Install Golang on the machine that runs
$ sudo apt install golang-go
1. Clone the repository
Clone the repository
cluster-monitoring with the following command (change ~/workspace/cluster-monitoring by the target folder of your choice):
$ git clone https://github.com/carlosedp/cluster-monitoring.git ~/workspace/cluster-monitoring
Then open the file
~/workspace/cluster-monitoring/vars.jsonnet and modify the following sections:
Enable k3s and put the IP of our master node
The suffix domain is used to deploy an ingress to access Prometheus
prometheus.<suffixDomain> and Grafana
grafana.<suffixDomain>. You can manually configure a DNS entry to point to
192.168.0.240 (Load Balancer IP of the Nginx) or used nip.io to automatically resolve a domain to an IP (basically it resolves
<ip> without requiring any other configuration).
Enable the persistence to store the metrics (Prometheus) and dashboard settings (Grafana).
Once we’ve done the configuration part, we can now proceed to the installation.
Navigate into the folder
$ cd ~/workspace/cluster-monitoring/
make vendor to download all the necessary packages.
$ make vendor
Finally deploy the monitoring stack with the command
$ make deploy
Repeat this command again if you see some errors as a result.
Once deployed, check that the namespace
monitoring has all the components up and running.
$ kubectl get pods -n monitoring -o wide
After configuring and deploying our Kubernetes Monitoring stack, you can now access the different components:
Click on the Grafana link and login with the default login/password
admin/admin (you will be asked to choose a new password)
You can now finally enjoy a lot of pre-configured dashboards for your Kubernetes cluster.