<p>I'm creating a HorizontalPodAutoscaler in Kubernetes and I need to configure the downscale stabilization window to be smaller than the default. The code used and error are below:</p>

<pre><code>apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
    name: busy-autoscaler
spec:
    behavior:
        scaleDown:
            stabilizationWindowSeconds: 10
    scaleTargetRef:
        apiVersion: apps/v1
        kind: Deployment
        name: busy-worker
    minReplicas: 1
    maxReplicas: 2
    metrics:
        - type: Resource
          resource:
              name: cpu
              target:
                  type: Utilization
                  averageUtilization: 50
</code></pre>

<pre><code>$ kubectl create -f some-autoscale.yaml
error validating "some-autoscale.yaml": error validating data: ValidationError(HorizontalPodAutoscaler.spec): unknown field "behavior" in io.k8s.api.autoscaling.v2beta2.HorizontalPodAutoscalerSpec
</code></pre>

<p>My understanding is that the <code>behavior</code> field should be supported from Kubernetes 1.17 as stated in the <a href="https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/#support-for-configurable-scaling-behavior" rel="nofollow noreferrer">docs</a>. Running <code>kubectl version</code> gives the following output:</p>

<pre><code>Client Version: version.Info{Major:"1", Minor:"17", GitVersion:"v1.17.1", GitCommit:"d224476cd0730baca2b6e357d144171ed74192d6", GitTreeState:"clean", BuildDate:"2020-01-14T21:04:32Z", GoVersion:"go1.13.5", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"17", GitVersion:"v1.17.0", GitCommit:"70132b0f130acc0bed193d9ba59dd186f0e634cf", GitTreeState:"clean", BuildDate:"2019-12-07T21:12:17Z", GoVersion:"go1.13.4", Compiler:"gc", Platform:"linux/amd64"}
</code></pre>

<p>The <a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.17/#horizontalpodautoscalerspec-v2beta2-autoscaling" rel="nofollow noreferrer">API reference</a> doesn't have the <code>behavior</code> field for <code>v2beta2</code> which makes this more confusing.</p>

<p>I'm running Minikube 1.6.2 locally. What am I doing wrong?</p>

cjm
<p>So it looks like this was a case of incorrect documentation that was corrected shortly after I asked my question. <a href="https://github.com/kubernetes/website/pull/18157" rel="nofollow noreferrer">PR #18157</a> on <code>kubernetes/website</code> adds the following text to the page on the <a href="https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/" rel="nofollow noreferrer">Horizontal Pod Autoscaler</a>.</p>

<blockquote>
  <p>Starting from v1.17 the downscale stabilization window can be set on a per-HPA
  basis by setting the <code>behavior.scaleDown.stabilizationWindowSeconds</code> field in
  the v2beta2 API. See Support for configurable scaling
  behavior.</p>
</blockquote>

<p><a href="https://github.com/kubernetes/website/pull/18965" rel="nofollow noreferrer">PR #18965</a> reverts the previous pull request since the <code>behavior</code> object is functionality targeted in 1.18, not 1.17.</p>

<p>For now, the solution is to use the <code>--horizontal-pod-autoscaler-downscale-stabilization</code> flag on the controller manager as mentioned in @ShantyMan's answer above which will set the value for every HPA.</p>
