Review the StatefulSet PodDisruptionBudget

Define how many voluntary disruptions the stateful application can tolerate.

Description

A StatefulSet’s PodDisruptionBudget (PDB) restricts evictions through the Eviction API, including during node drains. Manage node failures, direct Pod deletion and StatefulSet rolling updates separately.

Potential impact

Maintenance can leave too few available replicas to serve requests or retain quorum. An overly strict budget can block the drain.

Remediation

Select the Pod labels in the same namespace. Set either max_unavailable or min_available to preserve quorum. Check ready replicas and replacement capacity, then test a drain. Also review placement across failure domains and the update strategy.

Examples

Supply the omitted Pod template and prometheus headless Service. Use kubernetes_pod_disruption_budget_v1 for the current policy/v1 API.

Before

hcl
resource "kubernetes_stateful_set" "example" {
  metadata {
    name = "prometheus"
  }

  spec {
    replicas = 2

    selector {
      match_labels = {
        app = "prometheus"
      }
    }

    service_name = "prometheus"
  }
}

After

hcl
resource "kubernetes_stateful_set" "example" {
  metadata {
    name = "prometheus"
  }

  spec {
    replicas = 2

    selector {
      match_labels = {
        app = "prometheus"
      }
    }

    service_name = "prometheus"
  }
}

resource "kubernetes_pod_disruption_budget" "example" {
  metadata {
    name = "prometheus-pdb"
  }

  spec {
    max_unavailable = "20%"

    selector {
      match_labels = {
        app = "prometheus"
      }
    }
  }
}

Both configurations request two replicas. The new PDB selects app=prometheus. With both Pods ready, 20% rounds up to one, so one healthy Pod can be evicted. Check that the remaining replica can maintain quorum.

References