New to Kestra?
Use blueprints to kickstart your first workflows.
Auto-remediate unhealthy Kubernetes deployments with Kestra. A webhook alert triggers a guarded kubectl restart, verified with retries and Slack alerts.
Turn "have you tried restarting it" into a governed automation. When a monitoring alert fires, it posts the namespace and deployment name to a secured webhook; the flow validates both against an allowlist, performs a rolling restart with kubectl, then polls the deployment status with exponential backoff until the rollout is healthy. Success and failure both land in Slack, so on-call engineers see remediation happen without touching a terminal.
alert_webhook trigger (io.kestra.plugin.core.trigger.Webhook) accepts POSTs secured by K8S_REMEDIATION_WEBHOOK_KEY; Alertmanager, Datadog, or any monitor can call it with namespace and deployment_name query parameters.parse_webhook_payload task (io.kestra.plugin.core.execution.SetVariables) resolves the target from trigger.parameters with ?? fallbacks to flow variables.validate_namespace task (io.kestra.plugin.core.flow.If) fails fast when the deployment name is missing or the namespace is not in allowed_namespaces, preventing alerts from restarting arbitrary workloads.restart_service task (io.kestra.plugin.kubernetes.kubectl.Restart) performs the rolling restart of the Deployment.get_deployment_status task (io.kestra.plugin.kubernetes.kubectl.Get with fetchType: FETCH_ONE) fetches the deployment and retries with an exponential policy (5 attempts, PT15S initial interval, PT5M cap) until the status reflects a healthy rollout.notify_slack_success posts the verified status; a flow-level errors handler posts a failure message if validation, restart, or verification fail. Cluster credentials are injected once via pluginDefaults for all io.kestra.plugin.kubernetes tasks.pluginDefaults block.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.
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.allowed_namespaces to the namespaces you are willing to auto-remediate.?namespace=staging&deployment_name=my-app.io.kestra.plugin.core.flow.Pause approval for production namespaces while auto-remediating staging.io.kestra.plugin.kubernetes.kubectl.Get on pods for post-incident analysis.