Skip to main content
In this lesson you’ll deploy the Grafana + Loki logging stack on a Kubernetes cluster and wire it up with Alloy (agent) for log collection. The cluster for this lab already includes networking and an S3-compatible object store provided by SeaweedFS, which we will use as Loki’s object backend. In production you would typically use a managed S3 or GCS backend. Prerequisites
  • A running Kubernetes cluster with access via kubectl.
  • Helm installed and configured to talk to the cluster.
  • SeaweedFS (S3-compatible) available in the logging namespace in this lab.
Verify the cluster components and running pods:
Sample output (cluster system components, storage provisioner, SeaweedFS in the logging namespace):
Overview of what we’ll deploy
  • Grafana — Visualization UI and data source configuration.
  • Loki — Log storage and query engine, backed by SeaweedFS (S3-compatible).
  • Alloy — Agent/DaemonSet to collect pod logs, relabel, and forward to Loki.

Deploy Grafana

Add the Grafana Helm repository and refresh chart indexes:
Create a small values file to expose Grafana via NodePort so it is reachable from the lab environment:
Install Grafana into the logging namespace:
After installation the chart prints useful notes. Retrieve the admin password:
If you need the NodePort URL to reach Grafana from your workstation:
Persistence is disabled by default in this example. You will lose Grafana dashboards and settings if the Grafana pod is deleted or rescheduled unless you enable persistence.
Watch the Grafana pod come up:

Find the Loki Helm chart

Locate the Loki chart within the grafana-community repo:
You should see grafana-community/loki. Note that older charts included Promtail (a now-deprecated agent in some repos). For current Promtail documentation see: https://grafana.com/docs/loki/latest/clients/promtail/

Install Loki

Create a values file to configure Loki for this lab. It sets:
  • Single binary deployment mode.
  • SeaweedFS as an S3-compatible object store.
  • Authentication disabled for lab convenience.
Install the chart into the logging namespace (pin a chart version if desired):
Port-forward the Loki gateway for quick local testing:
Send a test log to Loki (note the required timestamp format in the values array):
Query the test log (the label selector uses curly braces; see the example wrapped below):
Watch the Loki pods start:
List services in the logging namespace to identify the loki-gateway service:
Example output (truncated):

Connecting Grafana to Loki

Retrieve Grafana admin credentials stored as Kubernetes secrets:
Log into Grafana using the NodePort URL you exported earlier and the admin credentials.
A screenshot of Grafana's dark-themed web UI showing the "Welcome to Grafana" home dashboard with panels for a tutorial, adding a data source, and creating a first dashboard. The left sidebar navigation (Home, Dashboards, Explore, Alerting, Administration, etc.) is visible.
In Grafana:
  1. Click Add data source.
  2. Select “Loki”.
  3. Set the URL to the cluster-local Loki gateway: http://loki-gateway.logging.svc.cluster.local/
  4. Click Save & test — Grafana should show a successful connection.
A Grafana settings screenshot showing the "Connections > Data sources > loki" Additional settings page with fields for HTTP settings (allowed cookies, timeout), alerting toggle, query options, and derived fields. A green banner reads "Data source successfully connected" and action buttons ("Delete", "Remove default", "Save & test") appear at the bottom.

Deploy Alloy as a DaemonSet (log collector)

Alloy discovers pod logs, applies relabeling rules, and forwards logs to Loki. Deploy Alloy as a DaemonSet so an instance runs on every node. Create an Alloy Helm values file that configures it as a DaemonSet and provides the Alloy configuration (applied as a ConfigMap):
Install Alloy into the logging namespace:
Verify Alloy pods are running (one per node):
Alloy will:
  • Discover pods via the Kubernetes API.
  • Apply the relabel rules to produce human-friendly labels: namespace, pod, container, app.
  • Forward logs to http://loki-gateway.logging.svc.cluster.local/loki/api/v1/push.

Explore logs in Grafana

  1. Open Grafana and go to the Explore tab.
  2. Select the Loki data source you created.
  3. Use label selectors (for example pod=) and the relabeled fields (namespace, pod, container, app) to filter logs.
  4. You should see logs streaming from system and application pods.
Example log line captured by Loki (truncated):

Troubleshooting tips

  • Watch pods and deployments as they start: kubectl get pods -n logging -w.
  • If pods remain in Pending or ContainerCreating, inspect node resources, taints/tolerations, node selectors, and PVCs.
  • If Loki clients cannot push logs, validate service reachability from the client namespace: kubectl exec -n logging <pod> -- curl -sS http://loki-gateway.logging.svc.cluster.local/loki/api/v1/health.
Quick reference: deployed components

Summary

You have deployed:
  • Grafana for UI and dashboards.
  • Loki for log ingestion and querying, backed by SeaweedFS as an S3-compatible store in this lab.
  • Alloy as a DaemonSet to collect, relabel, and forward pod logs to Loki.
Next steps to take in a production-ready environment:
  • Enable persistence for Grafana (PVCs).
  • Split Loki into multiple components (ingesters, distributor, querier, ruler) with HA and scaling.
  • Use a managed S3/GCS object store for durability.
  • Harden access: enable authentication and secure communication between components.
Links and references

Watch Video

Practice Lab