Kubernetes - HPA

 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: 3

  template:

    metadata:

      labels:

        app: nginx-app

    spec:

      containers:

      - name: nginx-container

        image: nginx:1.7.9

        ports:

        - containerPort: 80

        resources:

           requests:

             cpu: 100m

  selector:

    matchLabels:

      app: nginx-app


2. Create HPA

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

Comments

Popular posts from this blog

Terraform

Scrum Master Interview help - Bootcamp

Kubernetes