Featured image for 3scale API Management.

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.
In the architecture used for this article, OpenShift contains a load balancer that splits requests between two services provided by two API gateways.
Figure 1: Load balancer between the 3scale API Management and the API gateways.

Prerequisites

Before starting the procedure in this article, you need to:

  1. Set up 3scale API Management on either SaaS or Red Hat OpenShift.
  2. Create a back-end product for the default staging and production API gateways.
  3. 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:

  1. Install the 3scale APIcast gateway operator.
  2. Deploy one instance of a self-managed API gateway.
  3. Deploy a second instance of a self-managed API gateway.
  4. Configure an OpenShift route for the load balancer.
  5. Configure a 3scale API Management product using the load balancer route's URL.
  6. Promote your product API to use the load balancer route's URL in the staging API gateway.
  7. 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).

The 3scale APIcast gateway Operator is available in the OpenShift console.
Figure 2: 3scale APIcast gateway operator in the OpenShift console.

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).

Two instances are shown under 3scale APIcast gateway in the console.
Figure 3: 3scale APIcast gateways in the console.

There are also two pods running, one for each API gateway (Figure 4).

Two pods are running 3scale APIcast gateways.
Figure 4: 3scale APIcast pods in the console.

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.

Screenshot showing two services listed in the 3scalegateway project: apicast-example2-apicast and apicast-example-apicast.
Figure 5: The services listed in the 3scalegateway project.

While creating the route, configure the two services with equal service weight (Figure 6).

The load balancer route has its own configuration.
Figure 6: Configuration for the load balancer route.

Step 5: Configure a 3scale API Management product using the load balancer route's URL

Go to 3scale API ManagementProducts<Product Name>IntegrationSettings. 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).

The product has its own configuration.
Figure 7: 3scale API Management configuration.

Step 6: Promote your product API to use the load balancer route's URL in the staging API gateway

Go to 3scale API ManagementProducts<Product Name>IntegrationConfiguration and promote the Staging APIcast configuration (Figure 8).

The APIcast has its own configuration.
Figure 8: Configuration for the APIcast.

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.

Information retrieved by cURL commands to the service show that two different hosts are responding.
Figure 9: Information retrieved by cURL commands to the service.

Conclusion

3scale API Management supports multiple deployment strategies with API gateways. For more information, see the following links:

Last updated: September 19, 2023