Schedule icon
Commands icon
Docker icon
Script icon
If icon
SlackIncomingWebhook icon
Set icon

EventWatch - Kubernetes warning event spike watcher

A Kestra blueprint that aggregates Kubernetes Warning events per object and alerts on Slack when one spikes, without spamming.

Categories
Infrastructure

How it works

  1. list_events (io.kestra.plugin.scripts.shell.Commands) dumps the namespace's events as JSON with kubectl.
  2. find_spikes (io.kestra.plugin.scripts.python.Script) keeps only Warning events, groups them by involved object, and sums the per-event counts. Any object at or above spike_threshold is spiking. It compares against the KV state so only new spikes alert, and quotes the top reasons plus one sample message per object.
  3. maybe_alert (io.kestra.plugin.core.flow.If) posts the Slack alert only when there is a new spike.
  4. save_state (io.kestra.plugin.core.kv.Set) writes back the currently spiking objects. Events expire on their own in Kubernetes, so a fixed issue fades from the list and a fresh spike alerts again.

What you get

  • A five-minute check on the most underused diagnostic stream in Kubernetes, no agent to install.
  • Slack alerts that catch trouble early: which object is spiking, how many warnings, the top reasons, and a sample message.
  • No alert spam: the KV-backed memory remembers what already spiked, and faded spikes drop out on their own.
  • Quiet runs when warnings stay flat.

Who it's for

Anyone running Kubernetes who only looks at events after something already broke. This watches them continuously and tells you when the noise becomes a signal.

Why orchestrate this with Kestra

Events are ephemeral and easy to miss; a scheduled flow turns them into a reliable signal. Kestra holds the cluster credentials as secrets, keeps every run's findings where you can audit them, and the KV state means the second run does not re-alert the same spike.

Prerequisites

  • A Kubernetes cluster with events you can list.
  • A kubeconfig client certificate and key with permission to list events in the target namespace.
  • Kestra with the Docker task runner available (used for the kubectl and Python steps).
  • A Slack Incoming Webhook URL.

Secrets

Secret What it is
CLIENT_CRT base64-encoded client certificate from your kubeconfig
CLIENT_KEY base64-encoded client key from your kubeconfig
MASTERURL base64-encoded Kubernetes API server URL, reachable from inside the Kestra container
SLACK_WEBHOOK base64-encoded Slack Incoming Webhook URL

In Kestra OSS, secrets come from environment variables prefixed with SECRET_ and must be base64-encoded. If the API URL uses 127.0.0.1 or localhost, replace it with host.docker.internal so the Kestra container can reach it.

Quick start

  1. Start Kestra with the four secrets above as SECRET_ environment variables.
  2. Import this flow and run it with your namespace: quiet if warnings are flat.
  3. Break something noisy (like a CrashLooping pod) and run again: the Slack alert names the object, the warning count, and the top reasons.
  4. Fix it, wait for events to expire, run again: quiet.

How to extend

  • Watch Normal events too, for audit-style change tracking.
  • Split thresholds per reason (BackOff vs FailedMount) with a mapping input.
  • Run across all namespaces by looping the namespace input with a Loop task.
  • Route alerts to PagerDuty or Opsgenie by swapping the Slack task for another notification task.

Inputs

Input Type Default What it does
namespace STRING default the namespace whose events to watch
spike_threshold INT 10 alert when an object's warning count reaches this
slack_webhook STRING (required) Incoming webhook URL of the Slack channel for alerts

Links

Pitfalls

  • Events expire (default one hour), so a spike can fade before you investigate. The alert quotes the top reasons and a sample message so you have something to go on.
  • The count is summed across event objects, and Kubernetes aggregates repeated events into one object with a count. Bursty but distinct failures on the same object add up together.
  • One threshold for every reason: a chatty but harmless warning can trip it. Tune spike_threshold per namespace after the first week.
  • The flow is strictly read-only. It never touches workloads or deletes events.
See How

New to Kestra?

Use blueprints to kickstart your first workflows.