在 kubernetes 中将 HPA 应用于 Statefulset



我正在尝试在 kubernetes 环境中为我的 statefulset(for elasticsearch(设置 HPA。我计划使用 CPU 利用率扩展状态集。我从 https://github.com/stefanprodan/k8s-prom-hpa/tree/master/metrics-server 创建了公制服务器。

而我的 HPA yaml 用于有状态集是 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 为单位获得输出,如下所示:

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 之后,您可以使用以下方法自动扩展有状态集:

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

最新更新