- 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.
- A running Kubernetes cluster with the logging stack (Loki + Grafana) already installed.
kubectl,helm, andbase64(or equivalent) available on your workstation.
1) Retrieve Grafana admin credentials and install Alloy
Inspect the Grafana secret in thelogging namespace and decode the admin user and password:
logging namespace (condensed):
2) Deploy the example application
Create a Deployment namedapi that uses the kodekloud/loki-demo image and emits structured JSON logs to stdout.
app-deployment.yaml:
3) Verify logs are emitted to stdout
Once the pod is Running, tail its logs to confirm the app emits structured JSON lines: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: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.