Kubernetes Autoscaler:当可以缩减规模时部署不会停机?

Kubernetes Autoscaler: no downtime for deployments when downscaling is possible?

在一个项目中,我正在从 Kubernetes 启用集群自动缩放器功能。

根据文档:How does scale down work,据我了解,当一个节点在给定时间内的使用量低于其容量的 50% 时,它将连同其所有 pods,如果需要,将在不同的节点中复制。

但可能会出现以下问题:如果与特定部署相关的所有 pods 都包含在要删除的节点中怎么办?这意味着用户可能会遇到此部署应用程序的停机时间。

有没有一种方法可以避免在部署仅包含 pods 运行 节点时缩减删除该节点?

我已经检查了文档,一个可能(但不是很好)的解决方案是为所有包含应用程序 here 的 pods 添加注释,但这显然不会缩小规模集群以最佳方式。

您提到的同一份文件有:

How is Cluster Autoscaler different from CPU-usage-based node autoscalers? Cluster Autoscaler makes sure that all pods in the cluster have a place to run, no matter if there is any CPU load or not. Moreover, it tries to ensure that there are no unneeded nodes in the cluster.

CPU-usage-based (or any metric-based) cluster/node group autoscalers don't care about pods when scaling up and down. As a result, they may add a node that will not have any pods, or remove a node that has some system-critical pods on it, like kube-dns. Usage of these autoscalers with Kubernetes is discouraged.

在同一文档中:

What happens when a non-empty node is terminated? As mentioned above, all pods should be migrated elsewhere. Cluster Autoscaler does this by evicting them and tainting the node, so they aren't scheduled there again.

什么是Eviction?:

The eviction subresource of a pod can be thought of as a kind of policy-controlled DELETE operation on the pod itself.

好的,但是如果节点上的所有 pods 同时被驱逐怎么办? 您可以使用 Pod Disruption Budget 来确保最少的副本始终有效:

什么是 PDB?:

A PDB limits the number of Pods of a replicated application that are down simultaneously from voluntary disruptions.

k8s docs中您还可以阅读:

A PodDisruptionBudget has three fields:

A label selector .spec.selector to specify the set of pods to which it applies. This field is required.

.spec.minAvailable which is a description of the number of pods from that set that must still be available after the eviction, even in the absence of the evicted pod. minAvailable can be either an absolute number or a percentage.

.spec.maxUnavailable (available in Kubernetes 1.7 and higher) which is a description of the number of pods from that set that can be unavailable after the eviction. It can be either an absolute number or a percentage.

因此,如果您使用 PDB 进行部署,则不应一次将其全部删除。

但请注意,如果节点由于其他原因(例如硬件故障)而失败,您仍然会遇到停机时间。如果您真的关心高可用性,请考虑使用 pod 反亲和性来确保 pods 不会全部安排在一个节点上。