apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
  name: kubia
  namespace: chp15-set1512
spec:
  behavior:
    scaleUp:
      stabilizationWindowSeconds: 0 # default
      policies:
      - type: Percent
        value: 10 # default is 100
        periodSeconds: 15 # default is 15
    scaleDown: 
      stabilizationWindowSeconds: 10 # default is 300
      policies:
      - type: Percent
        value: 10 # default
        periodSeconds: 15 # default
  maxReplicas: 3 # this overrides spec.replicas setting in deployment object
  minReplicas: 1
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: kubia-deploy
  metrics:
  - type: Resource
    resource:
      name: cpu # cpu percentage of resource specified on pod containers
      target:
        type: Utilization # resource metric in terms of percentage
        averageUtilization: 5 # When pod consumes 5% of CPU, create new pod

# We are scaling for an average CPU memory use


# 1. Tell the Autoscaler to adjust the number of pods so they each utilize 30% of requested CPU.
# 2. Defaults: https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/
# 3. Overall reference: https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale-walkthrough/
# 4. Starting from v1.18 the v2beta2 API allows scaling behavior to be configured through the HPA behavior field.
# 5. Scaling policies: https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/#scaling-policies
