Document

SUBSCRIBE TO GET FULL ACCESS TO THE E-BOOKS FOR FREE 🎁SUBSCRIBE NOW

Professional Dropdown with Icon

SUBSCRIBE NOW TO GET FREE ACCESS TO EBOOKS

Horizontal Pod AutoScaling

Horizontal Pod Autoscaler

The Horizontal Pod Autoscaler automatically scales the number of Pods in a replication controller, deployment, replica set or stateful set based on observed CPU utilization (or, with custom metrics support, on some other application-provided metrics). Note that Horizontal Pod Autoscaling does not apply to objects that can’t be scaled, for example, DaemonSets.

1. Create a Deployment

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deploy
  labels:
    app: nginx-app
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: nginx-app
    spec:
      containers:
      – name: nginx-container
        image: nginx:1.7.9
resources:
requests: memory: “64Mi” cpu: “250m” limits: memory: “128Mi” cpu: “500m”
        ports:
        – containerPort: 80
  selector:
    matchLabels:
      app: nginx-app


apiVersion: v1
kind: Service
metadata:
  name: my-service
  labels:
    app: nginx-app
spec:
  selector:
    app: nginx-app
  type: NodePort
  ports:
  – nodePort: 31111
    port: 80
    targetPort: 80
2. Create HPA


kubectl autoscale deployment nginx-deploy –cpu-percent=20 –min=1 –max=5

OR

 you can  create below yaml file

apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
     name: nginx
spec:
    scaleTargetRef:
      apiVersion: apps/v1
      kind: Deployment
      name: nginx-deploy
    minReplicas: 1
    maxReplicas: 10
    targetCPUUtilizationPercentage: 10

3. Pods will be autoscaled as per cpu utilization
4. kubectl get hpa
5. while true; do wget -q -O- http://localhost:31111; done
Share your love

Leave a Reply

Your email address will not be published. Required fields are marked *