Webhook icon
SetVariables icon
Log icon
If icon
Fail icon
Pause icon
Restart icon
Get icon
SlackIncomingWebhook icon

Kubernetes Deployment Restart Remediation with Protected Namespace Approval

Restart Kubernetes Deployments from alerts, auto-healing staging and requiring human approval for protected production namespaces.

Categories
Infrastructure

Turn incident response into a governed workflow. A monitoring alert supplies a target namespace and Deployment through a secured webhook. The flow validates the namespace against an allowlist. Allowed non-production namespaces proceed automatically, while protected production namespaces require explicit human approval for up to one hour. Approval timeout fails closed. Kestra then performs a real rolling restart and retries deployment-status checks. Slack receives success or failure notifications.

How it works

  1. The alert_webhook trigger accepts POST requests secured by K8S_REMEDIATION_WEBHOOK_KEY, with namespace and deployment_name parameters.
  2. parse_webhook_payload resolves the requested target. validate_namespace rejects missing deployment names and namespaces outside the configured allowlist.
  3. production_approval_gate checks whether the namespace is in protected_namespaces. Staging and other unprotected allowed namespaces skip approval and continue automatically.
  4. For protected production namespaces, human_approval pauses execution for up to one hour. An explicit resume is required; behavior: FAIL ensures timeout cannot reach the restart.
  5. restart_service performs a real rolling restart of the named Kubernetes Deployment using secret-backed cluster credentials.
  6. get_deployment_status fetches the target Deployment and retries with exponential backoff. Slack receives the success result, while the flow-level error handler reports failures.

What you get

  • Automatic remediation for allowed non-production namespaces such as staging.
  • Human approval for protected production namespaces before any restart.
  • A one-hour approval timeout that fails closed.
  • Namespace allowlist guardrails and secret-backed Kubernetes authentication.
  • Deployment status verification with retries and Slack success/failure notifications.

Who it's for

  • SRE teams automating runbook step one for crashlooping or degraded deployments.
  • Platform teams offering guarded self-service restarts to application teams.
  • On-call engineers who want alerts to arrive already remediated.

Why orchestrate this with Kestra

A webhook receiver script with kubectl access is a security incident waiting to happen. Kestra adds the guardrails: a keyed webhook, explicit allowlist validation before any cluster call, secrets management for the cluster token, exponential-backoff verification as a declarative retry policy rather than a sleep loop, and an execution log that shows exactly which alert restarted what and whether it recovered.

Prerequisites

  • A Kubernetes cluster reachable from the Kestra worker.
  • A service account token with permission to restart and get deployments in the allowed namespaces.
  • A monitoring system able to POST to the webhook with the target parameters.

Secrets

  • K8S_REMEDIATION_WEBHOOK_KEY: shared key guarding the webhook trigger.
  • K8S_MASTER_URL, K8S_CA_CERT_DATA, K8S_OAUTH_TOKEN: cluster connection settings used by all Kubernetes tasks.
  • SLACK_WEBHOOK_URL: Slack incoming webhook for remediation reports.

Quick start

  1. Add the secrets above to your Kestra namespace.
  2. Adjust allowed_namespaces to the namespaces you are willing to auto-remediate.
  3. Test with a manual POST to the webhook: ?namespace=staging&deployment_name=my-app.
  4. Point your alerting rule at the webhook URL.

How to extend

  • Add namespaces to protected_namespaces when they require human approval before remediation.
  • Add approved non-production namespaces to allowed_namespaces when automatic remediation is appropriate.
  • Adjust pauseDuration to match your production incident-response policy.
  • Capture pod logs before restarting for post-incident analysis.
  • Track remediation counts per deployment and introduce rate limits to prevent repeated restarts.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.