Kubernetes - ReplicaSet vs PodDisruptionBudget

2/16/2021

I was wondering what added value gives the PodDisruptionBudget.

As far as I understand, PodDisruptionBudget promises that a certain amount of nodes will always remain in the cluster while there are 2 options to decide how: minAvailable / maxUnavailable.

Now, when I define ReplicaSet I define how many replicas I want. So if for example I define 2, there won't be less than 2 replicas. Then what gives the PodDisruptionBudget?

-- jrz
kubernetes
kubernetes-pod
replicaset

3 Answers

2/16/2021

Then what gives the PodDisruptionBudget?

If you have an application where you want high availability e.g. it may take time to rebuild a cache after each crash.

There are both voluntary and involuntary disruptions. PodDisruptionBudget can limit the latter but both counts against the budget.

An example of voluntary disruption is when an employee of your platform team decide to upgrade the kernel for all your nodes - sometimes you want to do this slowly since all Pods on the node will be terminated and scheduled to a different node.

There is also involuntary disruptions e.g. a disk crash on one of your nodes.

-- Jonas
Source: StackOverflow

2/16/2021

So if for example I define 2, there won't be less than 2 replicas. Then what gives the PodDisruptionBudget?

It's 2 for minAvailable. And maxAvailable is a wrong name , it's maxUnavailable.

-- Daein Park
Source: StackOverflow

2/16/2021

PodDisruptionBudget helps in ensuring zero downtime for an application which ReplicaSet can't guarantee.

The following post explains with an example how PodDisruptionBudget can be useful in achieving zero downtime for an application:

Quoting the post, the node upgrade is a normal scenario as described in:

Let’s consider a scenario, we need to upgrade version of node or update the spec often. Cluster downscaling is also a normal condition. In these cases, the pods running on the to-be-deleted nodes needs to be drained.

kubectl drain is performed on one of the nodes for the upgrade:

We need to remove node1 from the pool which we cannot do it by detaching instantly as that will lead to termination of all the pods running in there which can get services down. First step before detaching node is to make the node unscheduled.

Running kubectl get pods -w will show the pods running on the node get in termination state which leads to a downtime:

If you quickly check the pods with kubectl get pods , it will terminate all the running pods instantly which were scheduled on node1 . This could lead a downtime! If you are running few number of pods and all of them are scheduled on same node, it will take some time for the pods to be scheduled on other node.

PodDisruptionBudget with minAvailable are useful in such scenarios to achieve zero downtime. Replicaset will only ensure that the replicas number of pods will be created on other nodes during the process.

If you just have a Replicaset with one replica and no PodDisruptionBudget specified, the pod will be terminated and a new pod will be created on other nodes. This is where PDBs provide the added advantage over the Replicaset.

For the PodDisruptionBudget to work, there must be at least 2 pods running for a label selector otherwise, the node cannot be drained gracefully and it will be evicted forcefully when grace time ends.

-- Krishna Chaurasia
Source: StackOverflow