A lightweight agent runs on every node and watches log files or the container runtime's log stream. Filebeat, Fluent Bit, Fluentd, Vector, and Promtail are common agents. The agent tails new lines, attaches metadata such as host, pod name, and service, and forwards them.
Before logs land in storage they often pass through a parsing and buffering stage. Raw lines get turned into structured fields (level, status code, latency, trace ID), and a message queue like Kafka or a memory buffer absorbs bursts so a traffic spike does not overwhelm the store. JSON-formatted logs make this parsing trivial, which is why most teams log in JSON.
Storage works one of two ways. Elasticsearch indexes the full text of every field, so any term is searchable fast, at the cost of large indexes and heavy disk and memory use. Grafana Loki takes the opposite approach: it indexes only a small set of labels (service, level, namespace) and stores the log bodies compressed, so it is cheap to run but you filter by label first, then grep within. Loki was designed to be "like Prometheus but for logs" for exactly this cost reason.