A pod disruption budget is part of the
Kubernetes API, which can be
managed with oc
commands like other
object types. They
allow the specification of safety constraints on pods during operations, such as
draining a node for maintenance.
PodDisruptionBudget
is an API object that specifies the minimum number or
percentage of replicas that must be up at a time. Setting these in projects can
be helpful during node maintenance (such as scaling a cluster down or a cluster
upgrade) and is only honored on voluntary evictions (not on node failures).
A PodDisruptionBudget
object’s configuration consists of the following key
parts:
-
A label selector, which is a label query over a set of pods.
-
An availability level, which specifies the minimum number of pods that must be
available simultaneously.
The following is an example of a PodDisruptionBudget
resource:
apiVersion: policy/v1alpha1 (1)
kind: PodDisruptionBudget
metadata:
name: my-pdb
spec:
selector: (2)
matchLabels:
foo: bar
minAvailable: 2 (3)
1 |
PodDisruptionBudget is part of the policy/v1alpha API group. |
2 |
A label query over a set of resources. The result of matchLabels and
matchExpressions are logically conjoined. |
3 |
The minimum number of pods that must be available simultaneously. This can
be either an integer or a string specifying a percentage (for example, 20% ). |
If you created a YAML file with the above object definition, you could add it to project with the following:
$ oc create -f </path/to/file> -n <project_name>
You can check for pod disruption budgets across all projects with the following:
$ oc get poddisruptionbudget --all-namespaces
NAMESPACE NAME MIN-AVAILABLE SELECTOR
another-project another-pdb 4 bar=foo
test-project my-pdb 2 foo=bar
The PodDisruptionBudget
is considered healthy when there are at least
minAvailable
pods running in the system. Every pod above that limit can be
evicted.