Skip to main content

CentOS Stream 10: Horizontal Pod Autoscaler

Configure Horizontal Pod Autoscaler (HPA) to automatically scale applications based on metrics on CentOS Stream 10.

May 24, 2026 8 min read
centoscentos-stream-10kubernetesk8scluster

Configure Horizontal Pod Autoscaler to set auto scaling to Pods.

This example is based on the environment like follows.

+----------------------+   +----------------------+

|  [ ctrl.srv.world ]  |   |   [ dlp.srv.world ]  |

|     Manager Node     |   |     Control Plane    |

+-----------+----------+   +-----------+----------+

        eth0|10.0.0.25             eth0|10.0.0.30

            |                          |

------------+--------------------------+-----------

            |                          |

        eth0|10.0.0.51             eth0|10.0.0.52

+-----------+----------+   +-----------+----------+

| [ node01.srv.world ] |   | [ node02.srv.world ] |

|     Worker Node#1    |   |     Worker Node#2    |

+----------------------+   +----------------------+

Step 1

Deploy Metrics Server.

Step 2

This is an example of Deployment to set Horizontal Pod Autoscaler.

[cent@ctrl ~]$ vi my-nginx.yml

apiVersion: apps/v1

kind: Deployment

metadata:

  labels:

    run: my-nginx

  name: my-nginx

spec:

  replicas: 1

  selector:

    matchLabels:

      run: my-nginx

  template:

    metadata:

      labels:

        run: my-nginx

    spec:

      containers:

      - image: nginx

        name: my-nginx

        resources:

          <span class="color2"># requests : set minimum required resources when creating pods</span>

          requests:

            <span class="color2"># 250m : 0.25 CPU</span>

            cpu: 250m

            memory: 64Mi

          <span class="color2"># set maximum resorces</span>

          limits:

            cpu: 500m

            memory: 128Mi

[cent@ctrl ~]$ vi hpa.yml

apiVersion: autoscaling/v2

kind: HorizontalPodAutoscaler

metadata:

  name: my-nginx-hpa

  namespace: default

spec:

  scaleTargetRef:

    apiVersion: apps/v1

    kind: Deployment

    <span class="color2"># target Deployment name</span>

    name: my-nginx

  minReplicas: 1

  <span class="color2"># maximum number of replicas</span>

  maxReplicas: 4

  metrics:

  - type: Resource

    resource:

      <span class="color2"># scale if target CPU utilization is over 20%</span>

      name: cpu

      target:

        type: Utilization

        averageUtilization: 20

[cent@ctrl ~]$ kubectl apply -f my-nginx.yml -f hpa.yml

deployment.apps/my-nginx created

horizontalpodautoscaler.autoscaling/my-nginx-hpa created

[cent@ctrl ~]$ kubectl get pods

NAME                        READY   STATUS    RESTARTS   AGE

my-nginx-5496ddfbbb-z2zbl   1/1     Running   0          8s

[cent@ctrl ~]$ kubectl top pod

NAME                        CPU(cores)   MEMORY(bytes)

my-nginx-5496ddfbbb-z2zbl   0m           7Mi

[cent@ctrl ~]$ kubectl get hpa

NAME           REFERENCE             TARGETS       MINPODS   MAXPODS   REPLICAS   AGE

my-nginx-hpa   Deployment/my-nginx   cpu: 0%/20%   1         4         1          70s

run some processes to put stress in a pod manually and see current state of pods again

[cent@ctrl ~]$ kubectl get hpa

NAME           REFERENCE             TARGETS         MINPODS   MAXPODS   REPLICAS   AGE

my-nginx-hpa   Deployment/my-nginx   cpu: 200%/20%   1         4         4          2m32s

pods have been scaled for settings

[cent@ctrl ~]$ kubectl get pods

NAME                        READY   STATUS    RESTARTS   AGE

my-nginx-5496ddfbbb-886zt   1/1     Running   0          31s

my-nginx-5496ddfbbb-gt489   1/1     Running   0          31s

my-nginx-5496ddfbbb-p7zcn   1/1     Running   0          31s

my-nginx-5496ddfbbb-z2zbl   1/1     Running   0          2m46s

[cent@ctrl ~]$ kubectl top pod

NAME                        CPU(cores)   MEMORY(bytes)

my-nginx-5496ddfbbb-886zt   0m           7Mi

my-nginx-5496ddfbbb-gt489   0m           7Mi

my-nginx-5496ddfbbb-p7zcn   0m           7Mi

my-nginx-5496ddfbbb-z2zbl   0m           8Mi