One of the conveniences offered by Red Hat 3scale API Management is simplified load balancing on API gateways. This article shows how to use a route on Red Hat OpenShift and 3scale API Management to load balance two API gateways installed on an OpenShift instance.
Figure 1 shows the architecture used in this article. This setup is only one of several ways to deploy API gateways. Examples of setups that are not discussed in this article include the following:
- Deploy API gateways inside your corporate network closer to your API, and place a load balancer (registered with 3scale API Management) in your demilitarized zone (DMZ) to handle load balancing, allowing high performance and avoiding a single point of failure. This architecture hides your API gateway from the outside world.
- Install the API gateways via Docker containers along with a load balancer that forwards requests to the Docker containers.
- Use Kubernetes scaling in OpenShift to run the desired number of API gateway pods and have OpenShift’s route feature take care of load balancing.
Prerequisites
Before starting the procedure in this article, you need to:
- Set up 3scale API Management on either SaaS or Red Hat OpenShift.
- Create a back-end product for the default staging and production API gateways.
- Set up a project (namespace) on OpenShift where you'll install the 3scale API gateway operator.
In my configuration, I used the SaaS version for 3scale API Management with an Echo API.
Set up the load balancer
The rest of this article sets up load balancing by taking you through the following steps:
- Install the 3scale APIcast gateway operator.
- Deploy one instance of a self-managed API gateway.
- Deploy a second instance of a self-managed API gateway.
- Configure an OpenShift route for the load balancer.
- Configure a 3scale API Management product using the load balancer route's URL.
- Promote your product API to use the load balancer route's URL in the staging API gateway.
- Test the API.
The following video also walks through the steps. As it shows, the whole process can take less than ten minutes.
Step 1: Install the 3scale APIcast gateway operator
From the OpenShift Operator console, install the Red Hat Integration - 3scale APIcast gateway operator (Figure 2).
Step 2: Deploy one instance of a self-managed API gateway
The "Deploying an APIcast gateway self-managed solution using the operator" section of the 3scale API Management documentation describes this step in detail.
Step 3: Deploy a second instance of a self-managed API gateway
The procedure is just like installing the first instance, except that you should use a different secret. In other words, the secret shown in the following configuration parameter must be different in the two instances:
spec:
adminPortalCredentialsRef:
name: SOME_SECRET_NAME
The second instance of a self-managed API gateway in the same project (namespace) involves a slight change in how the secret is created.
At this point, you should see the two API gateways in the console (Figure 3).
There are also two pods running, one for each API gateway (Figure 4).
Step 4: Configure an OpenShift route for the load balancer
There are many ways to configure a load balancer. This section uses the OpenShift route to split traffic between services.
Figure 5 shows the services for the API gateways you created previously.
3scalegateway
project.While creating the route, configure the two services with equal service weight (Figure 6).
Step 5: Configure a 3scale API Management product using the load balancer route's URL
Go to 3scale API Management → Products → <Product Name> → Integration → Settings. Copy the route URL from Step 4 and set the Staging Public Base URL and Production Public Base URL in 3scale API Management (Figure 7).
Step 6: Promote your product API to use the load balancer route's URL in the staging API gateway
Go to 3scale API Management → Products → <Product Name> → Integration → Configuration and promote the Staging APIcast configuration (Figure 8).
Step 7: Test the API
The APIcast Configuration page shown in Figure 8 contains a cURL command that you can use to test the service. Repeat it to fire up a few requests. You should then see requests sent to both API gateways in a round-robin fashion. Figure 9 highlights the parts of the output that show how both API gateways are responding.
Conclusion
3scale API Management supports multiple deployment strategies with API gateways. For more information, see the following links:
Last updated: September 19, 2023