Grafana Setup and Prometheus Integration as a Data Source
1-) Grafana Setup
Persistent Storage Configuration
Since Grafana's data will be stored on a node in a Kubernetes cluster, PersistentVolume (PV) and PersistentVolumeClaim (PVC) definitions are required. This configuration allows Grafana to protect its data in case of shutdown or restart.
The PersistentVolume (PV) and PersistentVolumeClaim (PVC) configuration above allows Grafana to store its data on a specific node. However, the hostPath used here is dependent on the local file system of the specific node where Grafana is running.
Therefore:
If Grafana pods are moved to a different node, they will lose their data unless they have the same hostPath directory on the new node.
To guarantee that pods always run on the same node, it is necessary to pin pods to specific nodes using nodeAffinity or nodeSelector.
Alternatively, NFS, Ceph, Longhorn or a cloud-based storage solution can be used to store data in a node-independent manner.
Grafana ConfigMap Configuration
The username and password to be used in the Grafana interface are stored in the following configmap.
When Grafana is deployed on Kubernetes, it creates a Kubernetes service named grafana and of type NodePort. This service is required for access to Grafana from outside Kubernetes. However, instead of this service, you can use Ingress or whatever structure you use for the connection method in your organization.
2) Setting Prometheus as Data Source on Grafana
1. Sign in to Grafana
2. Click on the Data Source tab in the Left Menu and select Add new data source.
3. Select Prometheus as data source.
4. Enter and save the Prometheus Connection url and other required settings.
5. Click on the Dashboard tab from the Left Menu and select new dashboard.
6. Create a new dashboard and select prometheus as data source.