You can use Flex Gateway locally or in connected mode. If you use it locally, you will only be able to run it from your local machine, but you can’t manage the APIs from Anypoint Platform. In connected mode, you can view your gateways, your API instances, and policy configurations in API Manager. In this case, we’ll register and run Flex Gateway in connected mode using the Flex Gateway Docker image.
In this tutorial, you’ll learn how to:
1 - Log in to Anypoint Platform and navigate to Runtime Manager. Click on the Flex Gateways tab on the left and select Add Gateway.
If this is the first time you access Anypoint Platform, it may ask you to select an environment. Choose Sandbox.
2 - You will see different options to select where to set up your Flex Gateway. Let’s select Docker. We will now follow the instructions from the screen to set up our Flex Gateway with Anypoint Platform.
1 - Download the Flex Gateway Docker image by running the first command in Runtime Manager. We will be using the latest version in this tutorial.
1
docker pull mulesoft/flex-gateway:latest
You can browse the repository in DockerHub (here) to find any version you want to use instead. To use a different version, run docker pull mulesoft/flex-gateway:<version>
. For example, docker pull mulesoft/flex-gateway:1.0.0
.
2 - Verify the image was correctly installed by running docker images
or checking your images from the Docker Desktop app. You should see the new mulesoft/flex-gateway
image.
Command-line output:
1
2
REPOSITORY TAG IMAGE ID CREATED SIZE
mulesoft/flex-gateway latest 4ba042860c8f 7 days ago 273MB
Docker Desktop preview:
1 - Copy the command from Runtime Manager to register your gateway. It already contains the token
and organization ID
you need to authenticate and connect the gateway with your Anypoint Platform account. You only need to replace <gateway-name>
with your own name (i.e. my-gateway
). If you want to use a different version than the latest
, please update accordingly in the command.
It’s better to run this command in a new folder or in a known location to quickly identify the files that will be created.
You should end up with something like the following (with your own token
and organization
):
Command:
1
2
3
4
5
6
docker run --entrypoint flexctl -w /registration \
-v "$(pwd)":/registration mulesoft/flex-gateway \
register my-gateway \
--token=97ee6fd5-41a8-4089-9503-5ea06df491b1 \
--organization=8a3a006d-9557-4608-9f68-ff3c12eceebc \
--connected=true
Output:
1
2
Starting registration, please be patient.
Registration completed, the configuration files were written in directory ".".
2 - Verify there are 3 new files in the same directory you executed the command. There should be a .conf
, a .key
, and a .pem
file. Write down the absolute path and the name of the .conf
file because you will use these in the next steps. For example:
Absolute path | /Users/alex/flex-gateway |
.conf file | cdb13e72-f8c8-48c4-81dd-9ac3fffcce55.conf |
3 - If you check the Flex Gateway list in Runtime Manager, your should now see your new gateway (my-gateway
) listed with a status of Disconnected. Click on Add Gateway once more to return to the instructions with the commands.
1 - Copy the command from Runtime Manager to start your gateway. You need to replace the absolute path in the -v
parameter with your own and the -e FLEX_RTM_ARM_AGENT_CONFIG
parameter with your .conf
file name. You should end up with something like the following:
1
2
3
4
5
docker run --rm \
-v /Users/alex/flex-gateway/:/etc/flex-gateway/rtm \
-p 8081:8081 \
-e FLEX_RTM_ARM_AGENT_CONFIG=/etc/flex-gateway/rtm/cdb13e72-f8c8-48c4-81dd-9ac3fffcce55.conf \
mulesoft/flex-gateway
You should see an output similar to the following. Note that the command doesn’t finish running. If you kill the process from your local, your gateway will be disconnected.
1
2
3
4
5
6
7
...
[flex-gateway-envoy][info] starting main dispatch loop
[flex-gateway-envoy][info] cds: add 2 cluster(s), remove 2 cluster(s)
[flex-gateway-envoy][info] cds: added/updated 2 cluster(s), skipped 0 unmodified cluster(s)
[flex-gateway-envoy][info] cm init: all clusters initialized
[flex-gateway-envoy][info] all clusters initialized. initializing init manager
[flex-gateway-envoy][info] all dependencies initialized. starting workers
To run the Docker container in a detached mode, you can add -d
at the beginning of the command. Like so: docker run --rm -d ...
2 - If you check the Flex Gateways list in Runtime Manager, your should now see your new gateway (my-gateway
) with a status of Connected.
3 - You can also verify that the container is running in your local with docker container ls
in a new command line, or check if there’s a running container in Docker Desktop.
Command-line output:
1
2
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2d55079f848e mulesoft/flex-gateway "/init" 6 minutes ago Up 6 minutes 0.0.0.0:8081->8081/tcp stupefied_kalam
Docker Desktop preview:
1 - Copy the command from Runtime Manager to start an additional replica on the same host. You need to replace the absolute path in the -v
parameter with your own and the -e FLEX_RTM_ARM_AGENT_CONFIG
parameter with your .conf
file name just as we did in the previous command. Additional to that, assign a new port number in the -p
parameter (i.e., 8082:8082
). You should end up with something like the following:
1
2
3
4
5
6
docker run --rm \
-v /Users/alexandra.martinez/Downloads/flex-gw/:/etc/flex-gateway/rtm \
-p 8082:8082 \
-e FLEX_NAME=replica-name \
-e FLEX_RTM_ARM_AGENT_CONFIG=/etc/flex-gateway/rtm/cdb13e72-f8c8-48c4-81dd-9ac3fffcce55.conf \
mulesoft/flex-gateway
You should see an output similar to the previous command we ran. Same as before, the command doesn’t finish running. If you kill the process from your local, your gateway will be disconnected.
1
2
3
4
5
6
7
...
[flex-gateway-envoy][info] starting main dispatch loop
[flex-gateway-envoy][info] cds: add 2 cluster(s), remove 2 cluster(s)
[flex-gateway-envoy][info] cds: added/updated 2 cluster(s), skipped 0 unmodified cluster(s)
[flex-gateway-envoy][info] cm init: all clusters initialized
[flex-gateway-envoy][info] all clusters initialized. initializing init manager
[flex-gateway-envoy][info] all dependencies initialized. starting workers
To run the Docker container in a detached mode, you can add -d
at the beginning of the command. Like so: docker run --rm -d ...
2 - If you check the Flex Gateways list in Runtime Manager, you should now see 2 replicas listed in your gateway (my-gateway
), both with a status of Connected.
3 - You can also verify that the new container is running in your local with docker container ls
in a new command line, or check if there’s a new running container in Docker Desktop.
Command-line output:
1
2
3
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
392073434dcf mulesoft/flex-gateway "/init" 4 minutes ago Up 4 minutes 0.0.0.0:8082->8082/tcp xenodochial_dubinsky
2d55079f848e mulesoft/flex-gateway "/init" 16 minutes ago Up 16 minutes 0.0.0.0:8081->8081/tcp stupefied_kalam
Docker Desktop preview:
4 - You can continue adding more replicas with the same command but changing the port number for each replica.
1 - To remove a replica, you can stop running the docker run
command (if you didn’t use detached mode) and this will remove the container. Alternatively, you can run docker container stop <container-name>
(i.e., docker container stop stupefied_kalam
) or stop the container from Docker Desktop by clicking on the Stop button on the right side of the container.
2 - If you remove all replicas, you can verify no replicas are running with docker container ls
or in Docker Desktop.
Command-line output:
1
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
Docker Desktop preview:
3 - The gateway might still be listed in Runtime Manager but will have a status of Disconnected if no replicas are connected. The functionality to un-list a gateway is not available yet (when this tutorial was published). For more information, see Anypoint Flex Gateway overview.
In this tutorial, you learned how to:
In the next tutorial, you’ll learn how to manage your APIs from API Manager using the Flex Gateway you created in this tutorial.
Click on the Next button below to continue to the next tutorial.
Try Anypoint Platform for free
Start free trial