Step-by-Step Guide: Setting Up Prometheus and Grafana Using Helm

Step-by-Step Guide: Setting Up Prometheus and Grafana Using Helm

·

3 min read

:If you're looking to monitor your Kubernetes cluster effectively, Prometheus and Grafana are your go-to tools. With Helm, you can easily set up and manage these tools. Here's a straightforward guide to get you started:

Step 1: Install HELM

To install Helm, visit the official Helm website or use the following commands:

curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
chmod 700 get_helm.sh
./get_helm.sh

Step 2: Create a Namespace

Create a namespace for your monitoring tools:

kubectl create namespace monitoring

Step 3: Add Prometheus Community Helm Chart

Add the Prometheus community Helm chart repository:

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

Visit the Prometheus community GitHub repository for more details.

Step 4: Update Helm Repositories

Check the list of Helm repositories and update them:

helm repo list
helm repo update

Step 5: Install the Prometheus Stack

Install the Prometheus stack using Helm with the following command:

helm install prometheus-stack prometheus-community/kube-prometheus-stack \
--namespace monitoring \
--set prometheus.service.nodePort=30000 \
--set grafana.service.nodePort=31000 \
--set grafana.service.type=NodePort \
--set prometheus.service.type=NodePort

Step 6: Check Running Pods

Verify the pods running in the monitoring namespace:

kubectl get pods -n monitoring

Step 7: Check Running Services

View the services in the monitoring namespace:

kubectl get services -n monitoring

Step 8: Port-Forwarding for Prometheus

Set up port-forwarding for Prometheus to access it locally:

kubectl port-forward -n monitoring svc/prometheus-stack-prometheus 9090:9090 -n monitoring

Step 9: Access Prometheus in Your Browser

Open your browser and navigate to http://localhost:9090 to access Prometheus.

Step 10: Port-Forwarding for Grafana

Set up port-forwarding for Grafana:

kubectl port-forward -n monitoring svc/prometheus-stack-grafana 31000:80 -n monitoring

Step 11: Access Grafana in Your Browser

Navigate to http://localhost:31000 in your browser to access Grafana.

Step 12: Get the Grafana Admin Password

Retrieve the admin password for Grafana using this command:

kubectl get secret prometheus-stack-grafana -n monitoring -o jsonpath='{.data.admin-password}' | base64 --decode

Step 13: Log In to the Grafana Dashboard

Use the retrieved password to log in to Grafana. Once logged in, you can explore the pre-configured dashboard.

Step 14: Prometheus as Data Source

Prometheus is already set as a data source when using the Helm chart, so you can skip additional configurations.

Step 15: Create a Dashboard Based on Namespace

Create a custom dashboard in Grafana to visualize metrics based on your namespace.

Step 16: Import Pre-Built Dashboards

Visit the Grafana Dashboards site to browse pre-built dashboards. Copy the dashboard ID, import it into Grafana, and use Prometheus as the data source.

Here's how it will look:


That's it! You've successfully set up Prometheus and Grafana using Helm. Start monitoring your Kubernetes cluster efficiently and make data-driven decisions. If you found this guide helpful, share it with your network or leave a comment below!