本文介绍了在Kubernetes中为Statefulset应用HPA?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在kubernetes环境中为我的statefulset(用于elasticsearch)设置HPA.我正计划使用cpu利用率来扩展statefulset.我已经从 https://github.com创建了度量服务器/stefanprodan/k8s-prom-hpa/tree/master/metrics-server .

I am trying to setup HPA for my statefulset(for elasticsearch) in kubernetes environment. I am planning to scale the statefulset using the cpu utilization. I have created the metric server from https://github.com/stefanprodan/k8s-prom-hpa/tree/master/metrics-server.

我的状态状态HPA yaml如下:

and my HPA yaml for statefulset is as folows:

apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
  name: dz-es-cluster
spec:
  scaleTargetRef:
    apiVersion: extensions/v1beta1
    kind: StatefulSet
    name: dz-es-cluster
  minReplicas: 2
  maxReplicas: 3
  metrics:
  - type: Resource
    resource:
      name: cpu
      targetAverageUtilization: 80

但是要在hpa中获得输出,如下所示:

But getting output in hpa as follows:

Conditions:
  Type         Status  Reason          Message
  ----         ------  ------          -------
  AbleToScale  False   FailedGetScale  the HPA controller was unable to get the target's current scale: the server could not find the requested resource
Events:
  Type     Reason          Age                From                       Message
  ----     ------          ----               ----                       -------
  Warning  FailedGetScale  1m (x71 over 36m)  horizontal-pod-autoscaler  the server could not find the requested resource

请有人帮我.

推荐答案

在kubernetes 1.9中添加了使用HPA自动缩放状态集的支持,因此您的版本不支持它.在kubernetes 1.9之后,您可以使用以下方法自动缩放状态集:

The support for autoscaling the statefulsets using HPA is added in kubernetes 1.9, so your version doesn't has support for it. After kubernetes 1.9, you can autoscale your statefulsets using:

apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
  name: YOUR_HPA_NAME
spec:
  maxReplicas: 3
  minReplicas: 1
  scaleTargetRef:
    apiVersion: apps/v1
    kind: StatefulSet
    name: YOUR_STATEFUL_SET_NAME
  targetCPUUtilizationPercentage: 80

请参考以下链接以获取更多信息:

Please refer the following link for more information:

这篇关于在Kubernetes中为Statefulset应用HPA?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-19 11:26