DEV Community

akhil mittal
akhil mittal

Posted on

How EKF Simplifies Logging

This is a blog draft summarizing the key points of deploying and configuring the EFK (Elasticsearch, Fluent Bit, Kibana) stack on a Kubernetes cluster, focusing on practical observability for monitoring application logs.

Deploying and Configuring EFK Stack on Kubernetes for Effective Observability

In this guide, we’ll explore setting up an EFK stack—Elasticsearch, Fluent Bit, and Kibana—on a Kubernetes cluster. This setup is part of a broader observability journey, enabling teams to gain deeper insights and quickly troubleshoot issues within distributed systems.

Why Logging Matters in Observability

Logging is crucial for understanding the behavior of applications, especially in distributed systems where services are deployed across multiple nodes or namespaces. Logs offer insights into why an application behaves in a certain way, making it invaluable for debugging and resolving issues.

Introduction to the EFK Stack

The EFK stack is a powerful trio that collects, processes, and visualizes logs:

  • Elasticsearch serves as a scalable database that stores log data.
  • Fluent Bit collects logs from various sources and forwards them to Elasticsearch.
  • Kibana provides a visualization layer, enabling users to search and filter logs via a user-friendly interface.

Components and Setup of EFK on Kubernetes

Step 1: Set Up Elasticsearch

  1. Install Elasticsearch as a stateful set within your Kubernetes cluster. Ensure it’s configured to store data persistently by attaching it to an AWS EBS volume or other persistent storage options. This guarantees that logs are retained even after pod restarts.
  2. Authentication: Retrieve the Elasticsearch username and password, as these credentials will be used by Fluent Bit to forward logs securely.

Step 2: Configure Fluent Bit as a DaemonSet

  • Deploy Fluent Bit as a DaemonSet on Kubernetes. DaemonSets ensure that Fluent Bit runs on every node, which helps capture logs from all containers.
  • Configuration: Define inputs, filters, and outputs in the Fluent Bit configuration file. For instance:
    • Inputs: Set Fluent Bit to read logs from /var/log/containers.
    • Filters: Configure filters to exclude certain namespaces, such as kube-system, if these are irrelevant to your analysis.
    • Outputs: Define Elasticsearch as the destination for log data, using the previously retrieved credentials for authentication.

Step 3: Install Kibana for Log Visualization

  1. Deploy Kibana with a LoadBalancer service type for accessible user interfaces.
  2. Connect to Elasticsearch: Kibana will automatically pull data from Elasticsearch, allowing you to visualize logs and create custom dashboards to filter data by namespace, pod, or specific keywords.

How EFK Simplifies Log Management

In scenarios with hundreds of microservices, manually checking each pod’s logs can be tedious. EFK offers a centralized logging solution where all logs are gathered in one place. This allows for rapid searching across multiple namespaces and services, making it easy to locate issues like database connection failures, intermittent errors, or performance bottlenecks.

Advanced Configuration: Fluent Bit vs. Logstash

While Logstash provides more advanced filtering and processing features, Fluent Bit is lightweight and resource-efficient, making it ideal for Kubernetes. Fluent Bit forwards logs directly to Elasticsearch, which is often sufficient for most organizations, especially those that don’t require complex log transformations.

Wrapping Up

With EFK, Kubernetes users can achieve robust log management, improving observability and enhancing troubleshooting capabilities. Setting up centralized logging also enables quick responses to issues, especially when time is critical. As your observability needs grow, EFK’s flexibility and scalability will make it a cornerstone in your monitoring stack.

This setup, while simple to start, opens the door to a highly effective logging solution that’s scalable and capable of integrating with additional observability tools in the future.

This blog covers the foundational aspects of deploying the EFK stack and offers a practical way to manage logs in Kubernetes, aligning well with the observability goals in modern DevOps practices.

Top comments (0)