OfferTransform Your Career with Expert-Led IT Training. Flat discounts active!Explore Now
OnlineITGuru Logo
LIMITED PERIOD OFFER - FLAT 20% OFF
Cloud Computing & DevOps

Running Java Spring Boot Microservices on Red Hat OpenShift

Last updated on Nov 24, 2026

Copy Link:
Running Java Spring Boot Microservices on Red Hat OpenShift

The modern enterprise software landscape has experienced a paradigm shift. Monolithic applications that used to be the basis of corporate information technology have been gradually replaced by distributed microservices architectures. Among the frameworks that facilitate this transition, Java Spring Boot is the standard for enterprise backend development. It’s opinionated configuration, built-in server capabilities, and wide ecosystem allow engineering teams to quickly build production services. But building a microservice is only half the job. Running dozens or hundreds of interdependent services reliably at scale requires an equally capable orchestration platform. Red Hat OpenShift is an enterprise Kubernetes platform that links developer agility and operational governance.

Red Hat OpenShift lets you run Java Spring Boot microservices with the developer productivity and hybrid-cloud infrastructure. Upstream Kubernetes provides the core container orchestration primitives but OpenShift adds enterprise features on top like integrated continuous integration and delivery pipelines, hardened security defaults, automated build mechanisms, built-in monitoring and service mesh integration. For organisations that are committed to the Java ecosystem, understanding how Spring Boot works with OpenShift’s runtime environment is critical to achieving high availability, predictable performance, and cost efficiency.

Spring Boot and OpenShift: A Match Made in Heaven

Fundamentally, Spring Boot is aligned with the twelve-factor app principles. It advocates stateless processes, externalised configuration, fast startup and graceful shutdown as a means of disposability, and backing services treated as attached resources. Red Hat OpenShift is an opinionated platform layer on top of Red Hat Enterprise Linux and Kubernetes and follows those same principles.

When you deploy a microservice with Spring Boot on OpenShift, the platform handles the complexity of the underlying infrastructure. Developers don’t have to provision virtual machines, configure load balancers or deal with operating system patches. OpenShift does not schedule containers . Instead it schedules workloads . It manages the lifecycle of these containerised workloads . It schedules workloads across healthy nodes and maintains a desired number of replicas . Red Hat also offers commercial support for OpenJDK builds, and certified runtime tools, which provide long-term support and regular security updates for enterprise teams. It would be helpful for engineering groups to get trained in structured redhat openshift training since it provides a link between Java programming and clustering.

Approaches to Containerise Spring Boot

The Spring Boot microservice needs to be packaged into a container image to run on OpenShift. Traditionally, Java applications were packaged as monolithic fat archives containing compiled classes and all third party dependencies. This leads to inefficiencies in containerised environments: every small change in business logic leads to a complete archive rebuild and transfer over the network, increasing the registry storage and slowing down the deployment pipelines.

This is solved by layered image building, which separates dependencies, snapshot libraries, resources and compiled application classes into their own container layers. OpenShift caches the heavier, slower changing dependency layers. When a developer changes business logic, only the thin top layer containing compiled classes should be rebuilt and distributed.

OpenShift has several ways to build these container images:

  • Source-to-Image (S2I): S2I takes your application source code and directly injects it into a certified builder container image. The builder runs Maven or Gradle within the cluster, compiles the Java source, packages the artefact and produces a runnable runtime image, all without teams having to write or maintain Dockerfiles.

  • Buildpacks and Jib: Cloud Native Buildpacks and the Jib plugin build layered container images directly from Maven or Gradle lifecycles, for teams that want standardised, Dockerfile-less builds that integrate into external continuous integration pipelines.

  • Custom Containerfiles: Many organisations with strict compliance or custom runtime requirements will use multi-stage Containerfiles based on Red Hat Universal Base Images (UBI). The builder stage compiles the Java code using a full JDK image, and the final runtime stage copies only the compiled layers into a minimal runtime image, reducing the attack surface.

Externalising Configuration and Secrets Management

A core principle of cloud-native architecture is separation of configuration from compiled code. When a Spring Boot microservice is promoted from dev to staging and production, the same immutable container image should be running in all environments with only the external configuration changing.

Spring Boot loads properties from a number of sources like environment variables, command line arguments, Java system properties, and external property files. OpenShift has native support for this with ConfigMaps and Secrets.

ConfigMaps store non-sensitive configuration data like external API endpoints, feature flags, thread pool sizes, logging levels, etc. OpenShift projects ConfigMaps into pods either as environment variables or as mounted files. It’s a good fit for Spring Boot to mount a ConfigMap as a volume with application property files because it nicely keeps structured configuration keys.

Secrets are sensitive credentials including database passwords, OAuth client secrets, TLS certificates, and API keys. Secrets are stored in etcd and mounted into temporary, in-memory filesystems on worker nodes, which keeps sensitive data out of container image layers and off persistent disc. Teams can use the External Secrets Operator to sync external secret managers like HashiCorp Vault or cloud key management services into OpenShift Secrets for dynamic credential rotation and centralised auditing.

Spring Cloud Kubernetes also integrates Spring’s application context into the OpenShift API server, allowing a Spring Boot service to watch ConfigMaps and Secrets for changes and refresh beans at runtime without restarting the pod.

Memory Management in JVM and CPU Optimisation in Containers

One of the common failure modes when migrating Java workloads to OpenShift is incorrect resource allocation. The Java Virtual Machine historically did not respect Linux control group (cgroup) memory and CPU limits, instead inspecting host hardware, which could result in out-of-memory kills if heap allocations exceeded container quotas.

The current version of OpenJDK, including OpenJDK 17 and OpenJDK 21, is container aware, and thus cgroup memory and CPU restrictions can be detected by these JVMs. However, tuning of Java to enable successful run within OpenShift is not an easy task:

  • Memory footprint: Container memory restrictions do not mean JVM heap size Off-heap memory can consume hundreds of megabytes, including Metaspace for class metadata, thread stacks, direct byte buffers used by networking libraries, garbage collection structures, and native code cache. If the container memory limit is too close to the maximum heap size then the out-of-memory killer in the Linux kernel may kill the pod abruptly before a heap dump is written. Leaving about 25 to 30 percent of the container memory limit for off-heap overhead can help prevent unexpected kills.

  • Garbage Collector Selection: garbage collector choice impacts latency and throughput. Lightweight collectors with low overhead are often beneficial for small microservices with moderate heaps of less than two gigabytes. Defaulting to G1 is a common choice for larger, latency-sensitive services with high concurrency — it’s a balanced option. Lastly, low-pause collectors like ZGC minimise pause times on multi-gigabyte heaps such that garbage collection doesn’t cause cascading timeouts across calling services.

  • CPU Limits and Throttling: OpenShift distinguishes between CPU requests (capacity guarantyd at scheduling) and CPU limits (maximum a container can consume). Strict CPU limits can cause Completely Fair Scheduler throttling at startup or Just-In-Time compilation bursts, resulting in slow boot times and request latency spikes. Many platform teams set accurate CPU requests and set generous CPU limits or omit them for trusted internal workloads, so that startup and warm-up bursts can run without artificial throttling.

Making Startups Faster: AppCDS, CRaC and Native Images

Elasticity relies on the ability to spin up new pods rapidly as traffic spikes, and to cleanly replace unhealthy instances. Traditional Java services may be slower to start than lightweight runtimes because of class loading, bytecode verification, and reflection during Spring context initialisation.

Approaches that help reduce startup times include:

  • Application Class Data Sharing (AppCDS): At build time, AppCDS pre-processes the loaded class metadata into a shared archive. The JVM memory-maps archives at startup, skipping parsing and verification to speed up startup time and share memory among replicas.

  • Coordinated Restore at Checkpoint (CRaC) CRaC enables an application to start up and warm up its runtime, and checkpoint its state so that new instances can restore from the snapshot fast rather than cold starting.

  • Ahead-of-time compilation, available in Spring Boot through distributions such as Red Hat’s Mandrel as GraalVM Native Images, compiles a microservice down to a native standalone binary. Native binaries start in tens of milliseconds and consume less memory at boot, making them a good fit for scale-to-zero serverless workloads on OpenShift Serverless (Knative). However, they take longer to build and give up peak long-term runtime optimisation.

Graceful Lifecycle Management and Health Probes

Since pods on OpenShift are ephemeral, workloads move across nodes, scale up and down, and roll forward through new releases. OpenShift’s kubelet needs to be able to safely route traffic and recover stuck containers, which means Spring Boot microservices must expose accurate health signals.

Spring Boot Actuator includes dedicated health endpoints for lifecycle probes:

  • Startup Probes: Services that take a long time to initialise (like warming caches or running schema migrations) can use a startup probe to avoid liveness and readiness checks failing before initialisation is complete.

  • Liveness Probes: Liveness probes are tied to the liveness endpoint and tell OpenShift if the process is stuck or deadlocked and requires a container restart. Liveness probes should not look at the external system, such as database and third-party API end point. If there is an error in the database, that would cause a series of restarts of many apps as they failed their liveness checks.

  • Readiness Probes: These are linked with the readiness endpoint and indicate the pod's readiness to take any request. Readiness probes can check critical backing dependencies so that OpenShift removes an unready pod from Service load balancing until it recovers.

Graceful shutdown is equally important. During a rollout or scale-down, OpenShift sends a termination signal to a pod and updates cluster routing rules when it terminates a pod. Since routing updates take time to propagate across nodes, requests may still reach a terminating pod for a short time. Spring Boot graceful shutdown allows the embedded web server to stop accepting new connections and finish in-flight requests within a configured grace period before shutting down connection pools and exiting.

Traffic management, service discovery and network

In OpenShift, pods get ephemeral IP addresses on the cluster network (e.g., OVN-Kubernetes), so microservices should not hardcode or rely on direct pod IPs. Instead, OpenShift Services provide stable virtual IPs and internal DNS names that forward traffic to matching healthy pods. For instance, when a Spring Boot service calls another internal service by its DNS name, OpenShift handles discovery and load balancing in the platform layer, so you don’t need legacy client-side service registries like Netflix Eureka inside application code.

Ingress controllers expose external HTTP and HTTPS endpoints with OpenShift Routes and the Kubernetes Gateway API, including TLS termination, host routing, and path routing.

As the number of services grows, Red Hat OpenShift Service Mesh (built on Istio, Envoy, and Kiali) shifts cross-cutting traffic controls into sidecar proxies. It provides mutual TLS between services, network level retries, timeouts and circuit breaking and traffic splitting for canary or blue green releases.

Governance and Security for Enterprise

By default, OpenShift enforces strict Security Context Constraints and containers are run as a non-root user ID assigned from a namespace range, not as root. If a custom Containerfile writes files or directories that are only owned by root, the container might fail with permission errors at runtime. Images built for OpenShift should ensure that required directories are group-owned by root (GID 0) with appropriate group permissions to support running the application under any user ID assigned to it that is non-root.

End-to-end security across microservices also encompasses:

  • Identity and Access Management: Spring Boot services can be OAuth2 Resource Servers and can do stateless validation of JSON Web Tokens using OAuth 2.0 and OpenID Connect (for example, using Red Hat Build of Keycloak and Spring Security).

  • Network Policies: OpenShift NetworkPolicy resources restrict traffic between namespaces and pods, and determine which front-end services can access backend APIs or databases.

  • Supply Chain Security: Tools such as Red Hat Advanced Cluster Security scan container images and dependencies for known vulnerabilities and enforce policy checks before images deploy to production.

Logging, Metrics and Distributed Tracing Observability

To debug distributed requests across many Spring Boot services, you need consistent telemetry across the cluster:

  • Apps should log to standard output and standard error, not to local files that are lost when a pod restarts. Structured logs: OpenShift Cluster Logging collects these logs and enhances them with metadata from the cluster. The JSON structured logs provided by Logback or Log4j2 allow filtering for correlation ID, user ID, or status codes.

  • Metrics and Alerts: Spring Boot Actuator along with Micrometer collect various metrics like heap memory, garbage collection, connection pool, requests, latency, and business counters in Prometheus format. OpenShift collects these metrics.

  • Distributed traces: Micrometer Tracing and OpenTelemetry provide trace propagation over HTTP and messaging systems to the backends of traces so that end users can find out where slow calls are made.

CI/CD, GitOps and Data Persistence

The automation pipeline ensures repeatability and traceability of release. OpenShift Pipelines (Tekton) executes build, test, image creation, vulnerability scanning, and registry push steps in isolated pods. OpenShift GitOps (Argo CD) keeps declarative manifests, Helm charts or Kustomize overlays in Git as the source of truth and automatically reconciles cluster state when changes are committed.

Spring Boot services should be stateless when connecting to external databases or cluster-hosted databases (like Crunchy Postgres for Kubernetes) for stateful data and messaging. Keep connection pools (HikariCP) sized per pod so scaling out replicas does not run out of database connections. Event brokers (such as Red Hat Streams for Apache Kafka ) decouple producers from consumers for asynchronous workflows . Event-driven autoscaling with KEDA can scale consumer pods based on queue or topic backlog.

Production Takeaways

  • Keep services stateless and fault tolerant: design for retries with backoff, timeouts, idempotency, and graceful shutdown so pod evictions and network blips do not drop user traffic.

  • Size Resources With Real Load Tests Think about both JVM heap and off-heap memory and tune CPU requests and limits against realistic traffic rather than guess work.

  • Standardise templates and probes: Provide shared Spring Boot starters and deployment templates with separate startup, liveness, and readiness probes, structured logging, metrics and non-root container permissions.

  • Roll out gradually. Don't replace everything at once. Use rolling or canary deployment with roll-back conditions.

  • Spring Boot combined with Red Hat OpenShift helps an enterprise deploy a practical method for designing, deploying, and operating resilient microservices across hybrid and multi-cloud scenarios.

Conclusion

Java Spring Boot Microservices on Red Hat OpenShift combines two technologies that are built for modern enterprise software delivery. Spring Boot provides an expressive, convention-driven framework for building cloud-native services without the boilerplate overhead, while OpenShift offers an enterprise Kubernetes platform that automates deployment, scaling, security enforcement and day-two operations. Together they help organisations evolve from monolithic, inflexible systems to independently deployable, resilient services that can run consistently across hybrid and multi-cloud environments.

Getting that kind of resilience in production is not just a matter of wrapping up a Java application into a container and running it on a cluster. It requires a congruence of behaviour between the Java Virtual Machine and the way OpenShift manages container lifecycles. Teams need to embrace layered image builds, through Source-to-Image, Buildpacks, Jib, or even a minimal Universal Base Image multi-stage build, so updates are lightweight, fast and secure. Configuration and sensitive credentials must be strictly separate from the compiled code, using ConfigMaps, Secrets, external vault integrations, and dynamic configuration refreshes, so that identical container images flow cleanly from development to production.

Also important at scale are resource management and startup optimisation. Even with modern container-aware OpenJDK runtimes, engineers need to size memory limits to accommodate both heap and native off-heap overhead, and balance CPU requests and limits to avoid throttling during startup or bursts of JIT compilation. For scenarios that need fast elasticity or scale-to-zero execution, technologies such as Application Class Data Sharing, checkpoint restore, and GraalVM native images significantly reduce cold-start latency.

For operational stability in a dynamic cluster, accurate lifecycle signalling and network design are also a necessity. Separating startup, liveness and readiness probes avoids cascading restart storms from brief hiccups in dependencies and graceful shutdown lets active requests complete before the pods that are terminating will disappear. OpenShift Services, Routes, Network Policies and Service Mesh capabilities replace fragile client-side discovery tools with platform managed routing, mutual TLS encryption, progressive traffic shifting and strict zero-trust boundaries at the network layer. Also, the platform now supports non-root container execution, identity federation and automated vulnerability scanning, meaning security is baked in, not bolted on.

Long term success finally relies on observability, automation and disciplined engineering practices. Centralised structured logging, Prometheus metrics, and distributed tracing make complex microservice interactions actionable telemetry, while Tekton pipelines and Argo CD GitOps workflows keep releases repeatable and auditable. Combine stateless compute with suitably sized database connection pools and event driven messaging and you have systems that soak up spikes and recover cleanly in the face of failure.

People who desire to develop their skills in these automated procedures can greatly benefit from openshift training online.

In conclusion, it is important to learn how to use Spring Boot in Red Hat OpenShift, which will demand architecture discipline. Optimized Java for container, automated delivery pipeline, security, observability, and openshift online training enable you to have speed without losing the reliability and scalability.

Why Choose Us

Master Your Future with OnlineITGuru

We don't just provide courses; we build careers. From expert-led live training to dedicated placement support, discover why thousands of professionals trust us for their digital transformation journey.

200+

Partner Companies

$120K

Highest Package

75%

Average Hike

98%

Placement Rate

Reliable Career Partners

Google
Microsoft
Amazon
Meta
Netflix
Apple