kubernetes-training

Horizontal Autoscaling

apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: php-apache
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: php-apache
  minReplicas: 1
  maxReplicas: 10
  metrics:
  - type: Resource
    resource:
      name: cpu
      target:
        type: Utilization
        averageUtilization: 50
status:
  observedGeneration: 1
  lastScaleTime: <some-time>
  currentReplicas: 1
  desiredReplicas: 1
  currentMetrics:
  - type: Resource
    resource:
      name: cpu
      current:
        averageUtilization: 0
        averageValue: 0

Installation

  1. VPA Recommender :
    • continuously monitor resource usage from the kubernetes metrics API
    • collects historical and live usage data for pods
    • provides optimal CPU and memory values
  2. VPA Updater:
    • Detects pods running with sub-optimal resources and evicts them if an update is needed
    • The Updater needs information from the Recommender - VPA Admission Controller:
    • Interverne the pod creation process and uses the recommendations from the Recommender to apply the recommned resources

Declarative way

  1. About updatePolicy:
    • Off: only Recommender working
    • Initial: only applied if there’s new pod created
    • Recreate: Updater would jump in and evict pods
    • Auto: similar to recreate for now, until in-place resize of pod is available

      Scaling Cluster Infra

      - Horizontal: adding more nodes to the cluster
      - Vertical scaling: adding resources to the existing nodes in the cluster ## Scaling Workloads
      -  horiz: getting more pods
      -  vertical: adding resources to the existing pods ![](../../../img/Pasted%20image%2020250621160254.png)
      

Metrics

In-place resize of Pod Resources

```

References

VPA vs HPA