kubernetes - K8S - 没有部署对象的 HPA
问题描述
我在玩 k8s HPA - 水平 pod autoscaler。事情按预期工作(如此处所述 - https://kubernetes.io/docs/tasks/run-application/horizontal -pod-autoscale-walkthrough/ )
如果我删除部署kubectl delete deploy php-apache
,部署将被删除,pod 将被删除。但是 HPA 条目仍然存在用于部署。在没有部署对象的情况下,这个入口有什么意义?
解决方案
从逻辑上讲,水平 pod 自动扩缩器是一个控制循环,用于检查其指定目标(例如部署)以查看是否满足指标阈值。(这实际上是通过控制器管理器和指标 API 发生的)。HPA 是它自己的独立资源,它通过称为Scale subresource
. 这是一种抽象,可充当 Kubernetes 可能希望自动扩展的任何未来资源(不仅仅是部署)的接口。
Horizontal 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 可以保留,等待新的部署取代原来的位置,可以重新配置,也可以删除。
推荐阅读
- database - 用户和通知之间有什么样的数据库关系?
- excel - 如何从另一个文件vba匹配索引宏
- css - Angular Material Pagination - 如何用文本替换第一个和最后一个图标?
- html - 如何在 Nuxtjs 应用程序中使用 Bootstrap Vue 创建特定的引导多选下拉菜单
- mysql - 为什么mysql执行sql需要多次转换字符集
- apache - 如何配置 HTTP 服务器以在 HTTP 标头中设置 REMOTE_USER?
- python - 如何序列化一个对象
- karate - 如何从 karate-config.js 检查一个 API 的状态码?
- json - JsonPath 找到包含某个字符串的所有键?
- python - 从数组中获取字典