Search logs and the audit log
Find any container's output, a node's system journal or who changed what in the cluster, in Grafana or from the command line, including after the pod is gone; add your own log alerts.
Every cluster argoCTL creates keeps its logs for 7 days in Loki, inside the cluster:
- every container's output, labelled with its
namespace,pod,container,nodeandstream(stdoutorstderr); - every node's system journal (kubelet, containerd, the kernel, SSH logins), labelled with its
node, systemdunit,identifierandlevel; - the Kubernetes audit log: one event for every change to the cluster, saying who made it.
Logs stay searchable after a pod is deleted or replaced, and after a node reboots. In Grafana, open the Logs dashboard, or Explore with the Loki data source (see Monitoring and alerts). This guide searches from the command line, which needs nothing but kubectl; Loki itself isn't exposed outside the cluster.
Connect
Run these on the control plane, or on any machine with kubectl and the cluster's kubeconfig.
Forward Loki's port
kubectl -n monitoring port-forward svc/loki 3100:3100 &Get logcli
Use the logcli that matches Loki, 3.7.11: logcli-linux-amd64.zip (or the build for your laptop) from the Loki release.
export LOKI_ADDR=http://localhost:3100
logcli labels namespaceWithout installing anything, run logcli as a one-off pod next to Loki instead:
kubectl -n monitoring run logcli --rm -i --restart=Never \
--image=docker.io/grafana/logcli:3.7.11@sha256:b8a8b85ae2c00942a55af065e0c8e38c57f05f868966b7815b0ea3708b93a367 \
-- --addr=http://loki:3100 query '{namespace="default"}' --since 1hInside the cluster, Loki's HTTP API is at http://loki.monitoring.svc:3100 for any tool that speaks it.
Container logs
logcli query '{namespace="shop"}' --since 1h # a namespace
logcli query '{namespace="shop", pod="web-7d9c6b8f5-x2l4q"}' --since 24h # one pod, even after it's gone
logcli query '{namespace="shop", container="payments"} |= "error"' # one container's lines with "error"
logcli query --tail '{namespace="shop", pod=~"web-.*"}' # follow, like kubectl logs -f
logcli query '{job="kubernetes-pods", node="gpu2"}' --since 30m # every pod on one node
logcli query --from 2026-11-30T10:00:00Z --to 2026-11-30T11:00:00Z '{namespace="shop"}'logcli series '{namespace="shop"}' lists the pods and containers Loki has logs for. Queries use LogQL: a label selector in braces, then filters such as |= "text", != "text" or |~ "regex".
Node journals
logcli query '{job="node-journal", node="gpu2", unit="kubelet.service"}' --since 1h
logcli query '{job="node-journal", unit="containerd.service", level="err"}' --since 24h
logcli query '{job="node-journal", identifier="kernel"} |= "Out of memory"' --since 24h
logcli query '{job="node-journal", unit="ssh.service"} |= "Accepted"' --since 24h # SSH loginsWho changed what: the audit log
The Kubernetes API server records every create, update, patch and delete (who, what, when, from which address, and whether it was allowed), and every read of a Secret or ConfigMap. Request and response bodies are never recorded, so Secret values are never in it. Each line is one JSON event; | json turns its fields into labels such as verb, user_username, objectRef_resource, objectRef_namespace and objectRef_name.
# who created the Deployment "web" in "shop"
logcli query --since 7d '{job="kubernetes-audit"} | json | verb="create" | objectRef_resource="deployments" | objectRef_namespace="shop" | objectRef_name="web"' \
--output jsonl | jq -r '.line | fromjson | [.stageTimestamp, .user.username, .sourceIPs[0], .responseStatus.code] | @tsv'
# every change one user made today
logcli query --since 24h '{job="kubernetes-audit"} | json | user_username="alice@example.com" | verb=~"create|update|patch|delete"'
# who read Secrets in "shop"
logcli query --since 24h '{job="kubernetes-audit"} | json | objectRef_resource="secrets" | objectRef_namespace="shop" | verb=~"get|list"'
# requests the API server refused
logcli query --since 1h '{job="kubernetes-audit"} | json | responseStatus_code="403"'Health checks, leader-election leases, events, the nodes' and the control plane's own reads, and other reads aren't recorded: they're constant background traffic with no audit value.
Log alerts
Loki evaluates log-based alert rules every minute and sends alerts to the cluster's Alertmanager, which routes them like every other cluster alert. Built in:
| Alert | Fires when |
|---|---|
NodeKernelOOMKill | a node ran out of memory and its kernel killed a process |
KubeletEvictingPods | a kubelet is evicting pods to reclaim memory or disk |
KubeletPLEGNotHealthy | a kubelet can't keep up with its containers for 5 minutes |
KubernetesAPIForbiddenRequests | more than 20 requests from one user were refused in 10 minutes |
To add your own, create a ConfigMap in the monitoring namespace with the label loki_rule. Each key is a rule file in Prometheus' format, with a LogQL expression:
apiVersion: v1
kind: ConfigMap
metadata:
name: shop-log-alerts
namespace: monitoring
labels:
loki_rule: ""
data:
shop.yaml: |
groups:
- name: shop
rules:
- alert: ShopPaymentErrors
expr: sum by (pod) (count_over_time({namespace="shop", container="payments"} |= "payment failed" [5m])) > 5
labels:
severity: warning
annotations:
summary: "Payment errors in {{ $labels.pod }}"Loki loads it within a minute. Check what's loaded and what's firing through the port-forward:
curl -s http://localhost:3100/prometheus/api/v1/rules | jq '.data.groups[].name'
curl -s http://localhost:3100/prometheus/api/v1/alerts | jq '.data.alerts[] | {labels, state}'Limits
- 7 days. Older logs are deleted, and lines older than 7 days are refused.
- One log store. Loki runs as one pod with its data on one node's disk, like any
local-pathvolume. While it restarts, the collectors retry and catch up; if that node's disk is lost, so are the logs. Ship logs you must keep longer or elsewhere to your own system. - What's collected is what reaches the files. A container's output is read from the log file the kubelet keeps on its node; lines a container wrote before its node's collector started are read while the file still exists.
Monitoring and alerts
Metrics with Prometheus and kubectl top, alerts through Alertmanager to your own receivers, your own alert rules, silences, the Watchdog heartbeat and Grafana dashboards.
Reimage and recover
Reinstall nodes, apply site-file changes, resume interrupted runs, replace hardware and collect logs for support.