We will see how to install/ set-up Loki in Kubernetes, add Promtail, and connect to the Grafana dashboard. Loki in a distributed mode is generally better for scaling compared to running Loki in a single-instance mode.
We have already installed Grafana. So we will focus only on the Loki setup.
![]() |
Loki workflow diagram |
1. Install prometheus & Grafana.
These are some basic commands, you will understand by looking at them, no need to dive deep into that.
# Check Helm Installation helm version # Adding Helm repo helm repo add prometheus-community https://prometheus-community.github.io/helm-charts # Update repo helm repo update # helm repo update helm search repo prometheus-community # Install Stack helm install prometheus prometheus-community/kube-prometheus-stack -n monitoring --create-namespace # Get all Info kubectl get all -n monitoring2. Port-forward to open grafana. You can also use Ingress to expose it to outer world.
# Expose Grafana Service kubectl port-forward service/prometheus-grafana -n monitoring 80:80 # (Optional) Check Prometheus End Point. kubectl port-forward service/prometheus-operated -n monitoring 9090:9090Open the serviced URL in browser.
2. Setup Loki
helm repo add grafana https://grafana.github.io/helm-charts helm repo update helm show values grafana/loki-distributed > loki-distributed-overrides.yaml helm upgrade --install --values loki-distributed-overrides.yaml loki grafana/loki-distributed -n loki --create-namespaceUpdate the Endpoint URL of above file. Change Namespace accordingly.
3. Installing Promtail:
Promtail is a log collector agent, installed on every node and sends data to the Loki operator. It reads log files from various sources and transforms them into a specific format.
helm upgrade --install --values promtail-overrides.yaml promtail grafana/promtail -n lokiAdding Loki data source in Grafana dashboards.