Kubernetes: What's a PodDisruptionBudget?

2 min read | by Jordi Prats

In Kubernetes we can configure a PodDisruptionBudgets (PDB) to tell the cluster for a given set of Pods how they can tolerate interruptions (such as application upgrades) maintaining it's general availability.

This Kubernetes object has graduated to GA in Kubernetes v1.21

A PodDisruptionBudget has three fields:

  • .spec.selector: Selects the set of pods to which it applies. If the set of Pods is controlled by a deploymnet we can use the same selector we are using for the deployment
  • .spec.minAvailable: Sets the number of pods that that must still be available after the eviction
  • .spec.maxUnavailable: Sets the number of pods from that set that can be unavailable after the eviction

For both minAvailable and maxUnavailable we can set it as an absolute number or a percentage

For example, to tell the cluster that we want at least 3 replicas for the Pods that have the label "ampa=web" we would create the following PDB:

apiVersion: policy/v1beta1
kind: PodDisruptionBudget
metadata:
  name: ampa-web
spec:
  selector:
    matchLabels:
      ampa: web
  minAvailable: 3

We can tell it that we don't want any interruptions at all setting maxUnavailable to zero:

apiVersion: policy/v1beta1
kind: PodDisruptionBudget
metadata:
  name: ampa-web
spec:
  selector:
    matchLabels:
      ampa: web
  maxUnavailable: 0

By using this PDB we won't be tolerating any evictions so we will have to either delete the PDB if we want to allow some interruption or manually delete the Pod

Although this object is intented to be applied to a set of pods, we can use it on bare pods with the following restrictions:

  • Only minAvailable can be used
  • Since there is no actual group, only an integer value can be used for minAvailable, percentages are not allowed

Posted on 03/08/2021

Categories