Kubernetes - ReplicaSet 与 PodDisruptionBudget

Kubernetes - ReplicaSet vs PodDisruptionBudget

我想知道 PodDisruptionBudget 有什么附加价值。

据我了解,PodDisruptionBudget 承诺一定数量的节点将始终保留在集群中,同时有 2 个选项可以决定如何:minAvailable / maxUnavailable。

现在,当我定义 ReplicaSet 时,我定义了我想要的副本数。因此,例如我定义 2,则不会少于 2 个副本。那么什么给了 PodDisruptionBudget?

PodDisruptionBudget 有助于确保 ReplicaSet 无法保证的应用程序的零停机时间。

following post 举例说明了 PodDisruptionBudget 如何有助于实现应用程序的零停机时间:

引用post,节点升级是一个正常的场景,描述如下:

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在其中一个节点上执行升级:

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.

运行 kubectl get pods -w 将在节点上显示 pods 运行 进入导致停机的终止状态:

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.

PodDisruptionBudgetminAvailable 在这种情况下很有用,可以实现零停机时间。 Replicaset只会保证pods的replicas个数 在此过程中在其他节点上创建。

如果您只有一个 Replicaset 和一个副本并且没有指定 PodDisruptionBudget,pod 将被终止并在其他节点上创建一个新的 pod。这就是 PDBs 比 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.

Then what gives the PodDisruptionBudget?

如果您有一个需要高可用性的应用程序,例如每次崩溃后重建缓存可能需要一些时间。

两次 voluntary and involuntary 中断。 PodDisruptionBudget 可以限制后者,但两者都计入预算。

自愿中断的一个例子是当你的平台团队的一名员工决定为你的所有节点升级内核时——有时你想慢慢地做这件事,因为所有 Pods 节点上的将被终止并调度到不同的节点。

还有非自愿中断,例如您的一个节点上的磁盘崩溃。

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

minAvailable 为 2。 maxAvailable 是一个错误的名称,它是 maxUnavailable.