<p>Friends, I am trying to implement a HPA following the <a href="https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale-walkthrough/" rel="nofollow noreferrer">hpa tutorial</a> of k8s and I am having the following error:</p>
<p><strong>ValidationError(HorizontalPodAutoscaler.status): missing required field &quot;conditions&quot; in io.k8s.api.autoscaling.v2beta2.HorizontalPodAutoscalerStatus</strong>.</p>
<p>I couldn't find anything about this field &quot;conditions&quot;. Does someone have an idea what I may be doing wrong? Here its the YAML of my HPA:</p>
<pre><code>apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
  name: {{ .Values.name }}
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: {{ .Values.name}}
  minReplicas: {{ .Values.deployment.minReplicas }}
  maxReplicas: {{ .Values.deployment.maxReplicas }}
  metrics:
  - type: Resource
    resource:
      name: cpu
      target:
        type: Utilization
        averageUtilization: 50
status:
  observedGeneration: 1
  lastScaleTime: &lt;some-time&gt;
  currentReplicas: 2
  desiredReplicas: 2
  currentMetrics:
  - type: Resource
    resource:
      name: cpu
      current:
        averageValue: 0
</code></pre>
<p>And here the manifest of my deployment:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .Values.name }}
spec:
  replicas: {{ .Values.deployment.replicaCount }}
  selector:
    matchLabels:
      app: {{ .Values.labels}}
  template:
    metadata:
      annotations:
        checksum/config: {{ include (print $.Template.BasePath &quot;/configmap.yaml&quot;) . | sha256sum }}
      labels:
        app: {{ .Values.labels }}
    spec:
      initContainers:
      - name: check-rabbitmq
        image: {{ .Values.initContainers.image }}
        command: ['sh', '-c',
        'until wget http://$(RABBITMQ_DEFAULT_USER):$(RABBITMQ_DEFAULT_PASS)@rabbitmq:15672/api/aliveness-test/%2F; 
        do echo waiting; sleep 2; done;']
        envFrom:
        - configMapRef:
            name: {{ .Values.name }}
      - name: check-mysql
        image: {{ .Values.initContainers.image }}
        command: ['sh', '-c', 'until nslookup mysql-primary.default.svc.cluster.local; do echo waiting for mysql; sleep 2; done;']
      containers:
      - name: {{ .Values.name }}
        image: {{ .Values.deployment.image }}
        ports:
        - containerPort: {{ .Values.ports.containerPort }} 
        resources:
          limits:
            cpu: 500m
          requests:
            cpu: 200m
        envFrom:
        - configMapRef:
            name: {{ .Values.name }}
</code></pre>

<h3>Background</h3>
<p>Not sure, why you want to create <code>HPA</code> with <code>status</code> section. If you would remove this section it will create <code>HPA</code> without any issue.</p>
<p>In documentation <a href="https://kubernetes.io/docs/concepts/overview/working-with-objects/kubernetes-objects/#object-spec-and-status" rel="nofollow noreferrer">Understanding Kubernetes Objects - Object Spec and Status</a> you can find information:</p>
<blockquote>
<p>Almost every Kubernetes object includes two nested object fields that govern the object's configuration: the object <code>spec</code> and the object <code>status</code>. For objects that have a <code>spec</code>, you have to set this when you create the object, providing a description of the characteristics you want the resource to have: its desired state.</p>
</blockquote>
<blockquote>
<p>The <code>status</code> describes the current state of the object, <strong>supplied and updated by the Kubernetes system and its components.</strong> The Kubernetes control plane continually and actively manages every object's actual state to match the desired state you supplied.</p>
</blockquote>
<p>Your situation is partially described in <a href="https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale-walkthrough/#appendix-horizontal-pod-autoscaler-status-conditions" rel="nofollow noreferrer">Appendix: Horizontal Pod Autoscaler Status Conditions</a></p>
<blockquote>
<p>When using the <code>autoscaling/v2beta2</code> form of the <code>HorizontalPodAutoscaler</code>, you will be able to see status conditions set by Kubernetes on the HorizontalPodAutoscaler. These status conditions indicate whether or not the <code>HorizontalPodAutoscaler</code> is able to <code>scale</code>, and whether or not it is currently restricted in any way.</p>
</blockquote>
<h3>Example from my GKE test cluster</h3>
<p>As I mention before, if you will remove <code>status</code> section, you will be able to create <code>HPA</code>.</p>
<pre><code>$ kubectl apply -f - &lt;&lt;EOF
&gt; apiVersion: autoscaling/v2beta2
&gt; kind: HorizontalPodAutoscaler
&gt; metadata:
&gt;   name: hpa-apache
&gt; spec:
&gt;   scaleTargetRef:
&gt;     apiVersion: apps/v1
&gt;     kind: Deployment
&gt;     name: php-apache
&gt;   minReplicas: 1
&gt;   maxReplicas: 3
&gt;   metrics:
&gt;   - type: Resource
&gt;     resource:
&gt;       name: cpu
&gt;       target:
&gt;         type: Utilization
&gt;         averageUtilization: 50
&gt; EOF
horizontalpodautoscaler.autoscaling/hpa-apache created
</code></pre>
<p>Following <code>HPA</code> documentation, I've created <code>PHP Deployment</code>.</p>
<pre><code>$ kubectl apply -f https://k8s.io/examples/application/php-apache.yaml
deployment.apps/php-apache created
service/php-apache created
</code></pre>
<p>When you executed command <code>kubectl autoscale</code> you have created <code>HPA</code> for deployment <code>php-apache</code></p>
<pre><code>$ kubectl autoscale deployment php-apache --cpu-percent=50 --min=1 --max=10
horizontalpodautoscaler.autoscaling/php-apache autoscaled
</code></pre>
<p>Now you are able to see <code>hpa</code> resource using <code>kubectl get hpa</code> or <code>kubectl get hpa.v2beta2.autoscaling</code>. Output is the same.</p>
<p>First command will show all <code>HPA</code> objects with any <code>apiVersion</code> (<code>v2beta2</code>, <code>v2beta1</code>, etc), second command will show <code>HPA</code> only with <code>apiVersion: hpa.v2beta2.autoscaling</code>. My cluster as default is using <code>v2beta2</code> so output of both commands is the same.</p>
<pre><code>$ kubectl get hpa
NAME         REFERENCE               TARGETS   MINPODS   MAXPODS   REPLICAS   AGE
php-apache   Deployment/php-apache   0%/50%    1         10        1          76s
$ kubectl get hpa.v2beta2.autoscaling
NAME         REFERENCE               TARGETS   MINPODS   MAXPODS   REPLICAS   AGE
php-apache   Deployment/php-apache   0%/50%    1         10        1          84s
</code></pre>
<p>When execute command below, new file with <code>hpa</code> configuration will be created. This file is based on already created <code>HPA</code> from previous <code>kubectl autoscale</code> command.</p>
<pre><code>$ kubectl get hpa.v2beta2.autoscaling -o yaml &gt; hpa-v2.yaml
# If I would use command `kubectl get hpa hpa-apache &gt; hpa-v2.yaml` file would look the same
$ cat hpa-v2.yaml
apiVersion: v1
items:
- apiVersion: autoscaling/v2beta2
  kind: HorizontalPodAutoscaler
  metadata:
...
status:
    conditions:
    - lastTransitionTime: &quot;2020-12-11T10:44:43Z&quot;
      message: recent recommendations were higher than current one, applying the highest
        recent recommendation
      reason: ScaleDownStabilized
      status: &quot;True&quot;
      type: AbleToScale
      ...
    currentMetrics:
    - resource:
        current:
          averageUtilization: 0
          averageValue: 1m
</code></pre>
<h3>Conclusion</h3>
<p>The <code>status</code> describes the current state of the object, <strong>supplied and updated by the Kubernetes system and it's components.</strong></p>
<p>If you want to create resource based on <code>YAML</code> with <code>status</code>, you have to provide value in <code>status.conditions</code>, where <code>condition</code> require <code>array</code> value.</p>
<pre><code>status:
  conditions:
  - lastTransitionTime: &quot;2020-12-11T10:44:43Z&quot;
</code></pre>
<h3>Quick solution</h3>
<p>Just remove <code>status</code> section, from your YAML.</p>
<p>Let me know if you still encounter any issue after removing <code>status</code> section from YAML manifest.</p>
