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
HPAwithstatussection. If you would remove this section it will createHPAwithout 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
statussection, you will be able to createHPA.Following
HPAdocumentation, I've createdPHP Deployment.When you executed command
kubectl autoscaleyou have createdHPAfor deploymentphp-apacheNow you are able to see
hparesource usingkubectl get hpaorkubectl get hpa.v2beta2.autoscaling. Output is the same.First command will show all
HPAobjects with anyapiVersion(v2beta2,v2beta1, etc), second command will showHPAonly withapiVersion: hpa.v2beta2.autoscaling. My cluster as default is usingv2beta2so output of both commands is the same.When execute command below, new file with
hpaconfiguration will be created. This file is based on already createdHPAfrom previouskubectl autoscalecommand.Conclusion
The
statusdescribes 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
YAMLwithstatus, you have to provide value instatus.conditions, whereconditionrequirearrayvalue.Quick solution
Just remove
statussection, from your YAML.Let me know if you still encounter any issue after removing
statussection from YAML manifest.