{{- range $svcKey, $svcVal := .Values.services }} {{- if $svcVal.autoscaling.enabled }} --- apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler metadata: name: {{ include "deploy.serviceFullname" (dict "root" $ "svcKey" $svcKey) }} labels: {{- include "deploy.labels" $ | nindent 4 }} app.kubernetes.io/component: {{ $svcKey | replace "_" "-" }} spec: scaleTargetRef: apiVersion: apps/v1 kind: Deployment name: {{ include "deploy.serviceFullname" (dict "root" $ "svcKey" $svcKey) }} minReplicas: {{ $svcVal.autoscaling.minReplicas }} maxReplicas: {{ $svcVal.autoscaling.maxReplicas }} metrics: - type: Resource resource: name: cpu target: type: Utilization averageUtilization: {{ $svcVal.autoscaling.targetCPUUtilization }} {{- end }} {{- end }}