Centralized logging (EFK stack) in Kubernetes - Time & Space Complexity
Start learning this pattern below
Jump into concepts and practice - no test required
When using the EFK stack for centralized logging in Kubernetes, it's important to understand how the processing time grows as logs increase.
We want to know how the system handles more logs and how that affects performance.
Analyze the time complexity of the following Kubernetes Fluentd configuration snippet.
apiVersion: v1
kind: ConfigMap
metadata:
name: fluentd-config
namespace: logging
data:
fluent.conf: |
<source>
@type tail
path /var/log/containers/*.log
tag kubernetes.*
</source>
<match kubernetes.**>
@type elasticsearch
host elasticsearch.logging.svc.cluster.local
port 9200
</match>
This config tells Fluentd to read all container logs and send them to Elasticsearch for indexing.
- Primary operation: Fluentd reads each log line from all container log files.
- How many times: Once per log line, continuously as new logs are generated.
As the number of log lines grows, Fluentd processes each line individually.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 log lines | 10 processing steps |
| 100 log lines | 100 processing steps |
| 1000 log lines | 1000 processing steps |
Pattern observation: The processing grows linearly with the number of log lines.
Time Complexity: O(n)
This means the time to process logs grows directly in proportion to the number of log lines.
[X] Wrong: "Fluentd processes all logs instantly regardless of size."
[OK] Correct: Each log line must be read and sent, so more logs mean more work and time.
Understanding how log processing scales helps you design systems that handle growth smoothly and avoid bottlenecks.
"What if Fluentd batches multiple log lines before sending to Elasticsearch? How would the time complexity change?"
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
