107、kubernetes之HPA

1.HPA的配置

kubernetes中针对HPA的配置位于kube-controller-manager中,如下:

--horizontal-pod-autoscaler-downscale-delay duration                The period since last downscale, before another downscale can be performed in horizontal pod autoscaler. (default 5m0s)
--horizontal-pod-autoscaler-sync-period duration                    The period for syncing the number of pods in horizontal pod autoscaler. (default 30s)
--horizontal-pod-autoscaler-tolerance float                         The minimum change (from 1.0) in the desired-to-actual metrics ratio for the horizontal pod autoscaler to consider scaling. (default 0.1)
--horizontal-pod-autoscaler-upscale-delay duration                  The period since last upscale, before another upscale can be performed in horizontal pod autoscaler. (default 3m0s)
--horizontal-pod-autoscaler-use-rest-clients                        If set to true, causes the horizontal pod autoscaler controller to use REST clients through the kube-aggregator, instead of us

注意:对于有状态服务,扩缩容只能发生在所有pod为ready和running状态后

2.颠簸问题

所谓的颠簸就是容器在短时间内指标频繁波动导致副本数量频繁变化。解决此问题的处理方法是通过调整kube-controller-manager组件标志公开的全局HPA设置来缓解此问题。但是调整这两个时间要根据实际情况,如果调整太小会导致颠簸问题,如果调整太大会导致水平扩容的不及时,短时间内给应用造成很大负载(甚至可能应用down掉)

  • --horizontal-pod-autoscaler-downscale-delay:此选项的值是一个持续时间,指定控制器在两次缩容之间的时间间隔。默认值是5分钟(5m0s)。

  • --horizontal-pod-autoscaler-upscale-delay:此选项的值是一个持续时间,指定控制器在两次扩容之间的时间间隔。默认值是3分钟(3m0s)。

3.扩缩容指标的来源

  • 默认情况下扩缩容的依据来源于heapster采集的指标

  • 如果要使用自定义的指标,需要在部署群集时设置必要的配置启动API聚合层。

--requestheader-client-ca-file=<path to aggregator CA cert>
--requestheader-allowed-names=aggregator
--requestheader-extra-headers-prefix=X-Remote-Extra-
--requestheader-group-headers=X-Remote-Group
--requestheader-username-headers=X-Remote-User
--proxy-client-cert-file=<path to aggregator proxy cert>
--proxy-client-key-file=<path to aggregator proxy key>
#没有安装kube-proxy的情况下开启如下配置
--enable-aggregator-routing=true
  • kube-controller-manager中的其他配置。
    需要注意的是可以使用--master或--kubeconfig标志;如果两者都被指定,--master将会覆盖--kubeconfig,主要指定Apiserver的位置,使控制器能够和与API服务器进行通信。
--horizontal-pod-autoscaler-use-rest-clients 应该是true。

--kubeconfig <path-to-kubeconfig> 
或者
--master <ip-address-of-apiserver>
  • 自定义度量值指标类型:Pod度量指标和对象度量指标
    1. Pod度量指从某个维度计算,不同pod的期望扩缩的最终容器数不一样,才是采取平局值,和预期值比较来确定是否扩缩容
    2. 对象度量指标值该pod的度量值是从所在命名空间的其他对象上获取指标,多个指标最终就会导致扩缩容的目标结果不一致,此时采用的是最大值
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容