# =============================================================================
# MonkAPI - Horizontal Pod Autoscaler
# =============================================================================
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: monkapi-hpa
  namespace: monkapi
  labels:
    app: monkapi
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: monkapi
  minReplicas: 3
  maxReplicas: 20
  metrics:
    # CPU-based scaling
    - type: Resource
      resource:
        name: cpu
        target:
          type: Utilization
          averageUtilization: 70
    # Memory-based scaling
    - type: Resource
      resource:
        name: memory
        target:
          type: Utilization
          averageUtilization: 80
  behavior:
    scaleUp:
      stabilizationWindowSeconds: 60
      policies:
        - type: Pods
          value: 4
          periodSeconds: 60
        - type: Percent
          value: 100
          periodSeconds: 60
      selectPolicy: Max
    scaleDown:
      stabilizationWindowSeconds: 300
      policies:
        - type: Pods
          value: 1
          periodSeconds: 120
      selectPolicy: Min

---
# =============================================================================
# Pod Disruption Budget
# =============================================================================
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
  name: monkapi-pdb
  namespace: monkapi
  labels:
    app: monkapi
spec:
  minAvailable: 2
  selector:
    matchLabels:
      app: monkapi
