(K3S - 8/8) Deploy Prometheus and Grafana to monitor a Kubernetes cluster
This article is part of the series Build your very own self-hosting platform with Raspberry Pi and Kubernetes
- Introduction
- 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
Introduction
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.
Prerequisite
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
kubectl
1 | $ sudo apt install golang-go |
Configuration
1. Clone the repository
Clone the repository cluster-monitoring
with the following command (change ~/workspace/cluster-monitoring by the target folder of your choice):
1 | $ git clone https://github.com/carlosedp/cluster-monitoring.git ~/workspace/cluster-monitoring |
2. Configuration
Then open the file ~/workspace/cluster-monitoring/vars.jsonnet
and modify the following sections:
Enable k3s and put the IP of our master node kube-master
.
1 | k3s: { |
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 <anything>.<ip>.nip.io
by <ip>
without requiring any other configuration).
1 | suffixDomain: '192.168.0.240.nip.io', |
Enable the persistence to store the metrics (Prometheus) and dashboard settings (Grafana).
1 | enablePersistence: { |
Installation
Once we’ve done the configuration part, we can now proceed to the installation.
Navigate into the folder cluster-monitoring
.
1 | $ cd ~/workspace/cluster-monitoring/ |
First run make vendor
to download all the necessary packages.
1 | $ make vendor |
Finally deploy the monitoring stack with the command make deploy
.
1 | $ 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.
1 | $ kubectl get pods -n monitoring -o wide |
Dashboard
After configuring and deploying our Kubernetes Monitoring stack, you can now access the different components:
- Prometheus: https://prometheus.192.168.0.240.nip.io
- Grafana: https://grafana.192.168.0.240.nip.io
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.