feat: add unified status socket for health monitoring #2682
+1,064
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
Modern container orchestration platforms like Kubernetes require reliable health probes to manage application lifecycle. Currently, keepalived lacks a lightweight mechanism for external health checks that works across all its operational modes.
The Problem
Container environments need health endpoints. When running keepalived in Kubernetes:
livenessProbeneeds to verify keepalived is functioning correctlyreadinessProbeneeds to know if this instance should receive traffic (MASTER vs BACKUP)Existing options are insufficient:
Need for unified status. Keepalived runs multiple child daemons:
A health check endpoint should report aggregated state from ALL active daemons, not just one.
The Solution
This PR adds an optional Unix domain socket that provides:
socat,nc, or any socket clientHEALTH- single-word response for probe scripts:MASTER,BACKUP, orFAULTSTATUS- JSON response with detailed per-daemon informationArchitecture
The status socket runs in the parent (watchdog) process, not in child daemons. This follows keepalived's existing patterns (like BFD event pipes) and provides true unified health:
Children send
status_event_tstructs via pipes on state changes. Parent maintains aggregated state and responds to socket queries.Usage
Configuration
Build
Querying
Kubernetes Integration
Implementation Details
--enable-status-socket/_WITH_STATUS_SOCKET_Files Changed
configure.ac--enable-status-socketoptionkeepalived/include/status_event.hkeepalived/core/status_socket.ckeepalived/core/main.ckeepalived/vrrp/vrrp_daemon.ckeepalived/vrrp/vrrp_notify.ckeepalived/check/check_daemon.ckeepalived/check/ipwrapper.ckeepalived/bfd/bfd_daemon.ckeepalived/bfd/bfd_event.cdoc/man/man5/keepalived.conf.5.inTesting
Tested manually with:
Related
This addresses the common request for container-friendly health endpoints, similar to:
/healthendpoint