Skip to main content
Redhat Developers  Logo
  • Products

    Featured

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat OpenShift AI
      Red Hat OpenShift AI
    • Red Hat Enterprise Linux AI
      Linux icon inside of a brain
    • Image mode for Red Hat Enterprise Linux
      RHEL image mode
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • Red Hat Developer Hub
      Developer Hub
    • View All Red Hat Products
    • Linux

      • Red Hat Enterprise Linux
      • Image mode for Red Hat Enterprise Linux
      • Red Hat Universal Base Images (UBI)
    • Java runtimes & frameworks

      • JBoss Enterprise Application Platform
      • Red Hat build of OpenJDK
    • Kubernetes

      • Red Hat OpenShift
      • Microsoft Azure Red Hat OpenShift
      • Red Hat OpenShift Virtualization
      • Red Hat OpenShift Lightspeed
    • Integration & App Connectivity

      • Red Hat Build of Apache Camel
      • Red Hat Service Interconnect
      • Red Hat Connectivity Link
    • AI/ML

      • Red Hat OpenShift AI
      • Red Hat Enterprise Linux AI
    • Automation

      • Red Hat Ansible Automation Platform
      • Red Hat Ansible Lightspeed
    • Developer tools

      • Red Hat Trusted Software Supply Chain
      • Podman Desktop
      • Red Hat OpenShift Dev Spaces
    • Developer Sandbox

      Developer Sandbox
      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Secure Development & Architectures

      • Security
      • Secure coding
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
      • View All Technologies
    • Start exploring in the Developer Sandbox for free

      sandbox graphic
      Try Red Hat's products and technologies without setup or configuration.
    • Try at no cost
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • Java
      Java icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • API Catalog
    • Product Documentation
    • Legacy Documentation
    • Red Hat Learning

      Learning image
      Boost your technical skills to expert-level with the help of interactive lessons offered by various Red Hat Learning programs.
    • Explore Red Hat Learning
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

Autoscaling Red Hat Fuse applications with OpenShift

 

November 11, 2019
Chandra Shekhar Pandey
Related topics:
KubernetesSpring Boot
Related products:
Red Hat FuseRed Hat OpenShift

Share:

    In this article, we demonstrate Red Hat OpenShift's horizontal autoscaling feature with Red Hat Fuse applications. The result is a Spring Boot-based application that uses the Apache Camel component twitter-search that searches Twitter for tweets based on specific keywords. If traffic or the number of tweets increases, and this application cannot serve all requests, then the application autoscales itself by increasing the number of pods. The ability to serve all requests is monitored by tracking this application's CPU utilization on a particular pod. Also, as soon as traffic or CPU utilization is back to normal, the number of pods is reduced to the minimum configured value.

    There are two types of scaling: horizontal and vertical. Horizontal scaling is where the number of application instances or containers is increased. Vertical scaling is where system resources like CPU and memory are increased at the running application's or container's runtime. Horizontal scaling can be used for stateless applications, whereas vertical scaling is more suitable for stateful applications.

    Autoscaling is useful when applications are deployed in a cloud environment from any of the cloud vendors, where users have to pay for resources like CPU and memory. It may happen that traffic is heavier on weekends or particular weekdays, or even for a few hours on a specific day, so having a static setup might cost more and not fully utilize system resources. Having a dynamic environment where applications can scale themselves reduces overall cost.

    Note: For demonstration and proof-of-concept purposes, we are using Red Hat OpenShift 3.11 and Red Hat Fuse 7.4. Our aim is to display one of the OpenShift features (autoscaling), which is not available with traditional applications.

    Prerequisites

    Follow the instructions in the official Red Hat Fuse documentation to set up Red Hat Fuse 7.4 on OpenShift. OpenShift should automatically increase or decrease the scale of a replication controller, or deployment configuration, based on metrics collected from the pods. To collect these CPU and memory metrics from your pods, the metrics server has to be installed on your OpenShift server to capture CPU and memory metrics from pods. Check out the Pod Autoscaling guide for how to do this using Ansible.

    Create the application

    The code for this demonstration is available in my personal GitHub repository. Start by deploying this code to your OpenShift environment using the source-to-image (S2I) approach. First, select an application template from the OpenShift catalog. I selected Red Hat Fuse 7.4 Camel with Spring Boot, shown in Figure 1:

    The OpenShift catalog with an application template selected.

    Next, point the Git Repository URL to the GitHub repository's link. In our case, this camel-twitter-shift component searches tweets with the keywords imcdemo, RED_HAT_APAC, or RedHatTelco. This component will poll Twitter for two minutes, which is configured with the delay property and other properties that are user-specific.

    Now, point Git Reference to the branch containing the actual code. I set it to master, as you can see in Figure 2:

    Configuring the selected application template.

    To get your consumerKey, consumerSecret, accessToken, and accessTokenSecret, register for the Standard API (which is free, though there are limitations) through the Twitter developer platform. After consuming tweets for keywords, we then log them to the console with the Camel log component:

    <route id="twitter-search">
    <from id="route-search" uri="twitter-search://imcdemo OR RED_HAT_APAC OR RedHatTelco?type=polling&amp;delay=120000&amp;consumerKey=dF&amp;consumerSecret=Ay&amp;accessToken=7d&amp;accessTokenSecret=9K"/>
    <log id="route-log-search" message=">>> ${body}"/>
    </route>
    

    Set up horizontal autoscaling

    We can set autoscaling for the fuse74-camel-twitter deployment config with the following command. Note that cpu-percent is set to 10, which means that as soon as CPU utilization is more than 10% for the pod, the application will scale new pods, with the maximum number of pods being five:

    cpandey@cpandey camel-twitter-shift]$ oc autoscale dc/fuse74-camel-twitter --min 1 --max 5 --cpu-percent=10 horizontalpodautoscaler.autoscaling/fuse74-camel-twitter autoscaled 
    

    In Figure 3, the first red arrow points to the minimum and the maximum number of configured pods. The second arrow is the route with which we can access a pod from an external HTTP-based service or application. This setup is just to send HTTP traffic to the pod:

    Setting up autoscaling.
    POD-Image3

    Next, let's get information from the horizontal pod autoscaler (HPA):

    [cpandey@cpandey camel-twitter-shift]$ oc get hpa
    
    NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE
    
    fuse74-camel-twitter DeploymentConfig/fuse74-camel-twitter 10% 1 5 0 4s

    We can check OpenShift's GUI for the number of pods, as shown in Figure 4:

    The number of pods as shown in the OpenShift GUI.

    However, I find the command line to be more informative, as at runtime it provides CPU utilization and the number of active pods:

    [cpandey@cpandey camel-twitter-shift]$ watch 'oc describe hpa fuse74-camel-twitter'

    You can find more on this command in the OpenShift Pod Autoscaling docs.

    Simulate traffic to the application

    To simulate traffic so that we can demonstrate the OpenShift autoscaler feature, there is another route that accepts HTTP requests. This route uses Camel's undertow component, which starts the undertow web container. This container listens on port 9956:

    <route id="load-route">
        <from id="_from1" uri="undertow:http://0.0.0.0:9956/undertowTest"/>
        <convertBodyTo id="_convertBodyTo1" type="java.lang.String"/>
        <log id="_log1" loggingLevel="INFO" message="\n REQUEST RECEIVED :\n Headers: ${headers}\n Body: ${body} \n"/>
        <setBody id="_setBody1">
        <constant>hello all</constant>
        </setBody>
    </route>

    With the loop.sh script, we can send requests to this route in bulk. One can run this script in three or four terminals so that there is concurrent traffic, which would increase CPU utilization quickly. This script is part of the project as well:

    #!/bin/bash
    for ((;;))
    do
    curl http://demo-service-imc-demo.apps.csppnq.lab.pnq2.cee.redhat.com/undertowTest
    done

    See Figure 5 for the results in the GUI, and Figure 6 for the command-line version:

    Loop script results in the GUI.
    AutoScaling_to_3_pods-Image5
    Loop script results on the command line.
    AutoScaling_to_3_pods-Image6

    If we stop these scripts from executing, then CPU utilization returns to normal:

    After stopping the loop script.
    AutoScaling_to_1_pods-Image7

    Disable the horizontal pod autoscaler

    We can disable autoscaling with the following command:

    [cpandey@cpandey camel-twitter-shift]$ oc delete hpa fuse74-camel-twitter
    
    horizontalpodautoscaler.autoscaling "fuse74-camel-twitter" deleted

    That's it. I hope this demonstration helps you set up and use OpenShift's autoscaler feature with Red Hat Fuse applications, or any other application as well.

    Last updated: October 8, 2024

    Recent Posts

    • Container starting and termination order in a pod

    • More Essential AI tutorials for Node.js Developers

    • How to run a fraud detection AI model on RHEL CVMs

    • How we use software provenance at Red Hat

    • Alternatives to creating bootc images from scratch

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Products

    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform

    Build

    • Developer Sandbox
    • Developer Tools
    • Interactive Tutorials
    • API Catalog

    Quicklinks

    • Learning Resources
    • E-books
    • Cheat Sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site Status Dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Report a website issue