是否可以在kubernetes中将HPA应用于Statefulset?

时间:2019-02-13 06:25:00

标签: elasticsearch kubernetes autoscaling kubernetes-statefulset

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

我的状态状态HPA yaml如下:

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中获得输出如下:

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

请有人帮我。

1 个答案:

答案 0 :(得分:2)

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

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

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

  

https://github.com/kubernetes/kubernetes/issues/44033