<p>I've added some scaling policies to my <strong>HorizontalPodAutoscaler</strong> but they are not being applied. The <em>scaleUp</em> and <em>scaleDown</em> behaviours are being ignored. I need a way to stop pods scaling up and down every few minutes in response to small CPU spikes. Ideally the HPA would scale up quickly in response to more traffic but scale down slowly after about 30 minutes of reduced traffic.</p>

<p>I'm running this on an AWS EKS cluster and I have setup the policies according to <a href="https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/#support-for-configurable-scaling-behavior" rel="nofollow noreferrer">https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/#support-for-configurable-scaling-behavior</a>.</p>

<p>Could this be a limitation of EKS or my K8s version which is 1.14. I have run <code>kubectl api-versions</code> and my cluster does support <em>autoscaling/v2beta2</em>.</p>

<p>My Helm spec is:</p>

<pre><code>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
</code></pre>

<p>It works for me,</p>
<p>Client Version: v1.20.2
Server Version: v1.18.9-eks-d1db3c</p>
<p>kubectl api-versions and my cluster also supports autoscaling/v2beta2</p>
<pre><code>apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
  name: {{ template &quot;ks.fullname&quot; . }}-keycloak
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: {{ template &quot;ks.fullname&quot; . }}-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 }}
</code></pre>
