Interview's MateKubernetes
Interview's Mate

Kubernetes

K8s · Workloads · GitOps · Cloud

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
Kubernetes topics
Lesson 127/ 160
07. Observability, Troubleshooting & SRE

Centralized Logging with Grafana Loki & OpenSearch/ELK

Centralize logs in Loki or OpenSearch/ELK for search and retention.

IntermediateLoki · OpenSearch · ELK3 quiz questions
Practice DevOps Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

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 opensearch and 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

Loading interactive 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.

Verify OpenSearch, not only object creation

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.

Key takeaway: Loki is implemented only when this invariant remains observable: 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.

Recover from OpenSearch drift

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.

Key takeaway: Accept the trade-off consciously: Loki reduces index cost for label-oriented queries, while ELK offers flexible search at higher ingestion and storage overhead.

How it works, step by step

Step 1 of 4
SRE and service owner

1. 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.

Loki contract → owned state
Key numbers at this step
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 opensearch in 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 opensearch first: 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

Metrics and evidence-led diagnosis
Best for: Centralize logs in Loki or OpenSearch/ELK for search and retention. A concrete incident check is 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.

Ad-hoc console inspection
Best for: Quickly testing the OpenSearch assumption with 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.

Managed observability backend
Best for: Teams that need ELK integrated with guardrails; the evidence path is 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 opensearch without 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?
Interview tip: Interview sequence: state the invariant, run 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

Loading quiz

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.

Open DevOps Q&A →Tech Learn Q&A
Previous topic
Log Collection Architecture (DaemonSet Agents: Fluent Bit, Vector, Promtail)
Next topic
Distributed Tracing with OpenTelemetry Collector & Jaeger/Tempo