Friends, I am trying to implement a HPA following the hpa tutorial of k8s and I am having the following error:
ValidationError(HorizontalPodAutoscaler.status): missing required field "conditions" in io.k8s.api.autoscaling.v2beta2.HorizontalPodAutoscalerStatus.
I couldn't find anything about this field "conditions". Does someone have an idea what I may be doing wrong? Here its the YAML of my HPA:
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: <some-time>
currentReplicas: 2
desiredReplicas: 2
currentMetrics:
- type: Resource
resource:
name: cpu
current:
averageValue: 0
And here the manifest of my deployment:
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 "/configmap.yaml") . | 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 }}
Background
Not sure, why you want to create
HPA
withstatus
section. If you would remove this section it will createHPA
without any issue.In documentation Understanding Kubernetes Objects - Object Spec and Status you can find information:
Your situation is partially described in Appendix: Horizontal Pod Autoscaler Status Conditions
Example from my GKE test cluster
As I mention before, if you will remove
status
section, you will be able to createHPA
.Following
HPA
documentation, I've createdPHP Deployment
.When you executed command
kubectl autoscale
you have createdHPA
for deploymentphp-apache
Now you are able to see
hpa
resource usingkubectl get hpa
orkubectl get hpa.v2beta2.autoscaling
. Output is the same.First command will show all
HPA
objects with anyapiVersion
(v2beta2
,v2beta1
, etc), second command will showHPA
only withapiVersion: hpa.v2beta2.autoscaling
. My cluster as default is usingv2beta2
so output of both commands is the same.When execute command below, new file with
hpa
configuration will be created. This file is based on already createdHPA
from previouskubectl autoscale
command.Conclusion
The
status
describes the current state of the object, supplied and updated by the Kubernetes system and it's components.If you want to create resource based on
YAML
withstatus
, you have to provide value instatus.conditions
, wherecondition
requirearray
value.Quick solution
Just remove
status
section, from your YAML.Let me know if you still encounter any issue after removing
status
section from YAML manifest.