Deploying Prometheus and Grafana using Helm in kubernetes


Hi Everyone!! If you have deployed any application using kubernetes, it is very important to monitor the kubernetes cluster and the application. ‘Monitoring’ plays a crucial role. For monitoring purposes, the popular and widely used tools are prometheus and grafana. They are often used together. Prometheus is used to store the metrics and grafana is a visualization tool.

Prerequisites:

1) Fully functional kubernetes cluster
2) ‘helm’ Command line tool

Steps to deploy Prometheus:

Step1:- create a namespace named ‘prometheus’. Run the following command

kubectl create namespace prometheus

Step2: In helm, there is already a chart named ‘prometheus-community’ which we can use directly to deploy prometheus. To add the ‘prometheus-community’ chart repository. Run the following command.

helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update

Step 3: Deploy Prometheus by running the following command.

helm upgrade -i prometheus prometheus-community/prometheus –namespace prometheus

This command uses the chart ‘prometheus-community’ and installs all prometheus related components in the namespace ‘prometheus’. By default, all default values are used. However, if needed, you can override the values using the ‘–set’ flag.

Once it is done, You can verify if all of the pods in the ‘prometheus’ namespace are in the ‘READY’ state. To check it, Run the command.

kubectl get pods -n Prometheus

Steps to deploy grafana dashboard:

1)Create a namespace named ‘grafana’ by running the following command.

kubectl create namespace grafana

2)Add a grafana repository using helm by running the following command.

helm repo add grafana https://grafana.github.io/helm-charts
helm repo update

3)To deploy grafana, run the following command.

helm install grafana grafana/grafana  –namespace grafana   –set persistence.enabled=true  –set adminPassword=’EKS!sAWSome’ –set datasources.”datasources\.yaml”.apiVersion=1   –set datasources.”datasources\.yaml”.datasources[0].name=Prometheus  –set datasources.”datasources\.yaml”.datasources[0].type=prometheus    –set datasources.”datasources\.yaml”.datasources[0].url=http://prometheus-server.prometheus.svc.cluster.local     –set datasources.”datasources\.yaml”.datasources[0].access=proxy     –set datasources.”datasources\.yaml”.datasources[0].isDefault=true 

This command installs all grafana related components and overrides few default values. Make sure to check the value of ‘datasources[0].url’ which is the url of the ‘prometheus’. ‘adminPassword’ is the password we want to use to login to the grafana dashboard.

Once the above command is run, you can run the following command to verify all the resources in grafana.

kubectl get all -n grafana

When you list the resources, you can find one external-ip for a service named ‘grafana’. Through that url, you can access the grafana dashboard.

If you follow all these steps properly, You will be able to install prometheus and grafana and access the grafana dashboard.

I hope you enjoyed the article. Thanks for reading!!

Leave A Comment

Your email address will not be published. Required fields are marked *