Description
A PodDisruptionBudget (PDB) limits unavailability during operations that use the Eviction API, such as node drains. Plan separately for node failure, direct Pod deletion and Deployment rolling updates.
Potential impact
Too few remaining Pods can interrupt service during maintenance. A budget that is too strict can block a drain.
Remediation
Select the actual Pod labels in the same namespace. Set either max_unavailable or min_available, check readiness and replacement capacity, and test a drain. Review rollout strategy and placement across failure domains separately.
Examples
Add the missing Deployment selector to the first configuration. Both configurations need a Pod template with labels matching that selector. Use kubernetes_pod_disruption_budget_v1 for the current policy/v1 API.
Before
resource "kubernetes_deployment" "example" {
metadata {
name = "terraform-example"
labels = {
k8s-app = "prometheus"
}
}
spec {
replicas = 3
}
}
After
resource "kubernetes_deployment" "example" {
metadata {
name = "terraform-example"
labels = {
k8s-app = "prometheus"
}
}
spec {
replicas = 3
selector {
match_labels = {
k8s-app = "prometheus"
}
}
}
}
resource "kubernetes_pod_disruption_budget" "example" {
metadata {
name = "demo"
}
spec {
max_unavailable = "20%"
selector {
match_labels = {
k8s-app = "prometheus"
}
}
}
}
The first Deployment specifies three replicas. The added PDB selects k8s-app=prometheus. If all three are ready, 20% rounds up to one, allowing one healthy Pod to be evicted.