{{- if .Values.autoscaling.enabled }} apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler metadata: name: {{ include "aitbc-blockchain-node.fullname" . }} labels: {{- include "aitbc-blockchain-node.labels" . | nindent 4 }} spec: scaleTargetRef: apiVersion: apps/v1 kind: Deployment name: {{ include "aitbc-blockchain-node.fullname" . }} minReplicas: {{ .Values.autoscaling.minReplicas }} maxReplicas: {{ .Values.autoscaling.maxReplicas }} metrics: {{- if .Values.autoscaling.targetCPUUtilizationPercentage }} - type: Resource resource: name: cpu target: type: Utilization averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }} {{- end }} {{- if .Values.autoscaling.targetMemoryUtilizationPercentage }} - type: Resource resource: name: memory target: type: Utilization averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }} {{- end }} # Custom metrics for blockchain-specific scaling - type: External external: metric: name: blockchain_transaction_queue_depth target: type: AverageValue averageValue: "100" - type: External external: metric: name: blockchain_pending_transactions target: type: AverageValue averageValue: "500" behavior: scaleDown: stabilizationWindowSeconds: 600 # Longer stabilization for blockchain policies: - type: Percent value: 5 periodSeconds: 60 scaleUp: stabilizationWindowSeconds: 60 policies: - type: Percent value: 50 periodSeconds: 60 - type: Pods value: 2 periodSeconds: 60 selectPolicy: Max {{- end }}