Kubernetes Container Orchestration Monitoring and Logging 3 — Questions and Answers
Question 1: What annotation must be added to a Pod to enable Prometheus to automatically scrape its metrics?
- prometheus.io/scrape: 'true' (Correct answer)
- monitoring.io/enabled: 'true'
- metrics.kubernetes.io/scrape: 'true'
- prometheus.io/collect: 'true'
Correct answer: prometheus.io/scrape: 'true'
The `prometheus.io/scrape: 'true'` annotation signals Prometheus (via its scrape config) to collect metrics from that Pod's endpoint.
Question 2: Which Kubernetes object is most appropriate for deploying a log collection agent on every node in a cluster?
- DaemonSet (Correct answer)
- Deployment
- StatefulSet
- ReplicaSet
Correct answer: DaemonSet
A DaemonSet ensures that exactly one copy of a Pod runs on each node, making it ideal for node-level agents like log collectors.
Question 3: In the EFK stack, what is the role of Elasticsearch?
- Stores and indexes log data for search and retrieval (Correct answer)
- Collects logs from Kubernetes pods
- Visualizes logs in dashboards
- Forwards logs to object storage
Correct answer: Stores and indexes log data for search and retrieval
Elasticsearch is the storage and search engine in the EFK stack, indexing logs collected by Fluentd so they can be queried via Kibana.
Question 4: What does the `--previous` flag do when used with `kubectl logs`?
- Shows logs from the previously terminated container instance (Correct answer)
- Displays logs from 24 hours ago
- Shows logs from a previous Pod version
- Lists logs from terminated namespaces
Correct answer: Shows logs from the previously terminated container instance
The `--previous` flag retrieves logs from the previously terminated container instance, useful for debugging crash-looping containers.
Question 5: Which Prometheus query function calculates the per-second rate of increase of a counter metric over a time range?
- rate() (Correct answer)
- increase()
- delta()
- irate()
Correct answer: rate()
The `rate()` function computes the average per-second increase of a counter over the specified time window, smoothing out spikes.
Question 6: What is the default port that the Kubernetes API server metrics endpoint listens on?
- 6443 (Correct answer)
- 8080
- 10250
- 9090
Correct answer: 6443
The Kubernetes API server exposes metrics (including Prometheus-format metrics) on port 6443, the same port used for API requests.
Question 7: Which tool in the Loki stack is responsible for collecting and shipping logs to Loki?
- Promtail (Correct answer)
- Fluentd
- Logstash
- Filebeat
Correct answer: Promtail
Promtail is the official log collection agent for Loki, tailing log files and forwarding them with labels to the Loki storage backend.
What annotation must be added to a Pod to enable Prometheus to automatically scrape its metrics?