1

我在 Horizo​​ntalPodAutoscaler 中添加了一些扩展策略,它们没有被应用。scaleUp和scaleDown行为被忽略。我需要一种方法来阻止 Pod 每隔几分钟就扩大和缩小一次以响应小的 CPU 峰值。理想情况下,HPA 会迅速扩大以响应更多流量,但在减少约 30 分钟的流量后缓慢缩小。

我在 AWS EKS 集群上运行它,我已经根据https://kubernetes.io/docs/tasks/run-application/horizo ​​ntal-pod-autoscale/#support-for-configurable-scaling-behavior 设置了策略.

这可能是 EKS 或我的 K8s 版本 1.14 的限制。我已经运行kubectl api-versions并且我的集群确实支持autoscaling/v2beta2

我的 Helm 规格是:

apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
  name: {{ template "app.fullname" . }}
  labels:
    app: {{ template "app.name" . }}
    chart: {{ template "app.chart" . }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
spec:
  scaleTargetRef:
    apiVersion: apps/v1beta2
    kind: Deployment
    name: "{{ template "app.fullname" . }}-server"
  minReplicas: {{ .Values.hpa.minReplicas }}
  maxReplicas: {{ .Values.hpa.maxReplicas }}
  metrics:
  - type: Resource
    resource:
      name: cpu
      target:
        type: AverageValue
        averageValue: 200m
  behavior:
    scaleUp:
      stabilizationWindowSeconds: 300
      policies:
      - type: Pods
        value: 1
        periodSeconds: 300
    scaleDown:
      stabilizationWindowSeconds: 1200
      policies:
      - type: Pods
        value: 1
        periodSeconds: 300
4

3 回答 3

1

这个对我有用,

客户端版本:v1.20.2 服务器版本:v1.18.9-eks-d1db3c

kubectl api-versions 和我的集群也支持 autoscaling/v2beta2

apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
  name: {{ template "ks.fullname" . }}-keycloak
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: {{ template "ks.fullname" . }}-keycloak
  minReplicas: {{ .Values.keycloak.hpa.minpods }}
  maxReplicas: {{ .Values.keycloak.hpa.maxpods }}
  metrics:
  - type: Resource
    resource:
      name: memory
      target:
        type: Utilization
        averageUtilization: {{ .Values.keycloak.hpa.memory.averageUtilization }}
  - type: Resource
    resource:
      name: cpu
      target:
        type: Utilization
        averageUtilization: {{ .Values.keycloak.hpa.cpu.averageUtilization }}
  behavior:
    scaleDown:
      stabilizationWindowSeconds: {{ .Values.keycloak.hpa.stabilizationWindowSeconds }}
      policies:
        - type: Pods
          value: 1
          periodSeconds: {{ .Values.keycloak.hpa.periodSeconds }}
{{- end }}
于 2021-02-11T23:01:35.977 回答
0

正如评论中已经讨论的那样,即使autoscaling/v2beta2启用此功能也无法在 1.14 版本上运行。

v1.18开始, v2beta2 API 允许通过 HPA 行为字段配置缩放行为。

最简单的方法是升级到 1.18。

于 2020-04-22T07:46:04.210 回答
0

我想根据对targetAverageValue我有用的方法来实施 HPA

虽然 GKE 版本在您身边,但您1.12 to 1.14将无法应用清单,autoscaling/v2beta2但是您可以应用相同的东西,例如

apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
  name: core-deployment
  namespace: default
spec:
  maxReplicas: 9
  minReplicas: 5
  scaleTargetRef:
    apiVersion: extensions/v1beta1
    kind: Deployment
    name: core-deployment
  metrics:
  - type: Resource
    resource:
      name: cpu
      targetAverageValue: 500m
于 2020-09-14T09:51:35.833 回答