What if you could see all your system problems in one place, instantly?
Why Centralized logging (EFK stack) in Kubernetes? - Purpose & Use Cases
Start learning this pattern below
Jump into concepts and practice - no test required
Imagine you run many small shops in different parts of a city. Each shop keeps its own paper logbook to track sales and issues. When you want to see how all shops are doing, you have to visit each one, read their messy notes, and try to piece together the story.
This manual way is slow and frustrating. You waste hours traveling and reading different handwriting. You might miss important problems because some notes are lost or unclear. It's hard to find patterns or spot urgent issues quickly.
The EFK stack (Elasticsearch, Fluentd, Kibana) collects all logs from every shop into one clean, searchable place. Fluentd gathers logs from all sources, Elasticsearch stores and indexes them, and Kibana shows them in easy-to-understand dashboards. Now you can see everything at once, find problems fast, and make smart decisions.
ssh shop1; cat logs.txt ssh shop2; cat logs.txt
kubectl logs -l app=shop
# View all logs centrally in Kibana dashboardWith centralized logging, you can instantly monitor all your systems together and react to issues before they become big problems.
A company running hundreds of Kubernetes pods uses EFK to spot a sudden spike in error messages across pods, helping them fix a bug before customers notice.
Manual log checking is slow and error-prone.
EFK stack centralizes logs for easy searching and visualization.
This helps teams quickly find and fix issues across many systems.
Practice
Solution
Step 1: Understand EFK components
The EFK stack consists of Fluentd (log collector), Elasticsearch (log storage), and Kibana (log viewer).Step 2: Identify the main goal
Its main goal is to centralize logs from all Kubernetes pods for easier troubleshooting and monitoring.Final Answer:
To collect, store, and visualize logs from all pods centrally -> Option AQuick Check:
EFK = Centralized logging [OK]
- Confusing EFK with monitoring CPU/memory
- Thinking EFK manages networking
- Assuming EFK automates deployments
Solution
Step 1: Understand Fluentd deployment needs
Fluentd must run on every node to collect logs from all pods on that node.Step 2: Choose correct Kubernetes resource
DaemonSet ensures one pod per node, perfect for log collectors like Fluentd.Final Answer:
DaemonSet -> Option BQuick Check:
Fluentd runs as DaemonSet [OK]
- Using Deployment which may not run on all nodes
- Confusing ConfigMap with deployment type
- Thinking ServiceAccount deploys pods
match ** {
@type elasticsearch
host elasticsearch.logging.svc.cluster.local
port 9200
}What is the main effect of this configuration?
Solution
Step 1: Analyze Fluentd match directive
The match ** means all logs are matched and processed by this output plugin.Step 2: Understand output plugin settings
@type elasticsearch with host and port means logs are sent to Elasticsearch service at that address.Final Answer:
Fluentd sends all logs to Elasticsearch service at port 9200 -> Option AQuick Check:
match ** + elasticsearch output = send all logs to ES [OK]
- Thinking logs go directly to Kibana
- Assuming logs are stored locally
- Confusing match pattern with pod names
Solution
Step 1: Check Fluentd status
If Fluentd pods are not running, logs won't be collected or sent.Step 2: Verify Elasticsearch connectivity
Wrong port on Elasticsearch service means Fluentd can't send logs properly.Step 3: Confirm Kibana configuration
If Kibana points to wrong Elasticsearch URL, it can't display logs.Final Answer:
All of the above -> Option CQuick Check:
Any broken link in EFK stops logs [OK]
- Checking only one component
- Ignoring service port mismatch
- Assuming Kibana auto-fixes URLs
Solution
Step 1: Understand filtering with Fluentd grep plugin
The grep plugin can exclude logs matching certain patterns using blocks.Step 2: Identify namespaces to exclude
We want to exclude system namespaces like kube-system and default, so pattern must match both.Step 3: Compare options
filter ** { @type grep key kubernetes.namespace_name pattern ^(kube-system|default)$ }excludes both kube-system and default namespaces correctly; others exclude only one or do wrong action.Final Answer:
filter ** { @type grep key kubernetes.namespace_name pattern ^(kube-system|default)$ } -> Option DQuick Check:
Exclude system namespaces with grep exclude pattern [OK]
- Excluding only one namespace
- Using include instead of exclude
- Removing keys instead of filtering logs
