Redhat OpenShift Horizontal Pod Autoscaler (HPA) feature what? why?& how?…all Answered

Aadithya Seetharam
10 min readAug 9, 2021

Introduction

Redhat OpenShift is a modern hybrid cloud container platform as a service (PaaS) built on Kubernetes and is open source. It supports on premise, hybrid and multi cloud deployment workloads. OpenShift is layered with security and automation on top of Kubernetes to become an Enterprise grade Container Orchestration Platform. OpenShift comes in multiple flavors of Origin, Online, Dedicated and Enterprise and brings specific advantages to Developers and Operations Engineers. It is gaining rapid adoption by enterprises as Redhat claims recently in its press release that more than 1000 global enterprises using OpenShift platform for hosting their business applications.

One of the key feature of OpenShift that is important for enterprises is Scalability. By design Applications running on OpenShift Container Platform can scale to thousands of instances across hundreds of nodes in seconds. In this article, we will explore in a simple way how to configure and test this feature of Horizontal Pod Autoscaler known as (HPA) on OpenShift platform. Horizontal Pod Autoscaler HPA is the configuration on OpenShift which automatically manages the replica count of any resource implementing the scale based on the metrics specified. CPU utilization and Memory utilization are supported metrics.

You can use a horizontal Pod Autoscaler HPA to specify how OpenShift Container Platform should automatically increase or decrease the scale of your deployment configuration, based on metrics collected from the underlying Pods.

Here is a brief list of Agenda items of discussion, also key take away from this read.

Topic List

Prerequisites

Needless to say, that you would need a running OpenShift cluster to demonstrate HPA. But not to worry, you can install OpenShift on any cloud infrastructure like aws, azure, gcp or on premise hardware. However what if you already have an instance running and don’t want to go through the pain of installation process in the interest of time and cut costs.

There is good news, Redhat is hosting a OpenShift Developer Sandbox environment to skip installation and configuration and be up and running in seconds, not minutes! This is a kind of SaaS environment provisioned and available for a month time to use for free. You don’t need to provide any credit card information, just register for a Redhat account to start using. We will use this setup for this illustration.

What Next? We need to deploy our Example Application or Service workload into this platform. It is recommended to use your development application workload to try HPA so that you can appreciate better the benefits that it can bring to your App, end customers, development and operations teams.

However, in the priority of time and ease, what if you can try a sample demo app in the same technology architecture of your production application. Absolutely! How?

Here we will use a Java Spring boot application with MySQL Database in the backend. This github repository has code that is container-ready implementation of the iconic Spring Petclinic application.

Sample Application GUI

Specifically, this code is useful with the OpenShift Source-to-Image (s2i) technology. The readme provides simple steps on how to deploy this sample spring-petclinic web app on OpenShift Sandbox environment.

Practically, there are many other ways of deployment supported on OpenShift platform like using Docker Containers and Jenkins Pipeline job route using helm charts and OpenShift CLI which is adopted by enterprises. However to keep it simple, we will use this sample web app and follow the steps.

Once build and deployment is completed, your web Application can be launched in your favorite browser using App URL similar to that shown above. This App URL is public and can be accessed by anyone from anywhere connected to internet until the OpenShift Sandbox is running for you. No login required.

Understanding HPA setup and Configuration

Now that we have got the preparation steps out of our way, let us understand what HPA feature is and get to the actual configuration performed on the sample spring-petclinic web application deployed on Redhat OpenShift Sandbox environment.

To create HPA in OpenShift, you have to mention the min and max values for pods to be run. In addition specify either CPU Utilization or Memory Utilization target values. Once HPA configuration is saved, OpenShift actively computes the ratio of the current metric utilization with the desired metric utilization, and scales Pods up or down automatically.

HPA Configuration can be done either from the OpenShift Web Console UI or using the OpenShift CLI using >oc autoscale command based on developers preference. On OpenShift Web Console, HPA can be performed using Form UI or using YAML.

(Note: You need to have appropriate role based access RBAC configured in OpenShift enabling this feature for your role.)

Here is a simple example of HPA configured on spring-petclinic Application Deployment. I have used Form UI on the OpenShift web console.

OpenShift Web Console GUI

Login to the OpenShift web console and follow these simple steps.

1. From left menu navigate to Topology

2. Select your Deployment, spring-petclinic in my case and go to Actions menu in right corner shown in above screenshot.

3. Under Actions menu >chose Add HorizontalPodAutoscaler or Edit HorizontalPodAutoscaler

4. Give a suitable name for HPA configuration to refer later, select min and max values for pods to scale, in this example I have configured only CPU Utilization = 20%

5. Click Save button

The equivalent YAML view of the HPA config is available and can be downloaded from OpenShift UI. Follow these steps. Some fields may not be represented in this form view. So, YAML view gives full control.

Steps:

1. From left menu navigate to Topology and select your Deployment as before

2. Select the Resources tab on the right pane as shown in screenshot.

3. Scroll down and click on HPA link

4. Switch to YAML tab on the HPA displayed and click on Download button in right corner

Important note: As a prerequisite to configure HPA, Resource Limit has to be set up during initial Application code deployment or later by editing. In my case CPU Request and Limit for the Pods are shown below. As understood this is required for the HPA scaling calculations.

In my example, I have used CPU Utilization for HPA. Similarly, Memory Utilization can be used. Combination of CPU and Memory utilization can be used even in HPA for tuning your Application to the best performance.

Testing

Ok, now that we have successfully configured HPA in OpenShift. No issues. Are we done? Not yet! What is left? Happy Testing!

HPA feature on OpenShift has just got out of beta release. It is important to Test the Configuration as applied to your Application before deployment into Production. How?

Simple, Load testing. The artificial load need to be created on the Application deployed using virtual users in action. This can be achieved by any industry standard Load testing and Benchmarking tool for web apps already on premise or consumed from cloud. Like for example, MicroFocus (formerly HP Software) Loadrunner Cloud or Apache JMeter or other tool you prefer.

To keep it simple yet effective, in my example I am using a light weight open source command line free tool for testing, Apache Bench to generate http traffic load of concurrent user requests hitting my spring-pet-clinic application.

Apache Bench tool is included with the Apache web server software. Just verify using simple command >ab –V

You should see something like this returned on terminal. If not, no worries. Apache bench can be installed easy and quickly on any OS. I am keeping installation out of scope for this article.

Test Cases: Now let me approach testing systematically by thinking of test cases and test scenarios for my spring-petclinic app. Here is a simple test case and test steps

Step1: Launch my application and get to Landing page. For example

App URL = http://spring-petclinic-aadithyaks-dev.apps.sandbox-m2.ll9k.p1.OpenShiftapps.com/

spring pet-clinic sample web application GUI-Landing Page

Step2: click on Find Owners lens top menu.

Step3: On next page, click Find Owner button with blank Last name.

This will initiate a full search and bring up all my records, pet owner names and demographics data from the database in return. Refer screenshot below.

This is the URL =http://spring-petclinic-aadithyaks-dev.apps.sandbox-m2.ll9k.p1.OpenShiftapps.com/owners?lastName=

spring pet-clinic sample web application GUI-Pets Search Page

Now I can issue this command from my linux machine to perform the load test.

Let me explain this. I am hitting my target page on the App using the URL just mentioned above using Apache bench tool.

-n =10000 Total of Ten thousand requests

-c = 100 One hundred concurrent requests at a time

My Load test run is completed! This is why I said Apache bench is simple tool. My Load test run results basic statistics is returned on the terminal. I will let you review it yourself in the screenshot below. (We will discuss details and analyze this in the last part of this article).

Apache Bench tool -Performance Test Run Results

You can continue and run more test scenarios to measure performance of key business transactions that are important to your customers.

HPA in Action

This was the moment when HPA was triggered in action when my load test was run. In the Background, my application did automatically scale to maximum of 3 pods from initial state of 1. The beauty of OpenShift is that I can see that scaling moment on OpenShift web UI as it happens.

Refer snapshot below. So, ultimately HPA is working as expected. Test passed!

HPA in action — Visual on OpenShift Topology view

If I don’t run further load tests, it was a spike. Now OpenShift will monitor the load for a threshold time and then start scaling back to 1 pod and get to normal state automatically.

On the Monitoring Dashboard view of OpenShift web console, this action is reflected and the CPU usage of 03 Application pods and 1 Database pod can be seen below. Prometheus open source monitoring software is used by OpenShift. Any production systems metrics, reporting and analytics is possible.

OpenShift Monitoring Dashboard view -Prometheus based
CPU usage of Pods at 2 instances — HPA triggered

Benefits measured

Now we come to the last part of this article. Keeping technical stuff of HPA aside for a moment, let us analyze and understand from the layman perspective. Why HPA? What measurable business benefits, competitive advantages HPA brings to enterprises, digital end user experience who consume this feature at real time. Objectively I assume you are convinced on the theme of scalability if you have chosen to read this article and have come so far reading this.

So, I am not repeating the fundamentals of Scalable and Elastic nature of modern Infrastructure. However what is still mystery for you may be on benefits of “how much”? Let me step back and review Benchmark statistics returned by Apache Bench tool during load test run of HPA.

Benchmark statistics critical metrics are compared in the table below.

1. What if without HPA?

2. During HPA in action, (Transient state) and

3. HPA fully Scaled High Performance State

Apache Benchmarking tool-App Response Statistics comparison without/ with HPA

App Performance Comparison without/ with HPA

The observations in the table are self-explanatory. Even when the system is under peak load, end users experience a fantastic application performance for example: Response time of 2.5 milliseconds per request. That is almost instantaneous!

While all this happens, your infrastructure costs is optimized to the best. Is this not the much noted benefit of the cloud? Yes of course. But here the OpenShift HPA solution is cloud agnostic. As we discussed in the beginning, OpenShift can be hosted on premise, multi cloud or a hybrid infrastructure. Nothing is left behind. The advantage is you are truly master and in full control of the game here!

The security challenges that come with cloud can be avoided and some of the serious Fintech companies can be using this approach.

OpenShift platform supports every modern popular digital architecture like Python, NodeJS and many others flavors similar to Java Spring boot we just saw. So, every business in the world has a winning use case in OpenShift!

Summary & Conclusion

So far in this article, we have discussed what Redhat OpenShift PaaS is, How to configure Horizontal Pod Autoscaler HPA in OpenShift, test the configuration, appreciate the benefits and competitive advantages of this solution. Thanks for your time!

Additionally you can watch a 15 minutes video on youtube.com I have recorded HPA in action demonstrated exactly covering the content in this article just read. Good luck!

************************* ~ THE END~ ************************

--

--