Skip to main content
This guide shows how to deploy a tiny example application to a Kubernetes cluster where logs are already collected and forwarded to Grafana Loki. You will:
  • Retrieve Grafana credentials and (optionally) install Alloy.
  • Deploy a simple app that writes structured JSON logs to stdout.
  • Verify logs locally with kubectl logs.
  • Confirm the logs are visible in Grafana Assistant (Grafana Loki) using a LogQL query.
Prerequisites:
  • A running Kubernetes cluster with the logging stack (Loki + Grafana) already installed.
  • kubectl, helm, and base64 (or equivalent) available on your workstation.

1) Retrieve Grafana admin credentials and install Alloy

Inspect the Grafana secret in the logging namespace and decode the admin user and password:
If Alloy is not already installed, install it via Helm (using your values file):
Example output from the Helm install and the pods in the logging namespace (condensed):

2) Deploy the example application

Create a Deployment named api that uses the kodekloud/loki-demo image and emits structured JSON logs to stdout. app-deployment.yaml:
Apply the manifest and watch the pod start:
Example progress (condensed):

3) Verify logs are emitted to stdout

Once the pod is Running, tail its logs to confirm the app emits structured JSON lines:
Sample JSON log lines emitted by the app (streamed):
The log collector performs automatic discovery of pod logs (stdout/stderr) and forwards them to Grafana Loki, so applications that write to standard output are collected without extra configuration.

4) Query the logs in Grafana (Explore view)

Open Grafana Assistant (Explore view) and run a Loki query that filters by the Deployment label we applied. For example:
This LogQL expression selects log streams with the app="api" label and returns all log lines. Running it should stream the same JSON lines you saw with kubectl logs, confirming the logs reached Grafana Loki. Example formatted output in Grafana Assistant (condensed):

Quick reference

Summary

  • Deploy the example app and verify it writes structured JSON logs to stdout using kubectl logs.
  • The cluster log collector auto-discovers pod stdout/stderr and forwards those logs to Grafana Loki—no per-app config required for stdout logs.
  • Use a Grafana (Explore) LogQL query such as {app="api"} |= "" to view application logs in Grafana Assistant.

Watch Video