How to install Flex Gateway on Ubuntu Server (Connected Mode)


As a MuleSoft architect, one of the key considerations when managing APIs at scale is deploying an effective API gateway. Flex Gateway, MuleSoft’s ultrafast and lightweight gateway, is designed for modern microservices. It’s the Mulesoft’s option for managing non-mule apps and can be deployed in various environments, including bare metal servers, VMs, and Kubernetes.

When installing Flex Gateway as a Linux service, we have two deployment options: local mode and connected mode. While local mode operates independently of the Anypoint Platform, connected mode allows for centralized API management and governance directly from Anypoint. In this blog post, we’ll go through the steps to install and configure Flex Gateway as a Linux service on Ubuntu in connected mode, enabling seamless integration with our Anypoint Platform organization.


Prerequisites

To follow this tutorial we’ll need:
  • Ubuntu Server - In this tutorial we’ll use Ubuntu Server, version 24.04 LTS running on an AWS EC2 instance.
  • A non-mule API running to test the Flex GW - If you don’t have an API for testing check out these posts to quickly get one:
How to Create a REST API with Spring Boot
How to Create a REST API with NodeJS

In this tutorial, we’ll use this Spring Boot REST API deployed in the same server as the Flex Gateway, in port 4000. This way, when we run the following command from the Ubuntu server:

curl http://localhost:4000/hello

We get the response:

{"message":"Hello World from Springboot!"}


Install Flex Gateway

We’ll start by updating our Ubuntu server.

sudo apt update
sudo apt install curl apt-transport-https gnupg -y


Add the Mulesoft Repository

Run the following commands to add the Flex Gateway GPG key and the Mulesoft’s repository:

curl -XGET -L https://flex-packages.anypoint.mulesoft.com/ubuntu/pubkey.gpg | sudo apt-key add - echo "deb https://flex-packages.anypoint.mulesoft.com/ubuntu $(lsb_release -cs) main" \ | sudo tee /etc/apt/sources.list.d/mulesoft.list

Update the package list again.

sudo apt-get update


Install Flex Gateway

Run the installation command command:

sudo apt-get install -y flex-gateway


Verify the installation


flexctl version


(Don’t worry about the error messages - those are normal, as we still haven’t start the Flex GW)


Register and Configure Flex Gateway

To run Flex Gateway in Connected Mode we will follow these steps:


Log in to Anypoint Platform

  • Navigate to Runtime Manager → Flex Gateway and click Add Gateway.
  • In the options for deployment choose Linux and then Ubuntu/Debian as the OS. We will get a set of instructions
  • Copy the registration command provided. The command will contain the details of our business group ID and a token for authentication to connect to our org. Something like this:

sudo flexctl registration create <gateway-name> \
--token=[YOUR_TOKEN] \
--organization=[YOUR_BUSINESS_GROUP_ID] \
--connected=true \
--output-directory=/usr/local/share/mulesoft/flex-gateway/conf
.d

Where

  • --token is the token generated from the control plane to authenticate the registration request
  • <gateway-name> is the descriptive name for our Flex GW
  • --organization=[YOUR_BUSINESS_GROUP_ID] is the ID of the Business Group where we’ll be deploying our API instances
  • --connected=true tells Flex GW that the installation will be connected to the control plane
  • --output-directory - Specifies the path with our Ubuntu server where Flex GW will place the output of the command


Run the Registration Command

  • Copy the registration command and run it on our Ubuntu server replacing the value for the Flex Gateway name.
  • After running the command, our new Flex Gateway should appear in Runtime Manager under Flex Gateway in the left navigation. Additionally, a new file named registration.yaml will be created in /usr/local/share/mulesoft/flex-gateway/conf.d.


Start the Flex Gateway

Once the installation is ready, we’ll enable the flex gateway as a Linux service and start it:

sudo systemctl enable flex-gateway
sudo systemctl start flex-gateway


Verify the installation

To verify that everything went we’ll check the status of the service and the logs


Check the Status

Run the systemctl command:

sudo systemctl status flex-gateway

You should see the service active and green


View Logs

It’s also a good idea to check the logs of the service with the command:

journalctl -u flex-gateway --no-pager --lines=50


Confirm Registration in Anypoint Platform

Lastly, since we’re installing in connected mode, let’s check if the control plane has successfully register our Flex GW. Go to Runtime Manager → Flex Gateway and verify that the new gateway appears as Active.


With that, our Flex GW is connected and running.


Deploy and Manage an API on Flex Gateway

Now it’s time to deploy an API instance in front of our Springboot REST API. For that, go to the Anypoint Platform > API Manager and click on Add API > Add new API.
As Runtime, select Flex Gateway and choose the Flex Gateway we’ve just installed. Click Next


After that, Create new API and provide a name for the API we want to protect. Select HTTP API as asset type. This will create a new asset in our Exchange to identify the API we’re protecting. Click Next


Downstream details - The downstream represents the endpoint that our Flex GW exposes for this API. Select a port and a Base path and make sure this will be unique for all the APIs you plan to protect with this Flex GW instance. In our case, we’ll use port 8081 and /springboot as base path. This way we’ll forward all the traffic in this point to our Spring Boot app. Click Next.



For the Upstream, we need to specify the details of the endpoint(s) where we’ll redirect all the traffic in our Downstream endpoint. This section is full of different options that allow Flex GW to create different routes, routes rules and upstreams. In our case, for simplicity, we will only add one route, the local route of our Spring Boot API http://localhost:4000. This is how all incoming traffic to http://[FLEX_GW_HOSTNAME]:8081/springboot will be redirect to http://localhost:4000. Click Next and then Save & Deploy.



In a few seconds our API instance will be running.

Test the API instance

To verify our API instance is up & running make a request to the Downstream endpoint and add the relative path to the Spring boot REST API. You can use curl or Postman for this

curl http://[FLEX_GW_HOSTNAME]:8081/springboot/hello

If everything went well we should get the Hello World response message

Previous Post Next Post