Centralized Logging with Grafana Loki & OpenSearch/ELK
Centralize logs in Loki or OpenSearch/ELK for search and retention.
In plain words
Loki is a labeled archive of sealed tape reels, while OpenSearch is a card catalog indexing more facts inside every page. The simple Kubernetes rule is: Loki indexes labels and stores compressed log chunks, while OpenSearch or ELK-style systems index documents for richer queries; both centralize retention, access, and search.
Think of it like…
Loki is a labeled archive of sealed tape reels, while OpenSearch is a card catalog indexing more facts inside every page.
Where you’ve seen it
An SRE testing a diagnosis runs kubectl get pvc -n logging; curl -s http://loki:3100/ready; kubectl get svc -n logging | grep opensearch. Expected evidence: Loki indexes labels and stores compressed log chunks, while OpenSearch or ELK-style systems index documents for richer queries; both centralize retention, access, and search. If the run instead shows this symptom, stop and restore the last known state: High-cardinality Loki labels explode streams, and unconstrained OpenSearch field mappings or replica pressure turn unbounded logs into cost and cluster failure.
Words you’ll hear
- Loki
- For this lesson, Loki is the controlling idea: Loki indexes labels and stores compressed log chunks, while OpenSearch or ELK-style systems index documents for richer queries; both centralize retention, access, and search.
- OpenSearch
- OpenSearch is the checkpoint; run
kubectl get pvc -n logging; curl -s http://loki:3100/ready; kubectl get svc -n logging | grep opensearchand inspect the owner chain. High-cardinality Loki labels explode streams, and unconstrained OpenSearch field mappings or replica pressure turn unbounded logs into cost and cluster failure. - ELK
- ELK is the outcome to preserve; the cost is explicit: Loki reduces index cost for label-oriented queries, while ELK offers flexible search at higher ingestion and storage overhead.
- Verification evidence
- The evidence command is
kubectl get pvc -n logging; curl -s http://loki:3100/ready; kubectl get svc -n logging | grep opensearch. It connects the declaration to this behavior: Centralize logs in Loki or OpenSearch/ELK for search and retention.
Visual diagram
Theory & deep dive
How Loki reaches the intended state
Centralize logs in Loki or OpenSearch/ELK for search and retention. Loki indexes labels and stores compressed log chunks, while OpenSearch or ELK-style systems index documents for richer queries; both centralize retention, access, and search.
The concrete checkpoint is kubectl get pvc -n logging; curl -s http://loki:3100/ready; kubectl get svc -n logging | grep opensearch; compare the Loki owner, OpenSearch state, and ELK outcome instead of treating YAML acceptance as proof.
Run kubectl get pvc -n logging; curl -s http://loki:3100/ready; kubectl get svc -n logging | grep opensearch after the change and correlate the result with Events and the owning object. Loki indexes labels and stores compressed log chunks, while OpenSearch or ELK-style systems index documents for richer queries; both centralize retention, access, and search.
OpenSearch: failure boundary and production cost
High-cardinality Loki labels explode streams, and unconstrained OpenSearch field mappings or replica pressure turn unbounded logs into cost and cluster failure. The prerequisite contract is concrete: Loki indexes labels and stores compressed log chunks, while OpenSearch or ELK-style systems index documents for richer queries; both centralize retention, access, and search.
Loki reduces index cost for label-oriented queries, while ELK offers flexible search at higher ingestion and storage overhead. A safe design limits blast radius, records the last good configuration, and uses kubectl get pvc -n logging; curl -s http://loki:3100/ready; kubectl get svc -n logging | grep opensearch as a deterministic rollback checkpoint.
Capture the current state with kubectl get pvc -n logging; curl -s http://loki:3100/ready; kubectl get svc -n logging | grep opensearch, then correct the controlling manifest rather than patching a child object; the relevant divergence signal is specific: High-cardinality Loki labels explode streams, and unconstrained OpenSearch field mappings or replica pressure turn unbounded logs into cost and cluster failure.
How it works, step by step
Step 1 of 41. Define the symptom and SLI
Turn the user symptom into a measurable question and select a telemetry source: Loki indexes labels and stores compressed log chunks, while OpenSearch or ELK-style systems index documents for richer queries; both centralize retention, access, and search.
- Goal
- Centralize logs in Loki or OpenSearch/ELK for search and retention.
- Owner
- Loki
When to use it & trade-offs
What it is
Centralize logs in Loki or OpenSearch/ELK for search and retention. Loki indexes labels and stores compressed log chunks, while OpenSearch or ELK-style systems index documents for richer queries; both centralize retention, access, and search.
Why it matters: High-cardinality Loki labels explode streams, and unconstrained OpenSearch field mappings or replica pressure turn unbounded logs into cost and cluster failure. The invariant at risk is specific: Loki indexes labels and stores compressed log chunks, while OpenSearch or ELK-style systems index documents for richer queries; both centralize retention, access, and search. The quickest fact check before changing the design is kubectl get pvc -n logging; curl -s http://loki:3100/ready; kubectl get svc -n logging | grep opensearch.
When to reach for it
- Use Loki to enforce this invariant: Loki indexes labels and stores compressed log chunks, while OpenSearch or ELK-style systems index documents for richer queries; both centralize retention, access, and search.
- Use OpenSearch evidence from
kubectl get pvc -n logging; curl -s http://loki:3100/ready; kubectl get svc -n logging | grep opensearchin reviews and incident timelines. Centralize logs in Loki or OpenSearch/ELK for search and retention. - Choose the managed observability backend route only when this cost is justified by governance or scale: Loki reduces index cost for label-oriented queries, while ELK offers flexible search at higher ingestion and storage overhead.
When to avoid or be careful
- Avoid assuming Loki is complete after YAML submission; the required behavior is concrete: Loki indexes labels and stores compressed log chunks, while OpenSearch or ELK-style systems index documents for richer queries; both centralize retention, access, and search.
- Avoid treating the next symptom as random; check the owner and state with
kubectl get pvc -n logging; curl -s http://loki:3100/ready; kubectl get svc -n logging | grep opensearchfirst: High-cardinality Loki labels explode streams, and unconstrained OpenSearch field mappings or replica pressure turn unbounded logs into cost and cluster failure. - Avoid adopting a heavier platform wrapper before measuring its cost: Loki reduces index cost for label-oriented queries, while ELK offers flexible search at higher ingestion and storage overhead.
Native, manual, and managed paths for Loki
kubectl get pvc -n logging; curl -s http://loki:3100/ready; kubectl get svc -n logging | grep opensearch.Strengths: Loki indexes labels and stores compressed log chunks, while OpenSearch or ELK-style systems index documents for richer queries; both centralize retention, access, and search.
Watch out: Loki reduces index cost for label-oriented queries, while ELK offers flexible search at higher ingestion and storage overhead. Recovery must also recognize this signal: High-cardinality Loki labels explode streams, and unconstrained OpenSearch field mappings or replica pressure turn unbounded logs into cost and cluster failure.
kubectl get pvc -n logging; curl -s http://loki:3100/ready; kubectl get svc -n logging | grep opensearch; the expected invariant is: Loki indexes labels and stores compressed log chunks, while OpenSearch or ELK-style systems index documents for richer queries; both centralize retention, access, and search.Strengths: kubectl get pvc -n logging; curl -s http://loki:3100/ready; kubectl get svc -n logging | grep opensearch gives immediate feedback without first building a platform layer.
Watch out: A manual change can hide drift, and unlike Loki, it does not make this symptom self-documenting: High-cardinality Loki labels explode streams, and unconstrained OpenSearch field mappings or replica pressure turn unbounded logs into cost and cluster failure.
kubectl get pvc -n logging; curl -s http://loki:3100/ready; kubectl get svc -n logging | grep opensearch.Strengths: Platform controls can wrap this exact behavior in policy or dashboards: Loki indexes labels and stores compressed log chunks, while OpenSearch or ELK-style systems index documents for richer queries; both centralize retention, access, and search.
Watch out: The added platform ownership buys value at this cost: Loki reduces index cost for label-oriented queries, while ELK offers flexible search at higher ingestion and storage overhead.
Interview signals & numbers to know
When this topic comes up
- Interview anchor: Loki indexes labels and stores compressed log chunks, while OpenSearch or ELK-style systems index documents for richer queries; both centralize retention, access, and search.
- Trace Loki to ELK through OpenSearch; the invariant is: Loki indexes labels and stores compressed log chunks, while OpenSearch or ELK-style systems index documents for richer queries; both centralize retention, access, and search.
- Recognize the symptom: High-cardinality Loki labels explode streams, and unconstrained OpenSearch field mappings or replica pressure turn unbounded logs into cost and cluster failure.
- Justify the cost: Loki reduces index cost for label-oriented queries, while ELK offers flexible search at higher ingestion and storage overhead.
- Verify with kubectl get pvc -n logging; curl -s http://loki:3100/ready; kubectl get svc -n logging | grep opensearch instead of only inspecting YAML.
Benchmarks & rules of thumb
- 2
- log-backend designs compared: label-indexed and full-text-oriented
- 1
- retention policy must cover compliance and cost
- 0
- centralized logs prove delivery when agents are backpressured
Common mistakes & follow-ups
Common interview mistakes
- Debugging only the child object misses the Loki owner contract: Loki indexes labels and stores compressed log chunks, while OpenSearch or ELK-style systems index documents for richer queries; both centralize retention, access, and search.
- Ignoring this telltale condition leads to unrelated changes: High-cardinality Loki labels explode streams, and unconstrained OpenSearch field mappings or replica pressure turn unbounded logs into cost and cluster failure.
- Repeating
kubectl get pvc -n logging; curl -s http://loki:3100/ready; kubectl get svc -n logging | grep opensearchwithout an owner for remediation wastes retry cost. Loki reduces index cost for label-oriented queries, while ELK offers flexible search at higher ingestion and storage overhead.
Likely interviewer follow-ups
- How would API output and runtime evidence prove this behavior: Loki indexes labels and stores compressed log chunks, while OpenSearch or ELK-style systems index documents for richer queries; both centralize retention, access, and search?
- Which owner object, logs, and Events would you inspect for this symptom-High-cardinality Loki labels explode streams, and unconstrained OpenSearch field mappings or replica pressure turn unbounded logs into cost and cluster failure-?
- At what threshold would this cost become unacceptable: Loki reduces index cost for label-oriented queries, while ELK offers flexible search at higher ingestion and storage overhead?
kubectl get pvc -n logging; curl -s http://loki:3100/ready; kubectl get svc -n logging | grep opensearch, name the failure, then justify the cost. Invariant: Loki indexes labels and stores compressed log chunks, while OpenSearch or ELK-style systems index documents for richer queries; both centralize retention, access, and search. Failure: High-cardinality Loki labels explode streams, and unconstrained OpenSearch field mappings or replica pressure turn unbounded logs into cost and cluster failure. Cost: Loki reduces index cost for label-oriented queries, while ELK offers flexible search at higher ingestion and storage overhead.Knowledge check
Put it into practice
Practice related interview Q&A
Apply Centralized Logging with Grafana Loki & OpenSearch/ELK with generative AI interview Q&A and hands-on practice.