Pod Disruption Budget is a resource in Kubernetes that allows us to manage disruption behavior in our cluster when voluntary changes are made by cluster Administrator or Human Operators. It provides a way for us to specify the Minimum available pods and as of Kubernetes version 1.7 it now allows us to specify the maximum unavailable pods in our cluster.
PDB uses a label selector to specify the pods it is trying to assign a budget to. It uses the fields
maxUnavailable to specify both the minimum number of pods that should be available and the maximum number of pods that can be unavailable in the cluster. The field values can either be an absolute value or percentage.
We use PDB as a way to provide safety constraints on pods. PDB determines how cluster specific actions such as autoscaling, draining of pods and pod priority scheduling affects the pods that have disruption budget assigned to them. PDB is crucial when we have a Quorum-based application. When trying to evict pods we can use the eviction API by using
curl command to make calls to the eviction API. Below are examples of how to use Pod Disruption Budget and making calls to the eviction API.
tunde:~ babatundeolu-isa$ kubectl create pdb aquatribe-pdb --selector=app=aquatribe --min-available=3 poddisruptionbudget.policy "aquatribe-pdb" created
apiVersion: policy/v1beta1 kind: PodDisruptionBudget metadata: name: aquatribe-pdb spec: selector: matchLabels: app: aquatribe minAvailable: 60%
apiVersion: policy/v1beta1 kind: PodDisruptionBudget metadata: name: aquatribe-pdb spec: selector: matchLabels: app: aquatribe maxUnavailable: 40%
tunde:~ babatundeolu-isa$ curl -k -v -H 'Content-type: application/json' https://localhost:6443/api/v1/namespaces/default/pods/busybox-59485cf84c-2kxms/eviction -d @disruption.json