# HPA — Horizontal Pod Autoscaler
# docs/architecture: 02-k3s-microservices-spec.md §3.3, 05-gaps-and-best-practices.md §9
# Требует metrics-server в кластере: kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml

---
# PodDisruptionBudget — docs/architecture: 05-gaps-and-best-practices.md §9
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
  name: chat-svc-pdb
  namespace: gooseek
spec:
  minAvailable: 1
  selector:
    matchLabels:
      app: chat-svc
---
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
  name: search-svc-pdb
  namespace: gooseek
spec:
  minAvailable: 1
  selector:
    matchLabels:
      app: search-svc
---
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: chat-svc-hpa
  namespace: gooseek
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: chat-svc
  minReplicas: 2
  maxReplicas: 8
  metrics:
    - type: Resource
      resource:
        name: cpu
        target:
          type: Utilization
          averageUtilization: 70
    - type: Resource
      resource:
        name: memory
        target:
          type: Utilization
          averageUtilization: 80
---
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: search-svc-hpa
  namespace: gooseek
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: search-svc
  minReplicas: 2
  maxReplicas: 6
  metrics:
    - type: Resource
      resource:
        name: cpu
        target:
          type: Utilization
          averageUtilization: 70
---
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: discover-svc-hpa
  namespace: gooseek
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: discover-svc
  minReplicas: 1
  maxReplicas: 4
  metrics:
    - type: Resource
      resource:
        name: cpu
        target:
          type: Utilization
          averageUtilization: 70
---
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: finance-svc-hpa
  namespace: gooseek
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: finance-svc
  minReplicas: 1
  maxReplicas: 4
  metrics:
    - type: Resource
      resource:
        name: cpu
        target:
          type: Utilization
          averageUtilization: 70
---
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: travel-svc-hpa
  namespace: gooseek
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: travel-svc
  minReplicas: 1
  maxReplicas: 3
  metrics:
    - type: Resource
      resource:
        name: cpu
        target:
          type: Utilization
          averageUtilization: 70
---
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: memory-svc-hpa
  namespace: gooseek
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: memory-svc
  minReplicas: 1
  maxReplicas: 3
  metrics:
    - type: Resource
      resource:
        name: cpu
        target:
          type: Utilization
          averageUtilization: 70
