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

K3s Embedded etcd Peer RTT and Heartbeat Miss Sentinel

Audits K3s embedded etcd metrics to detect peer network RTT spikes, Raft heartbeat failures, and leader election instability.

Categories
CloudInfrastructure

Automates continuous health and consensus stability surveillance for K3s lightweight Kubernetes embedded etcd datastores.

How it works

  1. A schedule trigger executes the K3s embedded etcd health audit workflow every 15 minutes.
  2. The Python task queries the K3s etcd Prometheus metrics endpoint on port 2381.
  3. The script extracts peer round-trip latencies, Raft heartbeat transmission failure counters, and leader change totals.
  4. An evaluation gate determines whether peer latency spikes, heartbeat transmission failures, or leader flapping breach bounds.
  5. When etcd consensus degradation is detected, a high-priority Slack incident alert is dispatched to the Platform team.
  6. When embedded etcd consensus maintains sub-millisecond latencies and stable Raft leadership, nominal telemetry is logged.
  7. A structured JSON audit manifest is emitted for edge control plane governance and distributed consensus records.

Architecture diagram

graph TD
    Trigger[Schedule Trigger: 15m] --> ScanMetrics[Python Script: Scrape K3s etcd Metrics]
    ScanMetrics --> EvalBreach{RTT > 150ms OR Heartbeats > 3 OR Flapping?}
    EvalBreach -- Yes --> SlackAlert[Slack: High-Urgency Edge Alert]
    EvalBreach -- No --> LogNominal[Log: Nominal etcd State]
    SlackAlert --> EmitManifest[Debug Return: etcd Audit Manifest]
    LogNominal --> EmitManifest

Architecture components

  • Trigger: Automated schedule polling at 15-minute recurring intervals.
  • Script Task: Scrapes K3s embedded etcd Prometheus metrics endpoints using Docker container runners.
  • Decision Gate: Evaluates whether peer RTT durations or Raft heartbeat failure totals exceed limits.
  • Notification Task: Dispatches structured Slack alerts with cluster name and peer latency metrics.
  • Audit Manifest: Emits JSON execution payloads containing embedded etcd health and timestamps.

Key capabilities

  • Continuous surveillance of embedded etcd consensus members across K3s multi-master server nodes.
  • Early warning detection for edge WAN jitter that threatens Raft election timeouts and split-brain states.
  • Automated tracking of leader election changes preventing cascading Kubernetes API server unresponsiveness.
  • Zero host dependency execution via isolated containerized Python runners.

What you get

  • Real-time visibility into edge Kubernetes control plane datastore health and consensus peer latency.
  • Proactive alerts preventing cluster quorum loss and unrecoverable etcd database corruption.
  • Standardized audit manifests containing exact RTT measurements, heartbeat failure counts, and timestamps.
  • Zero-overhead deployment compatible with K3s High Availability (HA) embedded etcd architectures.

Who it's for

  • Edge computing engineers deploying lightweight K3s clusters across remote industrial and retail locations.
  • Site Reliability Engineers ensuring control plane stability for edge point-of-sale and IoT gateways.
  • Cloud infrastructure leads managing hybrid edge-to-cloud Kubernetes control planes.
  • DevOps engineers diagnosing API server latency spikes in resource-constrained environments.

Why orchestrate this with Kestra

  • Serverless Docker Isolation: Executes telemetry scraping in ephemeral Docker environments without persistent workers.
  • Centralized Secrets Governance: Protects sensitive Slack webhooks using encrypted namespace secrets.
  • Declarative YAML Workflows: Manages control plane datastore surveillance as versioned code in Git repositories.
  • Comprehensive Audit History: Preserves historical consensus latency metrics in searchable Kestra execution logs.

Use cases

  • Edge WAN Network Jitter Alarm: Detects when intermittent cellular or satellite links degrade Raft peer sync.
  • Disk Fsync Latency Correlation: Pinpoints when slow SD card or eMMC writes cause etcd heartbeat timeouts.
  • Quorum Loss Early Warning: Alerts engineers before member node drops lead to minority partition lockouts.

Inputs

Name Type Default Description
k3s_etcd_metrics_url STRING https://127.0.0.1:2381 Internal HTTP/HTTPS URL exposing Prometheus metrics for K3s etcd.
cluster_name STRING edge-pos-cluster-01 Identifier of the target K3s lightweight Kubernetes cluster.
max_peer_rtt_ms INT 150 Maximum allowable peer network round-trip time in milliseconds.
max_heartbeat_failures_threshold INT 3 Maximum allowable Raft leader heartbeat transmission failures.
alert_on_leader_flapping BOOL true Toggle whether leader election flapping triggers an incident alert.

Expected outputs

  • {{ outputs.scan_k3s_etcd_telemetry.vars.peer_rtt_ms }}: Maximum observed network round-trip time between peers.
  • {{ outputs.scan_k3s_etcd_telemetry.vars.heartbeat_failures_total }}: Total count of Raft leader heartbeat send failures.
  • {{ outputs.scan_k3s_etcd_telemetry.vars.leader_changes_seen }}: Count of leader changes observed within the window.
  • {{ outputs.scan_k3s_etcd_telemetry.vars.is_alerting }}: Boolean flag indicating if etcd health bounds are breached.
  • {{ outputs.scan_k3s_etcd_telemetry.vars.audit_timestamp }}: ISO-8601 UTC timestamp of the K3s etcd audit run.

Prerequisites

  • K3s deployed in High Availability mode with embedded etcd metrics exposed on port 2381.
  • Network connectivity from the Kestra worker to the K3s server nodes metrics endpoint.
  • Configured Slack incoming webhook URL with permissions to post in platform alert channels.

Secrets

  • SLACK_WEBHOOK_URL: Secure webhook URL for routing edge platform alerts to the Platform Slack channel.

Quick start

  1. Verify that K3s server nodes expose etcd Prometheus metrics on port 2381.
  2. Add the SLACK_WEBHOOK_URL secret within your Kestra namespace settings.
  3. Specify your cluster identifier in cluster_name.
  4. Run a manual flow execution via the Kestra UI to validate metric ingestion.
  5. Enable the periodic_k3s_etcd_audit schedule trigger to establish automated monitoring.

Common pitfalls and troubleshooting

  • Port Accessibility: By default K3s binds etcd metrics to localhost; set --etcd-expose-metrics=true on servers.
  • Client Certificate Verification: If etcd TLS authentication is enforced, provide client certs or set verify false.
  • Disk I/O Contention: High disk write latency on the K3s data directory directly inflates peer RTT metrics.
  • Odd Node Count Rule: Always deploy 3 or 5 server nodes; 2-node clusters cannot survive a single member failure.

How to extend

  • Automated Snapshot Trigger: Initiate an automated k3s etcd-snapshot backup if leader changes begin to climb.
  • PagerDuty Escalation: Escalate to on-call edge engineers if heartbeat failures exceed 10 across 2 audit cycles.
  • Multi-Cluster Edge Sweep: Expand script parameters to monitor embedded etcd health across hundreds of retail sites.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.