Architecting Observability with the ELK Stack via Dockerized GitHub Implementations

The Elastic Stack, colloquially known as the ELK stack, represents a powerhouse of data ingestion, analysis, and visualization. At its core, it consists of Elasticsearch, Logstash, and Kibana, though the ecosystem has evolved to include a suite of "Beats" for edge-side data shipping and APM (Application Performance Monitoring) for deep-trace analysis. The primary objective of this stack is to provide users with the capability to analyze any data set by leveraging the advanced searching and aggregation capabilities of Elasticsearch and the sophisticated visualization power of Kibana. For developers and system administrators, deploying this stack from scratch can be an arduous process involving complex configuration files and networking hurdles. This is where specialized GitHub repositories, such as those by garutilorenzo, deviantony, and sherifabdlnaby, become indispensable. These projects provide a containerized framework using Docker and Docker Compose, transforming a complex distributed system into a manageable set of services that can be launched with a few commands.

Technical Architecture and Component Breakdown

The ELK stack is not a single application but a coordinated ecosystem of services. To understand the implementations found on GitHub, one must first understand the technical role of each component and how they interact within a Docker network.

Elasticsearch serves as the heart of the stack. It is a distributed, RESTful search and analytics engine. Technically, it stores data as JSON documents, allowing for near real-time search over massive volumes of data. In a Dockerized environment, Elasticsearch requires significant system resources, specifically memory and virtual memory mapping, to handle the Lucene index.

Logstash acts as the data processing pipeline. It ingests data from multiple sources, transforms it through a series of filters, and sends it to a steady destination—usually Elasticsearch. In the context of the provided GitHub implementations, Logstash is often configured via .yml files located within the container directory, allowing users to define specific input and output plugins.

Kibana is the visualization layer. It provides a web-based interface that allows users to explore the data indexed in Elasticsearch. It translates user queries into Elasticsearch API calls and renders the results as charts, maps, or tables. By default, this interface is exposed on port 5601.

The "Beats" ecosystem extends the stack's reach. Beats are lightweight data shippers. Filebeat, for instance, is designed to monitor log files on a host and ship them to Logstash or Elasticsearch. Metricbeat collects metrics from the operating system and containers, while Heartbeat monitors the availability of the other stack components.

Detailed Analysis of Deployment Implementations

Different GitHub repositories offer different philosophies regarding the deployment of the ELK stack. Depending on whether a user needs a "quick start" template or a "production-ready" blueprint, the choice of repository varies.

The Garutilorenzo Implementation

The implementation by garutilorenzo focuses on providing a comprehensive suite that includes not only the core ELK components but also APM monitoring and various Beats. This version is heavily reliant on the official Docker images provided by Elastic.

One of the critical technical aspects of this deployment is the configuration of Beats. The configurations for each container are stored at the root of the folder under the structure {{ container }}/config/{{ configuration }}.yml.

The operational logic for the Beats in this repository is as follows:

  • Filebeat: This agent is configured to monitor container logs specifically located in /var/lib/docker/containers. To achieve this, it utilizes the add_docker_metadata processor, which requires direct access to the Docker socket at /var/run/docker.sock.
  • Heartbeat: Its primary role in this setup is to monitor the health and uptime of the Elasticsearch and Kibana containers.
  • Metricbeat: This agent monitors the containers running on the host machine. Technically, for Metricbeat to function, the container must have access to /var/run/docker.sock, and the metricbeat user within the container must be part of the docker group. This often requires the user to adjust the Group ID (GID) of the Docker group within the metricbeat/Dockerfile or alternatively run the container as the root user.

The Deviantony Docker-ELK Framework

The docker-elk repository by deviantony is designed as a template for exploration and tweaking rather than a rigid production blueprint. It emphasizes minimal and unopinionated configurations to allow users to learn the system's internals.

The deployment workflow for this repository involves several critical stages:

  1. Cloning: The repository must be cloned onto the Docker host using git clone https://github.com/deviantony/docker-elk.git.
  2. Initialization: Users must run docker compose up setup to initialize the necessary Elasticsearch users and groups.
  3. Key Generation: For enhanced security, users are encouraged to generate encryption keys for Kibana by executing docker compose up kibana-genkeys. The output of this command must be manually copied into the kibana/config/kibana.yml file.
  4. Execution: The stack is launched using docker compose up, or docker compose up -d for detached mode.

A key feature of this implementation is the handling of users and passwords. Upon initial startup, the elastic, logstash_internal, and kibana_system users are initialized with passwords defined in the .env file, which defaults to changeme.

The Elastdocker Approach by Sherifabdlnaby

The elastdocker project takes a more systemic approach to optimization and infrastructure. It introduces several advanced configurations that address common Docker performance bottlenecks.

Technically, this project implements the following enhancements:

  • Memory Management: It parameterizes heap sizes and includes recommended environment configurations such as Ulimits and the disabling of Swap in the Docker Compose files to prevent performance degradation.
  • Cluster Readiness: The architecture is designed to be extended into a multinode cluster, providing a path from a single-node development setup to a scaled production environment.
  • Self-Monitoring: It configures Filebeat agents to ship the ELK logs back into the ELK stack itself, creating a self-observability loop.
  • Tooling: It includes Prometheus Exporters for external monitoring and a Makefile to simplify complex operations into single commands.

The deployment process for elastdocker requires a critical system-level change for Linux hosts. Because the default virtual memory limit is often too low for Elasticsearch, users must execute the following command as root:

sysctl -w vm.max_map_count=262144

The sequence of operations for this setup is:

  1. Clone the repository: git clone https://github.com/sherifabdlnaby/elastdocker.git
  2. Setup: Run make setup to initialize the Elasticsearch Keystore and TLS Self-Signed Certificates.
  3. Launch: Use make elk or docker compose up -d.

Technical Specifications and Resource Requirements

Deploying the ELK stack is resource-intensive. Failure to allocate sufficient hardware resources will lead to container crashes (Out Of Memory kills) or extreme latency.

Hardware and Software Prerequisites

Based on the technical requirements of the elastdocker and docker-elk projects, the following specifications are mandatory:

  • Docker Version: Docker 20.05 or higher is required, utilizing Docker Compose v2.
  • Memory: A minimum of 4GB of RAM is required. For users on Windows or MacOS, this means the Docker Virtual Machine (VM) must be allocated more than 4GB of memory.
  • Virtual Memory: On Linux, the vm.max_map_count must be set to 262144.

Port Mapping and Connectivity

The ELK stack exposes several ports that must be open on the host firewall to allow communication between services and external access.

Port Service Protocol Description
5000 Logstash TCP Logstash TCP input for data ingestion
9200 Elasticsearch HTTP Elasticsearch REST API
9300 Elasticsearch TCP Elasticsearch transport layer for node communication
5601 Kibana HTTP/HTTPS Kibana Web User Interface
8200 APM Server HTTP Application Performance Monitoring endpoint

License Management and Feature Toggles

The Elastic stack offers different licensing tiers, ranging from the Basic (free) license to the Platinum trial. The GitHub implementations handle these differently.

In the garutilorenzo version, paid features are disabled by default via the setting xpack.license.self_generated.type: basic in the elasticsearch.yml file. Users who wish to test the full suite of features for a limited time can change this value to trial, which enables all Platinum features for 30 days.

In the deviantony docker-elk implementation, Platinum features are enabled by default for the 30-day trial. A significant technical advantage of this setup is that after the trial expires, the system seamlessly reverts to the Open Basic license without data loss or the need for manual intervention.

Advanced Configuration and Optimization

For those moving beyond the default installation, the provided GitHub projects offer several mechanisms for optimization.

JVM Heap Size Tuning

Both Elasticsearch and Logstash run on the Java Virtual Machine (JVM), and their memory consumption is governed by heap size settings. In environments where memory is limited (such as Docker Desktop for Mac, which defaults to 2GB), the docker-compose.yml in docker-elk caps the heap size:

  • Elasticsearch: Capped at 512 MB.
  • Logstash: Capped at 256 MB.

Users can override these limits using environment variables:

  • For Elasticsearch: Use ES_JAVA_OPTS.
  • For Logstash: Use LS_JAVA_OPTS.

Image Management and Updates

A critical warning present in these repositories is the need to rebuild images. When a user switches a branch or updates the version of the stack in the .env file, the existing containers may not reflect the changes. The following command must be executed to ensure the latest images and configurations are applied:

docker compose build

To fully reset the environment and remove all associated volumes (which deletes all indexed data), the following command is used:

docker-compose down -v

Log Collection and Data Pipeline Flow

The process of moving a log from a container into a Kibana dashboard involves a specific technical flow.

  1. Discovery: Filebeat discovers the logs in /var/lib/docker/containers.
  2. Parsing: Filebeat uses the add_docker_metadata processor to attach container names and IDs to the log entries.
  3. Shipping: The logs are sent to Logstash (port 5000) or directly to Elasticsearch (port 9200).
  4. Indexing: Elasticsearch processes the logs, indexes the text, and stores them in a searchable format.
  5. Visualization: The user accesses Kibana at http://localhost:5601 (or https:// for the elastdocker version) and creates an index pattern to view the logs.

In the elastdocker project, this process is simplified via a Makefile command:

make collect-docker-logs

This command automates the discovery and shipping process, allowing for "zero configuration" analysis of all Docker containers on the host.

Conclusion: Comparative Analysis of GitHub Implementations

When evaluating the various ELK stack implementations available on GitHub, the choice depends on the intended use case. The garutilorenzo repository is best suited for those who require a wide array of "Beats" and APM capabilities integrated from the start, though it requires more manual adjustment of GIDs for Metricbeat.

The deviantony docker-elk project serves as an ideal educational tool. Its philosophy of "documentation over automation" ensures that users understand the setup process, including the manual generation of encryption keys and the initialization of Elasticsearch users. It provides a safe environment for exploration without the risk of complex, hidden automation scripts.

The sherifabdlnaby elastdocker implementation is the most technically robust for those leaning towards a production-like environment. By addressing JVM heap sizes, Linux virtual memory limits, and integrating Prometheus exporters, it solves the most common failure points of Dockerized ELK deployments. Its use of a Makefile and HTTPS for Kibana makes it the most professional and secure of the three options.

Ultimately, all three repositories demonstrate the power of Docker Compose in orchestrating the Elastic Stack. They transform a distributed system that would typically require hours of manual configuration into a deployable asset that can be initialized in minutes. Whether through the simple docker compose up of docker-elk or the structured make setup of elastdocker, these projects provide the essential infrastructure for modern observability.

Sources

  1. Garutilorenzo ELK Stack
  2. Deviantony Docker-ELK
  3. Sherifabdlnaby Elastdocker
  4. GitHub ELK Stack Topic

Related Posts