Kubernetes Loki Error Log Deduplication and Slack Alerting - n8n Workflow

Use this powerful n8n workflow to monitor Kubernetes logs stored in Grafana Loki, automatically deduplicate recurring errors using a custom n8n node, and send unique, actionable alerts directly to Slack.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • DevOps Engineers and SREs needing reliable, spam-free Kubernetes error alerting.

  • Teams utilizing Grafana Loki for centralized log aggregation.

  • Users looking for advanced logic handling within an n8n workflow, specifically custom deduplication.

  • Administrators who want to reduce 'alert fatigue' caused by recurring transient errors.

Overview

Managing logs from large Kubernetes clusters (EKS, GKE, AKS) can quickly overwhelm monitoring channels like Slack if the same error repeats hundreds of times. This advanced n8n workflow solves the problem of alert fatigue by acting as an intelligent intermediary between Grafana Loki and Slack. The core value of this n8n template lies in its custom deduplication logic. After fetching the raw error logs, a specialized n8n node processes them, normalizing the log text (e.g., stripping unique timestamps and IDs) to identify truly similar errors within the batch. Only unique, parsed errors are forwarded, ensuring that your team receives clear, actionable alerts without being flooded by spam. This robust n8n automation provides a clean, scheduled monitoring solution.

How it Works

This n8n workflow operates on a fixed schedule, functioning as a pull-based alerting mechanism:


  1. Scheduled Activation: The process begins with the Schedule n8n trigger, configured to execute the entire n8n workflow every 5 minutes.

  2. Loki Query: An HTTP Request n8n node queries the configured Loki endpoint. It requests all logs containing the string "error" within the specified time range (the last 10 minutes).

  3. Log Parsing and Filtering: The first Code n8n node (🧹 Extract Log Fields) processes the structured data returned by Loki. It intelligently attempts to extract the relevant log content, along with associated metadata (pod, namespace, container, node). Crucially, this step also filters out lower-priority logs like debug or info that might have been accidentally caught by the initial Loki query.

  4. Deduplication Logic: The second Code n8n node (🧠 Remove Duplicate Alerts) implements the core anti-spam logic. It normalizes the extracted log message by masking dynamic elements (timestamps, numbers, quoted strings). It then generates a unique key (pod + normalized log) and uses a Set to filter out any identical alerts found within the current 5-minute batch, ensuring that this n8n automation only passes truly unique events.

  5. Slack Notification: The final HTTP Request n8n node uses the Slack API's chat.postMessage method to deliver the remaining deduplicated alerts to the specified #k8s-alerts channel. The message is richly formatted, including critical metadata (Pod, Namespace, Timestamp) and the full error log.

Installation Guide

To deploy this powerful n8n workflow, follow these steps:


  1. Import the n8n Workflow: Copy the provided JSON and import it into your n8n instance via the 'Workflows' menu, selecting 'New' and then 'Import from JSON'.

  2. Configure Loki Connection:

Open the 📥 Query Loki for Error Logs n8n node.
Update the URL parameter to point to your accessible Grafana Loki API endpoint if it differs from the internal cluster address provided.
Customize the query parameter if you need to target different namespaces or specific error patterns.

  1. Setup Slack Credentials:

The 📤 Send Alerts to Slack n8n node requires 'HTTP Bearer Auth'.
Create a new n8n credential for 'Bearer Auth' and paste your Slack Bot User OAuth Token (starting with xoxb-).
In the n8n node's body parameters, ensure the channel value (#k8s-alerts) matches your target Slack channel.

  1. Activate: Once configured, set the n8n workflow to 'Active' to start the scheduled monitoring.

Node Details

🕒 Every 5 Min Trigger (Schedule Trigger n8n node):
Function: Serves as the primary n8n trigger, initiating the data collection process every 5 minutes.
Key Configuration: Runs on a fixed interval of 5 minutes.
📥 Query Loki for Error Logs (HTTP Request n8n node):
Function: Executes the necessary PromQL query against the Loki API to fetch raw error logs.
Key Configuration: Uses a GET method; dynamically calculates start (10 minutes ago) and end (now) using n8n expressions for effective time-boxing.
🧹 Extract Log Fields (Code n8n node):
Function: Custom JavaScript logic to parse complex nested log data, extract critical fields (log message, pod, namespace, container), and filter out unwanted log levels (debug, info). This is a complex logic n8n node crucial for data preparation.
🧠 Remove Duplicate Alerts (Code n8n node):
Function: Implements the custom deduplication algorithm. It normalizes logs by masking dynamic values (timestamps, IDs) before comparing them. This ensures that the n8n workflow sends only one alert per unique error pattern in the time window.
📤 Send Alerts to Slack (HTTP Request n8n node):
Function: Sends the final, cleaned, and deduplicated alert messages to the configured Slack channel using a Bearer Token credential.
* Key Configuration: Uses a POST method, httpBearerAuth for authentication, and constructs a detailed message payload using dynamic n8n expressions ({{$json["pod"]}}, {{$json["log"]}}).

Related n8n Workflows

Free

Nodes: 4 Nodes
Updated: December 26 2025
View all

Featured*