<p>I can't find any examples as to where the behavior section should be specified in <code>Kind: HorizontalPodAutoscaler</code>.</p>
<p>In the docs they have this <a href="https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/#default-behavior" rel="nofollow noreferrer">section</a> but I couldn't find any examples as where it should fit in?</p>
<pre><code>behavior:
  scaleDown:
    stabilizationWindowSeconds: 300
    policies:
    - type: Percent
      value: 100
      periodSeconds: 15
  scaleUp:
    stabilizationWindowSeconds: 0
    policies:
    - type: Percent
      value: 100
      periodSeconds: 15
    - type: Pods
      value: 4
      periodSeconds: 15
    selectPolicy: Max
</code></pre>
<p>Here is a sample <code>auto-scaler.yml</code> without the behavior section</p>
<pre><code>apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
  name: nginx
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: nginx
  minReplicas: 1
  maxReplicas: 10
  metrics:
  - type: Resource
    resource:
      name: cpu
      target:
        type: Utilization
        averageUtilization: 50
  - type: Resource
    resource:
      name: memory
      target:
        type: AverageValue
        averageValue: 100Mi
</code></pre>

user630702
<p>Talking specifically about your example you will need to paste your <code>.behavior</code> definition  part under the <code>.spec</code> like below:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
  name: nginx
spec:
  # &lt;--- START ---&gt; 
  behavior:
    scaleDown:
      stabilizationWindowSeconds: 300
      policies:
      - type: Percent
        value: 100
        periodSeconds: 15
    scaleUp:
      stabilizationWindowSeconds: 0
      policies:
      - type: Percent
        value: 100
        periodSeconds: 15
      - type: Pods
        value: 4
        periodSeconds: 15
      selectPolicy: Max
      # &lt;--- END ---&gt; 
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: nginx
  minReplicas: 1
  maxReplicas: 10
  metrics:
  - type: Resource
    resource:
      name: cpu
      target:
        type: Utilization
        averageUtilization: 50
  - type: Resource
    resource:
      name: memory
      target:
        type: AverageValue
        averageValue: 100Mi
</code></pre>
<p><strong>Please remember that this feature is available from Kubernetes v1.18.</strong></p>
<p>Earlier version of Kubernetes will show following error:</p>
<pre class="lang-sh prettyprint-override"><code>error: error validating &quot;hpa.yaml&quot;: error validating data: ValidationError(HorizontalPodAutoscaler.spec): unknown field &quot;behavior&quot; in io.k8s.api.autoscaling.v2beta2.HorizontalPodAutoscalerSpec; if you choose to ignore these errors, turn validation off with --validate=false
</code></pre>
<hr />
<p>As for a side note you can also take a look on:</p>
<ul>
<li><code>$ kubectl autoscale</code></li>
<li><code>$ kubectl autoscale deployment nginx --min=1 --max=10 --cpu-percent=80</code> &lt;- example</li>
</ul>
<blockquote>
<p>Creates an autoscaler that automatically chooses and sets the number of pods that run in a kubernetes cluster.</p>
</blockquote>
<hr />
<p>Additional reference:</p>
<ul>
<li><em><a href="https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/" rel="nofollow noreferrer">Kubernetes.io: Docs: Tasks: Run application: Horizontal pod autoscaler</a></em></li>
<li><em><a href="https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#autoscale" rel="nofollow noreferrer">Kubernetes.io: Docs: Reference: Generated: Kubectl: kubectl commands: autoscale</a></em></li>
</ul>
