PurgeKV icon
Schedule icon

Purge KV Store

Automatically purge expired key-value entries from Kestra's internal KV store across namespaces on a daily schedule using a declarative YAML flow.

Categories
CoreInfrastructureSystem
id: kv-store-purge
namespace: system

tasks:
  - id: purge_kv
    type: io.kestra.plugin.core.kv.PurgeKV
    description: Remove key-value (KV) entries from Kestra’s internal storage every
      day at 12AM.
    expiredOnly: true
    namespaces:
      - system
      - company
    includeChildNamespaces: true # Whether to include sub-namespaces of the matched namespace(s).

triggers:
  - id: daily_midnight_schedule
    type: io.kestra.plugin.core.trigger.Schedule
    cron: "0 0 * * *"

Keep Kestra's internal key-value (KV) store clean by automatically removing expired entries across multiple namespaces every day. As flows write KV pairs for caching, state, tokens, and intermediate results, stale and expired keys accumulate and quietly bloat internal storage. This blueprint runs a scheduled cleanup that deletes only the entries you no longer need, so your KV store stays lean and predictable without any manual intervention.

How it works

A io.kestra.plugin.core.trigger.Schedule trigger fires every day at midnight using the cron expression 0 0 * * *. On each run, the purge_kv task of type io.kestra.plugin.core.kv.PurgeKV scans the targeted namespaces and removes matching KV entries. The task is configured with expiredOnly: true, so it deletes only entries whose TTL has lapsed and leaves active keys untouched. It targets the system and company namespaces via the namespaces property, and includeChildNamespaces: true extends the purge to every sub-namespace beneath them.

What you get

  • A hands-off daily cleanup of expired KV entries.
  • Safe deletion scoped to expired keys only, leaving live data intact.
  • Coverage across parent namespaces and all of their child namespaces.
  • Lower internal storage footprint and more predictable KV behavior.

Who it's for

  • Platform and infrastructure engineers maintaining a shared Kestra instance.
  • Teams that lean on the KV store for caching, tokens, or run-to-run state.
  • Admins who want governance and hygiene over internal storage by default.

Why orchestrate this with Kestra

The KV store has no built-in janitor, so without orchestration expired keys linger until someone deletes them by hand. Kestra closes that gap: a declarative YAML Schedule trigger runs the purge on an event-driven cron, retries can be layered on for resilience, and every execution is captured with full logs and lineage for audit. You define the cleanup policy once in version-controlled YAML instead of wiring up external cron jobs or scripts.

Prerequisites

  • A running Kestra instance with KV entries written under the targeted namespaces.
  • Permission to purge the system and company namespaces and their children.

Secrets

This blueprint references no secrets. It operates entirely against Kestra's internal KV store.

Quick start

  1. Add this flow to your Kestra instance.
  2. Adjust the namespaces list to match the namespaces you want to clean.
  3. Confirm expiredOnly: true matches your intent, then save.
  4. Wait for the midnight Schedule trigger, or run the flow manually to verify.

How to extend

  • Change the cron in the Schedule trigger to run hourly, weekly, or off-peak.
  • Set expiredOnly: false to purge all keys, or add a key filter for surgical cleanup.
  • Narrow or broaden the namespaces list, or toggle includeChildNamespaces.
  • Add a notification task to report how many entries were purged each run.

Links

Share this Blueprint
See How

New to Kestra?

Use blueprints to kickstart your first workflows.