When I am applying helm deployment yaml file in below format (with range) deployment works fine but it applies HorizontalPodAutoscaler only for one of the deployment.
{{- range .Values.services }}
{{ if .enabled }}
apiVersion: apps/v1
kind: Deployment
{{- range .Values.services }}
Metadata:
.
.
.
spec:
.
.
.
apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
name: mlservice-{{.name}}-v{{.version}}
namespace: {{$.Values.namespace }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: mlservice-{{.name}}-v{{.version}}
minReplicas: {{ $.Values.minReplicas }}
maxReplicas: {{ $.Values.maxReplicas }}
targetCPUUtilizationPercentage: {{ $.Values.targetCPUUtilizationPercentage }}
{{ end }}
{{- end }}
github action logs I see like :
client.go:239: [debug] Created a new HorizontalPodAutoscaler called "service-v1" in namespace
but I don't see anything like Created a new HorizontalPodAutoscaler called "service-v2"
No clue why , I am using aws EKS and complete workload works fine. except doing "kubectl get hpa" returns only one service. Before I had only one service and auto scaling and all workload used to work fine.
Fixed this HPA issue : need to add '---' at end of HorizontalPodAutoscaler section in deployment.yaml this is required because it is inside loop and k8s needs to understand that iteration is over.