Schedule icon
Get icon
Script icon
OutputValues icon
If icon
SlackIncomingWebhook icon
Fail icon
Log icon

Gate Kubernetes Maintenance on PodDisruptionBudget Readiness

Safely precheck Kubernetes Deployment health and PodDisruptionBudget capacity before planned pod evictions.

Categories
CloudInfrastructure

Check a named Deployment and PodDisruptionBudget before voluntary pod disruption. This is a point-in-time preflight. Kubernetes eviction admission remains the authority during actual drains: a green result is not a reservation.

How it works

  1. get_deployments and get_pdbs fetch full Kubernetes JSON lists using the certified Kubernetes Get plugin in STORE mode.
  2. evaluate_readiness checks both named resources exist exactly once, generation freshness, desired/ready/updated/available Deployment replicas, the PDB selector against pod-template labels, expectedPods, and PDB disruption capacity.
  3. report_location publishes the JSON evidence URI and result.
  4. readiness_gate alerts Slack and fails the execution if any check blocks. Kubernetes API failures, missing fields, and malformed data cannot PASS.

What you get

  • A PASS/BLOCK verdict with exact reasons and replica/budget numbers.
  • Detection of a stale PDB status, a Deployment still rolling out, mismatched selectors, or too few disruptions allowed.
  • JSON evidence and Slack alerts on blocked maintenance.

Who it's for

  • SREs about to drain a node or schedule cluster maintenance.
  • Platform teams building automated operations with safety gates.

Why orchestrate this with Kestra

Make the preflight a repeatable dependency of your runbook, with readable evidence, explicit failure semantics, and a schedule or manual trigger.

Prerequisites

  • Kubernetes API access and read permissions for Deployments and PDBs.
  • Kestra Node Script runner with the node:22-alpine image available.
  • A Slack incoming webhook for a BLOCK alert.
  • Both resources must exist in the selected namespace. Explicitly select the PDB that covers the workload; overlapping PDBs need manual review.

Secrets

  • K8S_MASTER_URL: Kubernetes API server URL.
  • K8S_TOKEN: read-only Kubernetes service account token.
  • SLACK_WEBHOOK_URL: incoming webhook for blocked preflights.

Quick start

  1. Configure secrets and set namespace, deployment_name, and pdb_name.
  2. Run manually with a healthy Deployment and at least one allowed disruption. Review outputs.report_location.values.report_uri.
  3. Test BLOCK with a PDB reporting zero disruptionsAllowed, and with a Deployment rollout in progress.
  4. Enable the schedule only after setting real input defaults and verifying both paths. Re-run the preflight immediately before drains.

How to extend

  • Add an approval step after PASS and a kubectl eviction stage that honors Kubernetes' live Eviction API and returns on budget rejection.
  • Add cross-workload PDB selection checks for shared selectors.
  • Persist reports to object storage for maintenance audit history.

Limits

  • This checks one explicitly named Deployment and one PDB.
  • It does not evict pods or modify the cluster.
  • PASS is not a guarantee: capacity can change after the query. Always use Kubernetes Eviction API for the actual disruption.
  • Policies with unsupported selectors are blocked, not assumed safe.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.