NZroot.dev

Introduction to Kubernetes Scaling

Dec 1, 2024

Learn how Kubernetes handles scaling of applications automatically. We dive into HPA, VPA, and cluster autoscaler.

Kubernetes is the de facto standard for container orchestration. One of its most powerful features is the ability to scale workloads automatically.

Horizontal Pod Autoscaler (HPA)

The HPA automatically scales the number of Pods in a replication controller, deployment, replica set, or stateful set based on observed CPU utilization.

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

This configuration ensures that your application always has enough resources to handle the current load, without wasting money on idle infrastructure.

Why Scale?

  1. Cost Efficiency: Pay only for what you use.
  2. Reliability: Handle traffic spikes without crashing.
  3. Performance: Maintain low latency for users.