AS
Ahmed Shams

Shams Systems · DevOps Engineer

Operational
Back to Blog & Docs
MonitoringKubernetesDevOps

Centralized Logging on Kubernetes: Elasticsearch, Filebeat & Kibana

A complete guide to architecting a production ELK logging pipeline: DaemonSet log collectors, Index Lifecycle Management (ILM), and Kibana analytics.

AS

Ahmed Shams

Mar 2, 20269 min read

In distributed microservices running on Kubernetes, tracking down bugs by running 'kubectl logs' on individual ephemeral pods is impossible. A centralized logging pipeline with Elasticsearch and Kibana aggregates all stdout/stderr streams into a single, searchable repository.

The ELK Logging Architecture on Kubernetes

  • Collection Layer (Filebeat / Fluent Bit): Runs as a DaemonSet on every node, tailing container log files from /var/log/containers/*.
  • Enrichment: Appends Kubernetes metadata (namespace, pod name, container name, labels) to every log event.
  • Storage Layer (Elasticsearch): Distributed cluster storing inverted index documents with sharding and replication.
  • Visualization Layer (Kibana): Web interface for interactive KQL querying, histogram analysis, and alerting dashboards.

Index Lifecycle Management (ILM)

Uncontrolled logging easily fills multi-terabyte disks. ILM automates index rollouts across hot, warm, and cold storage tiers:

json
{
  "policy": {
    "phases": {
      "hot": {
        "actions": {
          "rollover": {
            "max_primary_shard_size": "50GB",
            "max_age": "7d"
          }
        }
      },
      "warm": {
        "min_age": "7d",
        "actions": {
          "shrink": { "number_of_shards": 1 },
          "forcemerge": { "max_num_segments": 1 }
        }
      },
      "delete": {
        "min_age": "30d",
        "actions": { "delete": {} }
      }
    }
  }
}

Tip

Setting up a 30-day delete phase guarantees your Kubernetes nodes never suffer disk pressure evictions caused by runaway debug logs.

Filebeat DaemonSet Manifest

yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: filebeat-config
  namespace: logging
data:
  filebeat.yml: |
    filebeat.inputs:
    - type: container
      paths:
        - /var/log/containers/*.log
      processors:
        - add_kubernetes_metadata:
            host: ${NODE_NAME}
            matchers:
            - logs_path:
                logs_path: "/var/log/containers/"
    output.elasticsearch:
      hosts: ["http://elasticsearch.logging.svc:9200"]
      index: "k8s-logs-%{[agent.version]}-%{+yyyy.MM.dd}"
“

Observability is knowing that your systems are working; logging is knowing why they failed.

— SRE Reliability Principles