Script icon
Process icon
If icon
SlackIncomingWebhook icon
Log icon
Return icon
Schedule icon

Knative Service Revision Failure and Scale Sentinel

Audits Knative Serving custom resources to detect failed revisions, degraded conditions, and scaling bottlenecks in Kubernetes clusters.

Categories
CloudInfrastructure

Enterprise Knative Serving deployments automatically create immutable revisions for every application configuration change. In fast-paced microservice environments, broken deployments, bad environment variables, missing secrets, and container pull failures can leave broken revisions in degraded states, silently breaking traffic splitting and serverless scaling. This sentinel continuously inspects Knative Serving revisions across target Kubernetes namespaces, flags unready conditions and failure reasons, and alerts platform engineering teams before customer-facing serverless routes fail.

How it works

  1. Scheduled triggering: Automatically initiates every hour using a cron trigger (0 * * * *) or runs on-demand via manual execution or API webhooks.
  2. API inspection: Queries the Kubernetes API server for revisions.serving.knative.dev resources in the specified namespace.
  3. Status evaluation: Parses .status.conditions on each revision, checking Ready, ConfigurationsReady, and RoutesReady states.
  4. Failure analysis: Identifies degraded reasons such as ContainerMissing, ImagePullBackOff, ExitCode1, or configuration deadlocks, and extracts exact remediation commands.
  5. Conditional alerting: An io.kestra.plugin.core.flow.If condition checks if unready revisions exceed max_unready_revisions.
  6. Slack notification: Sends a detailed incident payload via SlackIncomingWebhook with revision names, parent services, and debugging commands.
  7. Audit logging and metrics return: Emits summary logs and returns a structured health report containing full diagnostic metadata.

Architecture diagram

flowchart TD
  A[hourly_knative_audit Schedule Trigger] --> B[scan_knative_revisions Python Script]
  B --> C[check_unready_revisions Flowable If]
  C -- Unready > Threshold --> D[notify_slack_knative_alerts Webhook]
  C -- Healthy --> E[log_knative_health_status Log]
  D --> E
  E --> F[export_knative_manifest Return]

Use cases

  • Serverless platform reliability: Detect broken container images or configuration drifts that prevent Knative services from scaling up from zero.
  • Automated canary guardrails: Validate that new revisions successfully reach Ready status during progressive rollouts before routing production traffic.
  • Multi-tenant namespace governance: Audit developer namespaces across shared Kubernetes clusters to ensure obsolete or broken revisions are safely pruned.

Inputs

Name Type Default Description
kubernetes_api_server STRING https://kubernetes.default.svc Base URL for the target Kubernetes cluster API server.
namespace_filter STRING default Kubernetes namespace containing Knative Serving services to audit.
alert_on_revision_unhealthy BOOL true Whether to dispatch alerts when unhealthy revisions or failed deployments are detected.
max_unready_revisions INT 1 Maximum count of degraded or unready revisions allowed before triggering critical alerts.

Expected outputs

  • {{ outputs.scan_knative_revisions.vars.total_revisions_scanned }}: Total count of evaluated Knative revisions in the namespace.
  • {{ outputs.scan_knative_revisions.vars.unhealthy_revisions_count }}: Number of revisions found in non-Ready states.
  • {{ outputs.scan_knative_revisions.vars.health_ratio_percentage }}: Percentage of operational revisions in the namespace.
  • {{ outputs.scan_knative_revisions.vars.unhealthy_revisions_details }}: Serialized JSON array containing failure reasons and kubectl remediation commands.
  • {{ outputs.export_knative_manifest.value }}: Structured dictionary containing the consolidated cluster health summary.

Prerequisites

  • Network access from Kestra execution workers to the Kubernetes API server.
  • A Kubernetes ServiceAccount with RBAC permissions to get and list resources under the serving.knative.dev API group.
  • Incoming Slack Webhook configured for incident dispatch.

Secrets

  • KUBERNETES_SERVICE_ACCOUNT_TOKEN: Bearer token for authenticating to the Kubernetes API server.
  • SLACK_WEBHOOK_URL: Slack Incoming Webhook endpoint URL for alerting.

Quick start

  1. Store your Kubernetes ServiceAccount bearer token in Kestra Secrets as KUBERNETES_SERVICE_ACCOUNT_TOKEN.
  2. Add your Slack Incoming Webhook URL in Kestra Secrets as SLACK_WEBHOOK_URL.
  3. Import this workflow into your Kestra instance under the company.devops namespace.
  4. Run a manual execution with your target Kubernetes namespace to verify revision discovery and alert routing.

Common pitfalls and troubleshooting

  • RBAC ClusterRole permissions: Ensure the ServiceAccount has list and get access on revisions in the serving.knative.dev API group, otherwise the script receives HTTP 403 Forbidden.
  • TLS certificate verification: In self-hosted or internal Kubernetes clusters using private Certificate Authorities, ensure proper CA certificates are mounted or handle SSL verification settings according to corporate security policy.
  • Zero-scale vs failed revisions: Knative revisions normally scale down to 0 pods when idle while maintaining a Ready: True condition. Do not confuse 0 active pods with an unhealthy revision state; this flow inspects condition status, not current pod count.

How to extend

  • Automated rollback trigger: Add a Kestra task that automatically updates traffic distribution on the parent Knative Service to 100% route back to the last known good revision.
  • PagerDuty escalation: Chain an additional webhook or integration task to trigger on-call escalations when mission-critical production services fail.
  • Multi-namespace cluster scanning: Wrap the scan task inside an io.kestra.plugin.core.flow.ForEach loop to audit all namespaces across an entire Kubernetes cluster.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.