首页 > 解决方案 > K8S - 没有部署对象的 HPA

问题描述

我在玩 k8s HPA - 水平 pod autoscaler。事情按预期工作(如此处所述 - https://kubernetes.io/docs/tasks/run-application/horizo​​ntal -pod-autoscale-walkthrough/ )

如果我删除部署kubectl delete deploy php-apache ,部署将被删除,pod 将被删除。但是 HPA 条目仍然存在用于部署。在没有部署对象的情况下,这个入口有什么意义?

标签: kubernetes

解决方案


从逻辑上讲,水平 pod 自动扩缩器是一个控制循环,用于检查其指定目标(例如部署)以查看是否满足指标阈值。(这实际上是通过控制器管理器和指标 API 发生的)。HPA 是它自己的独立资源,它通过称为Scale subresource. 这是一种抽象,可充当 Kubernetes 可能希望自动扩展的任何未来资源(不仅仅是部署)的接口。

Horizo​​ntal Pod Autoscaler 的规格(取自 k8s 设计文档):

type HorizontalPodAutoscalerSpec struct {
    // reference to Scale subresource; horizontal pod autoscaler will learn the current resource
    // consumption from its status,and will set the desired number of pods by modifying its spec.
    ScaleRef SubresourceReference
    // lower limit for the number of pods that can be set by the autoscaler, default 1.
    MinReplicas *int
    // upper limit for the number of pods that can be set by the autoscaler.
    // It cannot be smaller than MinReplicas.
    MaxReplicas int
    // target average CPU utilization (represented as a percentage of requested CPU) over all the pods;
    // if not specified it defaults to the target CPU utilization at 80% of the requested resources.
    CPUUtilization *CPUTargetUtilization
}

请注意,HPA 使用 scale ref 来定位所需的资源,而 Deployment 通过其选择器包含多个资源。出于灵活性原因,HPA 与特定部署分离。这意味着当您删除 Deployment 时,k8s 可以删除它通过其选择器管理的所有内容。HPA 不由 Deployment 管理,而仅通过其自己的规范连接到它。HPA 可以保留,等待新的部署取代原来的位置,可以重新配置,也可以删除。


推荐阅读