Deploying the Grafana Stack using Helm Charts
In this section, I will guide you through the process of deploying the Grafana Stack components (Prometheus, Loki, Tempo, and Grafana) and the Nginx ingress controller on your local Kubernetes cluster using Helm charts.
Deploying the kube-prometheus-stack Chart
The kube-prometheus-stack
chart from the Prometheus community repository includes Prometheus, Alertmanager, and Grafana, as well as the necessary exporters and service monitors for Kubernetes cluster monitoring.
- Create a namespace for the Grafana Stack components:
kubectl create namespace monitoring
- Install the
kube-prometheus-stack
Helm chart:
helm install prometheus prometheus-community/kube-prometheus-stack --namespace monitoring
This command deploys Prometheus, Alertmanager, Grafana, and related components in the monitoring
namespace.
Deploying Loki
To deploy Loki, use the loki
chart from the Grafana repository.
- Install the
loki
Helm chart:
helm install loki grafana/loki --namespace monitoring
This command deploys Loki in the monitoring
namespace.
Deploying Tempo
To deploy Tempo, use the tempo
chart from the Grafana repository.
- Install the
tempo
Helm chart:
helm install tempo grafana/tempo --namespace monitoring
This command deploys Tempo in the monitoring
namespace.
Deploying the Nginx Ingress Controller
The Nginx ingress controller is required to expose and access Grafana outside the Kubernetes cluster.
- Create a namespace for the Nginx ingress controller:
kubectl create namespace ingress
- Install the
ingress-nginx
Helm chart:
helm install nginx-ingress ingress-nginx/ingress-nginx --namespace ingress
This command deploys the Nginx ingress controller in the ingress namespace.
Accessing Grafana
To access Grafana, you need to create an ingress resource that maps a domain name to the Grafana service.
- Create a file named
grafana-ingress.yaml
with the following content:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: grafana
namespace: monitoring
annotations:
kubernetes.io/ingress.class: nginx
spec:
rules:
- host: grafana.local
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: prometheus-grafana
port:
number: 80
Replace grafana.local
with the desired domain name for accessing Grafana.
- Apply the ingress resource:
kubectl apply -f grafana-ingress.yaml
- Update your
/etc/hosts
file to map the domain name to your local Kubernetes cluster’s ingress IP address. Find the IP address by running:
kubectl get ingress -n monitoring grafana -o jsonpath='{.status.loadBalancer.ingress[0].ip}'
Add the following line to your hosts file:
<IP_ADDRESS> grafana.local
Replace <IP_ADDRESS>
with the actual IP address and grafana.local
with the domain name you used in the grafana-ingress.yaml
file.
- Access Grafana by opening your web browser and navigating to the domain name specified in the ingress resource (e.g.,
http://grafana.local
). The default username and password for Grafana areadmin
. On your first login, you will be prompted to change the password.
Configuring Grafana Data Sources
After accessing Grafana, you need to configure the data sources for Prometheus, Loki, and Tempo.
Configure the Prometheus data source by navigating to
Configuration > Data Sources
in the Grafana side menu, clicking onAdd data source
, and selectingPrometheus
. Set the URL tohttp://prometheus-kube-prometheus-prometheus.monitoring:9090
and click onSave & Test
.Configure the Loki data source by navigating to
Configuration > Data Sources
in the Grafana side menu, clicking onAdd data source
, and selectingLoki
. Set the URL tohttp://loki.monitoring:3100
and click onSave & Test
.Configure the Tempo data source by navigating to
Configuration > Data Sources
in the Grafana side menu, clicking onAdd data source
, and selectingTempo
. Set the URL tohttp://tempo.monitoring:3200
and click onSave & Test
.
With the Grafana Stack components and the Nginx ingress controller deployed on your local Kubernetes cluster and Grafana configured with the appropriate data sources, you can now start exploring your cluster’s metrics, logs, and traces using Grafana dashboards.