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

Karpenter Node Consolidation and Interruption Sentinel

Audits AWS Karpenter autoscaler Prometheus metrics to detect failed EC2 node launches, spot interruptions, and consolidation stalls.

Categories
CloudInfrastructure

Automates continuous health and capacity surveillance for AWS Karpenter Kubernetes autoscaling controllers.

How it works

  1. A schedule trigger executes the Karpenter audit workflow every 15 minutes.
  2. The Python task queries the Karpenter controller Prometheus metrics endpoint on port 8000.
  3. The script extracts active NodePool launch requests, failed node creations, spot termination notices, and consolidation actions.
  4. An evaluation gate determines whether launch failures or spot interruptions breach operational tolerance bounds.
  5. When thresholds are breached, a high-priority Slack alert is dispatched to platform engineering and cluster SREs.
  6. When nodes provision cleanly and consolidation proceeds normally, nominal telemetry is logged.
  7. A structured JSON audit manifest is emitted for cloud capacity governance and spot durability SLA archives.

Architecture diagram

graph TD
    Trigger[Schedule Trigger: 15m] --> ScanMetrics[Python Script: Scrape Karpenter Metrics]
    ScanMetrics --> EvalBreach{Failures > Threshold OR Spot Interruptions > 5?}
    EvalBreach -- Yes --> SlackAlert[Slack: High-Urgency Capacity Alert]
    EvalBreach -- No --> LogNominal[Log: Nominal Karpenter State]
    SlackAlert --> EmitManifest[Debug Return: Karpenter Audit Manifest]
    LogNominal --> EmitManifest

Architecture components

  • Trigger: Automated schedule polling at 15-minute intervals.
  • Script Task: Scrapes Karpenter Prometheus telemetry endpoints using Docker container isolation.
  • Decision Gate: Evaluates whether launch errors or spot interruption spikes exceed capacity safety limits.
  • Notification Task: Dispatches structured Slack alerts with cluster identity and failure counts.
  • Audit Manifest: Emits JSON execution payloads containing cluster autoscaling health and timestamps.

Key capabilities

  • Continuous surveillance of Karpenter node launch errors and AWS EC2 API throttling failures.
  • Rapid detection of spot instance interruption spikes across active NodePool configurations.
  • Granular tracking of node consolidation actions and capacity defragmentation cycles.
  • Zero external dependency execution via isolated containerized Python runners.

What you get

  • Preemptive alerting on compute capacity provisioning failures before workload pods enter pending loops.
  • Automated tracking of spot termination notices across AWS availability zones.
  • Real-time audit manifests capturing cluster autoscaler health for SOC 2 cloud compliance.
  • Configurable tolerance thresholds adaptable to critical production and batch compute clusters.

Who it's for

  • Kubernetes Platform Engineers managing large-scale dynamic compute fleets on AWS EKS.
  • Site Reliability Engineers safeguarding critical workload scheduling against spot terminations.
  • Cloud Infrastructure Architects optimizing compute utilization while maintaining node pool SLA.
  • FinOps teams tracking automated cluster defragmentation and node consolidation efficiency.

Why orchestrate this with Kestra

  • Deterministic Scheduling: Guarantees regular autoscaler health audits without fragile local crontab scripts.
  • Containerized Runners: Runs Python tasks inside isolated Docker containers without host library dependencies.
  • Condition Branching: Flowable If tasks route alerts and nominal logging cleanly without spaghetti code.
  • Enterprise Secret Safety: Securely injects Slack webhook credentials without plain-text exposure.

Use cases

  • Spot Interruption Wave Alerting: Rapidly notifies operations when AWS reclaims spot capacity across availability zones.
  • NodePool Misconfiguration Detection: Identifies bad AMI IDs or insufficient subnet IP allocations causing launch loops.
  • Consolidation Stall Auditing: Monitors whether aggressive bin-packing causes pod eviction thrashing and scheduling latency.
  • Continuous Infrastructure Compliance: Feeds daily cluster autoscaling health telemetry into long-term governance archives.

Inputs

Name Type Default Description
karpenter_metrics_url STRING http://karpenter.karpenter.svc.cluster.local:8000 Base HTTP URL exposing Prometheus metrics for Karpenter.
cluster_name STRING production-eks-cluster Target Kubernetes cluster under Karpenter surveillance.
max_failed_launches_threshold INT 2 Max allowable failed node launch attempts before alerting.
max_interrupted_nodes_threshold INT 5 Max spot instance interruptions tolerated in a cycle.
alert_on_any_interruption BOOL false Whether any nonzero spot interruption triggers an immediate alert.

Expected outputs

  • {{ outputs.scan_karpenter_telemetry.vars.node_launches_total }}: Total EC2 node launch requests evaluated.
  • {{ outputs.scan_karpenter_telemetry.vars.launch_failures_total }}: Count of failed node launch requests.
  • {{ outputs.scan_karpenter_telemetry.vars.interrupted_nodes_total }}: Count of spot interruption notices received.
  • {{ outputs.scan_karpenter_telemetry.vars.consolidation_actions_total }}: Count of consolidation actions performed.
  • {{ outputs.scan_karpenter_telemetry.vars.is_alerting }}: Boolean flag indicating threshold violation.
  • {{ outputs.emit_audit_manifest.value }}: Structured JSON audit manifest emitted for compliance archives.

Prerequisites

  • Karpenter controller deployed on AWS EKS with Prometheus metrics enabled on port 8000.
  • Metrics port reachable from the Kestra worker execution environment.
  • Docker daemon running on the Kestra host to execute containerized Python tasks.

Secrets

  • SLACK_WEBHOOK_URL: Incoming webhook URL for the target Platform SRE Slack alerting channel.

Quick start

  1. Ensure Karpenter service exposes port 8000 for Prometheus metrics scraping.
  2. Configure the SLACK_WEBHOOK_URL secret in your Kestra namespace settings.
  3. Specify your cluster identifier in cluster_name.
  4. Execute a manual test run via the Kestra UI to verify metric ingestion.
  5. Enable the periodic_karpenter_audit trigger to establish automated continuous surveillance.

Common pitfalls and troubleshooting

  • Network Policy Isolation: If Kestra cannot reach port 8000, verify Kubernetes NetworkPolicies allow ingress from Kestra pods.
  • Metric Name Evolution: Karpenter v0.32+ renamed several metrics; verify the endpoint exposes standard Prometheus gauges.
  • Spot Interruption Surges: Multiple spot interruptions within minutes may trigger repeated alerts; adjust thresholds accordingly.
  • RBAC Authentication: If metrics endpoint requires bearer token authorization, add an Authorization header to the scraper request.

How to extend

  • Automated Fallback to On-Demand: Chain an AWS CLI task to provision on-demand nodes when spot capacity collapses.
  • Dynamic NodePool Tuning: Adjust NodePool limits and consolidation policies via Kubernetes resource tasks.
  • PagerDuty Escalation: Escalate to on-call cloud platform engineers if launch errors exceed 10 in 15 minutes.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.