Author : MD TAREQ HASSAN | Updated : 2021/07/05

Types

Horizontal Pod Auto Scalling

Resource requests and limits for pod container

resources:
  requests:
    cpu: 250m
    memory: "64Mi"
  limits:
    cpu: 500m
    memory: "128Mi"

CPU usage examples

apiVersion: apps/v1
kind: Deployment
metadata:
  name: foo-api
  namespace: demo
spec:
#  replicas: 3
  selector:
    matchLabels:
      app: foo-api
  template:
    metadata:
      labels:
        app: foo-api
    spec:
      containers:
      - name: foo-api
        image: myacr.azurecr.io/foo:20210705
        ports:
        - name: http
          containerPort: 80
          protocol: TCP
        resources:
          limits:
            cpu: 250m
          requests:
            cpu: 500m

Auto scaller (examples are below)

foo-hpa.yaml

apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
  name: abc-hpa
spec:
  maxReplicas: 10 # define max replica count
  minReplicas: 3  # define min replica count
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: abc-deployment
  targetCPUUtilizationPercentage: 50 # target CPU utilization

---

apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
  name: xyz-hpa
spec:
  maxReplicas: 10 # define max replica count
  minReplicas: 3  # define min replica count
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: xyz-deployment
  targetCPUUtilizationPercentage: 50 # target CPU utilization

Kubectl command

kubectl autoscale deployment azure-vote-front --cpu-percent=50 --min=3 --max=10

Cluster Auto Scaller