title: How to implement Kubernetes horizontal pod autoscaling with scale up/down policies?
body: <p>Kubernetes v1.19 in AWS EKS</p>
  <p>I'm trying to implement horizontal pod autoscaling in my EKS cluster, and am trying to mimic what we do now with ECS. With ECS, we do something similar to the following</p>
  <ul>
  <li>scale up when CPU &gt;= 90% after 3 consecutive 1-min periods of sampling</li>
  <li>scale down when CPU &lt;= 60% after 5 consecutive 1-min periods of sampling</li>
  <li>scale up when memory &gt;= 85% after 3 consecutive 1-min periods of sampling</li>
  <li>scale down when memory &lt;= 70% after 5 consecutive 1-min periods of sampling</li>
  </ul>
  <p>I'm trying to use the <code>HorizontalPodAutoscaler</code> kind, and <code>helm create</code> gives me this template. (Note I modified it to suit my needs, but the <code>metrics</code> stanza remains.)</p>
  <pre><code>{- if .Values.autoscaling.enabled }}
  apiVersion: autoscaling/v2beta1
  kind: HorizontalPodAutoscaler
  metadata:
    name: {{ include &quot;microserviceChart.Name&quot; . }}
    labels:
      {{- include &quot;microserviceChart.Name&quot; . | nindent 4 }}
  spec:
    scaleTargetRef:
      apiVersion: apps/v1
      kind: Deployment
      name: {{ include &quot;microserviceChart.Name&quot; . }}
    minReplicas: {{ include &quot;microserviceChart.minReplicas&quot; . }}
    maxReplicas: {{ include &quot;microserviceChart.maxReplicas&quot; . }}
    metrics:
      {{- if .Values.autoscaling.targetCPUUtilizationPercentage }}
      - type: Resource
        resource:
          name: cpu
          targetAverageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
      {{- end }}
      {{- if .Values.autoscaling.targetMemoryUtilizationPercentage }}
      - type: Resource
        resource:
          name: memory
          targetAverageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
      {{- end }}
  {{- end }}
  </code></pre>
  <p>However, how do I fit the scale up/down information shown in <a href="https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/" rel="noreferrer">Horizontal Pod Autoscaling</a> in the above template, to match the behavior that I want?</p>