---
title: Logging with Grafana and Loki
sidebar_label: Grafana and Loki
---

### Install the Prometheus stack:
```
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm upgrade --install prometheus prometheus-community/kube-prometheus-stack --namespace monitor --create-namespace
```

### Install Loki:
```
helm repo add loki https://grafana.github.io/loki/charts
helm upgrade --install loki --namespace=monitoring grafana/loki-stack --create-namespace
```

### Setup Data Sources in Grafana
1. Open the Grafana Dashboard:
    * Port-forward grafana dashboard `kubectl port-forward -n monitor service/prometheus-grafana 3000:80`
    * Get Grafana credentials `kubectl get secrets -n monitor prometheus-grafana -o jsonpath='{.data.admin-password}' | base64 -D`
    * Navigate to [http://localhost:3000](http://localhost:3000)
1. Add a data source by navigating to [http://localhost:3000/datasources](http://localhost:3000/datasources) or click "Data Sources" under the ⚙️ icon from left menu.

    <img width="326" alt="image" src="https://user-images.githubusercontent.com/7482025/194852801-3fde2ff2-5089-4f58-bc92-57ba939c7895.png"></img>
1. Click on "Add Data Sources" and select "Loki" from the list.
    <img width="835" alt="image" src="https://user-images.githubusercontent.com/7482025/194853116-022872b1-38d5-4312-9f2d-11734df59a67.png"></img>
1. Enter the loki endpoint in the `URL` field as `http://loki.monitoring:3100` or to the corresponding `<name>.<namespace>:<port>` value according to your deployment, and click on "Save & test".
    <img width="637" alt="image" src="https://user-images.githubusercontent.com/7482025/194854355-6345ce89-d1a8-409f-9bd7-3a9f0f4329e9.png"></img>
1. Next click on "Explore" or navigate to [http://localhost:3000/explore](http://localhost:3000/explore) and select "Loki" from the dropdown menu. Select the desired Labels and Click on "Run query". Your logs should now start appearing.
    <img width="1358" alt="image" src="https://user-images.githubusercontent.com/7482025/194855100-e0e856d4-d0a3-446d-abcf-25e9466fef62.png"></img>