Script icon
Docker icon
If icon
SlackIncomingWebhook icon
Log icon
Return icon
Schedule icon

Kubernetes PersistentVolumeClaim (PVC) Storage Exhaustion Sentinel

Audits Kubernetes PersistentVolumeClaim disk usage via Prometheus, identifies impending volume exhaustion, and alerts SREs on Slack with remediation commands.

Categories
CloudInfrastructure

Audits Kubernetes PersistentVolumeClaim (PVC) storage utilization telemetry via Prometheus metrics, detecting volumes rapidly approaching disk capacity limits and alerting SRE teams on Slack with instant kubectl volume expansion commands before pod evictions occur.

How it works

  1. Prometheus Storage Metric Polling: Queries kubelet volume statistics (kubelet_volume_stats_used_bytes and kubelet_volume_stats_capacity_bytes) across the target Kubernetes namespace.
  2. Capacity Utilization Computation: Calculates percentage used and absolute remaining gigabytes for each persistent volume claim bound to stateful pods (e.g. PostgreSQL, Kafka, Elasticsearch, Prometheus).
  3. Threshold & Burn Rate Classification: Categorizes volumes into nominal, warning (>=80%), and critical (>=90%) severity tiers.
  4. Remediation Synthesis & Alerting: Generates actionable kubectl patch pvc expansion snippets and dispatches structured alerts directly to designated Slack channels.

Architecture diagram

flowchart TD
    A[periodic_pvc_storage_audit Schedule Trigger] --> B[scan_pvc_storage_metrics Python Script]
    B --> C[check_pvc_exhaustion_threshold Flowable If]
    C -- Capacity Breached --> D[notify_slack_storage_sre Webhook]
    C -- Storage Nominal --> E[log_nominal_storage_state Log]
    D --> E
    E --> F[export_storage_manifest Return]

Architecture components

  • Trigger (periodic_pvc_storage_audit): Drives scheduled recurring surveillance cycles every 15 minutes without human intervention.
  • Inspection Task (scan_pvc_storage_metrics): Queries Prometheus APIs, computes volume utilization ratios, and structures diagnostic indicators via Kestra outputs.
  • Evaluation Gate (check_pvc_exhaustion_threshold): Evaluates operational safety boundaries using deterministic boolean branching.
  • Notification Action (notify_slack_storage_sre): Dispatches rich, actionable incident messages with pre-computed kubectl patch commands directly to team channels.
  • Manifest Return (export_storage_manifest): Emits structured capacity payloads for SRE dashboards or long-term capacity planning.

Key capabilities

  • Proactive Disk Surveillance: Continuous scheduled auditing of all stateful volumes without installing custom in-pod sidecars or agents.
  • Instant Remediation Synthesis: Automatically constructs exact kubectl patch pvc commands with calculated 1.5x expansion sizing to accelerate incident resolution.
  • Deterministic Multi-Tier Alerting: Separate warning (80%) and critical (90%) thresholds to differentiate capacity warnings from emergency disk lockouts.
  • Machine-Readable Audit Manifest: Structured capacity telemetry exported for platform capacity planning and compliance reporting.

What you get

  • Real-time visibility into Kubernetes PVC storage headroom across stateful workloads.
  • Protection against sudden disk-full database halts and database index corruption.
  • Actionable copy-paste kubectl patch expansion commands delivered directly to Slack.
  • Fully automated scheduled audit runs requiring zero infrastructure maintenance.

Who it's for

  • Platform Engineers and SREs running stateful databases (PostgreSQL, MySQL, MongoDB, Redis) on Kubernetes.
  • DevOps Teams operating data-intensive workloads (Kafka brokers, Elasticsearch nodes, Vector databases) with high disk ingestion rates.
  • Cloud Infrastructure Leads enforcing proactive storage governance and preventing service-level outages.

Why orchestrate this with Kestra

  • Serverless Observability: Queries cluster Prometheus endpoints directly from lightweight containerized tasks without running standing agent pods.
  • Declarative Governance: Code-based workflow configuration stored in Git with native versioning, diffing, and audit logging.
  • Extensible Remediation: Easily add automated kubectl patch execution steps or Jira ticket creation within the same declarative YAML flow.
  • Secure Credential Isolation: Securely accesses Prometheus APIs and Slack webhooks through encrypted Kestra namespace secrets.

Use cases

  • Kafka Log Dir Exhaustion Sentinel: Detect Kafka broker PVCs filling up due to unconsumed partitions before broker pods are evicted.
  • Database WAL & Tablespace Guard: Catch PostgreSQL write-ahead log (WAL) and tablespace volume saturation during massive batch inserts.
  • Prometheus TSDB Retention Overflow: Prevent monitoring outages caused by Prometheus itself running out of TSDB disk storage.

Inputs

Name Type Default Description
prometheus_endpoint STRING http://prometheus-k8s.monitoring:9090 Base HTTP URL of the Prometheus server scraping kubelet volume statistics.
cluster_identifier STRING k8s-production-us-east-1 Cluster identifier label utilized within Prometheus metrics queries.
target_namespace STRING production Target Kubernetes namespace under audit, or 'all' to inspect all persistent volumes.
warning_threshold_pct FLOAT 80.0 Disk usage percentage threshold triggering a warning notification.
critical_threshold_pct FLOAT 90.0 Disk usage percentage threshold triggering an emergency priority incident.
lookback_burn_hours INT 6 Hours of historical disk consumption used to calculate burn rates.
alert_on_exhaustion BOOL True Toggle whether Slack webhook alerts are dispatched upon detecting elevated capacity usage.

Expected outputs

  • {{ outputs.scan_pvc_storage_metrics.vars.total_pvcs_scanned }}: Number of persistent volume claims scanned during the audit run.
  • {{ outputs.scan_pvc_storage_metrics.vars.warning_pvc_count }}: Number of PVCs currently between warning and critical capacity limits.
  • {{ outputs.scan_pvc_storage_metrics.vars.critical_pvc_count }}: Number of PVCs currently exceeding the critical capacity ceiling.
  • {{ outputs.scan_pvc_storage_metrics.vars.max_utilization_pct }}: Peak utilization percentage recorded across all inspected volumes.
  • {{ outputs.scan_pvc_storage_metrics.vars.top_exhaustion_pvc }}: Identifier (namespace/pvc) of the highest-utilization volume.
  • {{ outputs.scan_pvc_storage_metrics.vars.remediation_command }}: Copy-pasteable kubectl patch command to immediately expand the storage size.
  • {{ outputs.scan_pvc_storage_metrics.vars.is_alerting }}: Boolean flag indicating whether any volume exceeded configured safety thresholds.

Prerequisites

  • Kubernetes cluster with CSI storage drivers supporting volume expansion (allowVolumeExpansion: true).
  • Prometheus server scraping kubelet_volume_stats_* metrics endpoints.
  • Slack Incoming Webhook URL configured in Kestra secrets for operational alerts.

Secrets

  • SLACK_WEBHOOK_URL: Webhook URL for posting storage incident alerts into Slack.

Quick start

  1. Store your Slack webhook URL in Kestra secrets under SLACK_WEBHOOK_URL.
  2. Import this blueprint into your Kestra instance in the company.platform namespace.
  3. Update prometheus_endpoint to match your cluster's Prometheus internal DNS address.
  4. Run an initial manual execution to audit current PVC capacity across your namespaces.
  5. Keep the automated 15-minute schedule enabled for continuous background protection.

Common pitfalls and troubleshooting

  • CSI StorageClass Volume Expansion: Ensure the underlying StorageClass has allowVolumeExpansion: true, otherwise kubectl patch will fail to resize the volume.
  • Filesystem Resize Latency: Some cloud block storage volumes require pod restarts or filesystem resize daemons to reflect expanded capacity.
  • Ephemeral Storage vs PVCs: This blueprint inspects PersistentVolumeClaims; for container ephemeral writable layers, monitor container_fs_usage_bytes.

How to extend

  • Automated Self-Healing Expansion: Add an automated kubectl apply task via io.kestra.plugin.kubernetes.cli.Kubectl to expand storage automatically when critical.
  • PagerDuty Integration: Add an io.kestra.plugin.pagerduty.Incident step to wake on-call engineers when PVC utilization exceeds 95%.
  • Datadog / Grafana Annotation: Add an annotation step when volume expansion is triggered to mark the event on dashboard graphs.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.