DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Related

  • Containerization and Helm Templatization Best Practices for Microservices in Kubernetes
  • Messaging With Spring Boot and Azure Service Bus
  • Configuring Java Apps With Kubernetes ConfigMaps and Helm
  • Why Camel K?

Trending

  • Blue Skies Ahead: An AI Case Study on LLM Use for a Graph Theory Related Application
  • Distributed Consensus: Paxos vs. Raft and Modern Implementations
  • Mastering Fluent Bit: Installing and Configuring Fluent Bit on Kubernetes (Part 3)
  • AI Speaks for the World... But Whose Humanity Does It Learn From?
  1. DZone
  2. Software Design and Architecture
  3. Microservices
  4. Using Kong Ingress Controller with Spring Boot Services

Using Kong Ingress Controller with Spring Boot Services

Kong Ingress Controller allows users to include the power of Kong Gateway in existing Kubernetes implementations, all without much effort.

By 
John Vester user avatar
John Vester
DZone Core CORE ·
Feb. 21, 22 · Analysis
Likes (9)
Comment
Save
Tweet
Share
77.3K Views

Join the DZone community and get the full member experience.

Join For Free

Since 2003, I have used IntelliJ as my primary tool for developing applications and services. Nineteen years ago, I was impressed both by the small amount of RAM required to use the IDE and the refactoring abilities included with the 1.x release.

Developing in Java does not require me to use the IntelliJ IDEA product. Other developers on my current project use Eclipse or VS Code, but these tools are not required. When you can write your components, services, and applications with a simple text editor and terminal session, you’ll end up with the same compiled Java code.

So, why do I spend the money on IntelliJ every year? Because IntelliJ IDEA is designed to make things easier for developers—which equates to me being far more productive. For example, right-clicking on a class provides me with the option to relocate the class in a matter of seconds. When IntelliJ finds an opportunity to remove duplicate code, it creates the new shared code and correctly updates the locations that depend on the centralized method. IntelliJ is an excellent source of validation during code reviews too.

While this example might seem a little elementary, I wonder why more software engineers are not taking a similar approach when building their services.

Spring Boot Services and Kubernetes

Let’s assume your feature team has standardized the use of Spring Boot for API services. As a result of your team’s hard work and detailed design, your APIs are viewed as successful by public consumers. Your organization decides to use Kubernetes for these services.

For each Spring Boot service your team develops, this is what the high-level lifecycle looks like:

Spring Boot life cycle

A Spring Boot service is initialized, and custom code is added. That service is containerized into a Docker image, which is ultimately deployed into Kubernetes. 

By using Kubernetes, we get the following advantages:

  • A collection of Spring Boot-base Docker containers are placed into a “Pod” to act as a single application. This allows each Spring Boot service to be laser-focused on a given aspect of the resulting API.

  • One or more Pods can be grouped to form the resulting API service, which can be configured for discoverability, observability, horizontal scaling, and load balancing.

  • Rolling updates and canary deployments are utilized to lead to a stable consumer experience.

If you are interested in using Kubernetes with Spring Boot, check out the following URL:

Spring Boot Kubernetes

Based on the success of these popular APIs, let’s imagine that executive leadership would like to monetize the services to gain revenue from the most active consumers. A free tier will still be available, but limits on API usage will be introduced.

While the team could implement some custom logic at the Spring Boot level, this does not make sense. What we need is a centralized way to handle this new requirement.

Kong Ingress Controller to the Rescue

Last year, I started getting familiar with the Kong product suite as part of a long-term solution state for one of my clients. The scenario I described above mirrors situations I have encountered over the last five years: Centralizing common components is key for a successful microservices implementation.

If you want to read more about Kong, check out my publication from last May:

How I Stopped Coding Repetitive Service Components with Kong

For the use case mentioned above, we could handle the following components at the API gateway level:

  • Application registration (key-auth)

  • Rate limiting

  • Centralized logging

Since Kong Gateway is open source and a “leader” in the 2021 Gartner Magic Quadrant for Full Lifecycle API Management, Kong Gateway is a safe way to handle these common components. Knowing that Kong also provides an ingress controller for use within Kubernetes further validates the product decision.

You can find everything you need to get started with Kong Ingress Controller (KIC) on this GitHub page:

Kong Ingress Controller for Kubernetes

The illustration below shows the desired design for the two services:
Desired design for two services

Requests arrive at Kubernetes for API Service #1 or #2. The Kong Ingress Controller intercepts the requests and validates the API key provided. Based on that information, the controller determines if the consumer making the request has exceeded its request limit.

If the rate limit has not been exceeded, the request is forwarded to the appropriate service. However, if the rate limit is exceeded, then a 429 (Too Many Requests) HTTP response will be returned. In all cases, the logging module can be easily configured to track all incoming requests, including all the metadata being provided by the API consumer.

The Value of This Design

When we take a step back and look at the resulting architecture and design, we quickly see the benefits:

  • Spring Boot services are true microservices, each laser-focused on a single aspect of the API.

  • Docker allows the Spring Boot services to be self-contained and distributed at any point within the development lifecycle.

  • Kubernetes provides the ability to group those purpose-driven Docker images into Pods, which act as a single application. Those Pods are then grouped to surface as API services in our example.

  • Shared components—like application registration, rate limiting, and logging—exist in one centralized location within Kong Gateway.

  • Kong Ingress Controller becomes the middleware layer between Kong Gateway and Kubernetes to leverage all shared components. 

As a result of this model, feature team developers working on Spring Boot services only need to focus on the work provided by their product owner to improve or extend the service. These developers do not need to worry about API keys, rate limiting, or any other shared component managed elsewhere.

DevOps engineers supporting the Kubernetes implementation do not have to architect any custom design aspects to handle those shared components either. That’s because Kong Gateway is built to accommodate those needs and works well via the Kong Ingress Controller.

Conclusion

Since 2021, I have been trying to live by the following mission statement, which I feel can apply to any IT professional:

“Focus your time on delivering features/functionality which extends the value of your intellectual property. Leverage frameworks, products, and services for everything else.”

- J. Vester

At the start of this post, I talked about how I prefer IntelliJ IDEA over a text editor and terminal session. In reality, the core reason ties directly to my personal mission statement. The IDEA product allows me to focus on the right things; meanwhile, it handles the repetitive tasks related to writing original source code.

Similarly, Spring, Docker, Kubernetes, and Kong have provided solutions and frameworks to work toward the same mission. Every aspect noted above can be traced to a single source of truth for a given item. As a result, there is no duplication of services or functionality across the application landscape.

If you find yourself implementing the same process a second time,
it is certainly time to consider refactoring your design.

If your service tier falls into a similar modal as I’ve discussed here and you are not utilizing Kong Gateway or Kong Ingress Controller, they should certainly be on your shortlist of products to review when you are ready to refine your service design. 

Have a really great day!

Spring Framework Spring Boot microservice intellij Kubernetes

Opinions expressed by DZone contributors are their own.

Related

  • Containerization and Helm Templatization Best Practices for Microservices in Kubernetes
  • Messaging With Spring Boot and Azure Service Bus
  • Configuring Java Apps With Kubernetes ConfigMaps and Helm
  • Why Camel K?

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!