Alerting
An alert puts a threshold on one signal; the api-server evaluates it on a schedule and fires a webhook or email when it breaches for a sustained window, and again when it recovers. Notification config never enters your cluster. A rule’s source decides where the sample comes from.
# Golden-signal alert: 5xx rate above 5% for 5 minutes.
kubrain deploy alert set myapp \
--signal error_rate --op '>' --threshold 0.05 --for 5m \
--notify https://hooks.slack.com/services/XXX
kubrain deploy alert list myapp # each rule's live state + last value
kubrain deploy alert delete myapp error_rateThree sources
metric (default) — golden signals
Thresholds a signal from get_metrics: error_rate (fraction),
p95_ms, or req_rate. --op is > (default) or <.
kubrain deploy alert set myapp --component api \
--signal p95_ms --op '>' --threshold 500 --notify oncall@example.compod — pod health
Watches the deployment’s pods with a live cluster check (no metrics backend
needed). Fires when pods are failed, not ready (CrashLoopBackOff,
ImagePullBackOff, …), or stuck pending past a 5-minute grace. The single signal
pods_unhealthy defaults to > 0, so only --notify is required:
kubrain deploy alert set myapp --source pod --for 5m \
--notify https://hooks.slack.com/services/XXXThe firing notification names the offending pods and why.
probe — uptime & TLS
A black-box HTTP(S) check the api-server makes from outside the cluster to one of your app’s public ingress hosts — the true end-to-end “is my site up.” Two signals:
http_up(default) —GET https://<host>/; fires when it stops answering 2xx/3xx.cert_days— days until the host’s TLS certificate expires;cert_days < 14by default warns two weeks ahead.
kubrain deploy alert set myapp --source probe --host app.example.com --for 2m \
--notify oncall@example.com
kubrain deploy alert set myapp --source probe --host app.example.com \
--signal cert_days --threshold 21 --notify oncall@example.comHow it fires
A debounced state machine: ok → pending → firing, where --for is how long a
breach must persist before firing (omit to fire on the first breaching sample). A
recovery moves it back to ok. Steady-state firing notifies once (on start)
and once on resolve — not every tick.
Rules are idempotent per (component, signal) — setting the same signal again
replaces the rule and resets its state. list_alerts shows each rule’s state
(ok/pending/firing) and last sampled value.
Notifications
--notify takes a webhook URL (Slack, Discord, PagerDuty, any incoming
webhook) or an email address — the channel is inferred from the shape. Webhooks
POST a stable JSON payload; email needs the platform SMTP relay configured.
Gotchas
req_rate < Nwon’t fire on total silence — a no-traffic window reads as no-data, treated as “not breaching.” Fine forerror_rate,p95_ms, andreq_rate >.source=log(log-keyword alerts) is accepted but not wired yet.
Playbook
kubrain deploy metrics myapp→ confirm it’s serving; note the baseline.kubrain deploy alert set myapp --signal error_rate --op '>' --threshold 0.05 --for 5m --notify …kubrain deploy alert list myapp→ verify it’s stored in stateok.
See also
- Metrics — read the numbers you’re thresholding.