Authors: Rohit Singh & Anjali Kushwaha
Anypoint Flex Gateway is a lightweight, cloud-native API gateway that can be deployed anywhere. It is capable of exposing both MuleSoft APIs and non-MuleSoft APIs to the public internet. In connected mode, Flex Gateway can be utilized to manage and secure APIs deployed on Kubernetes.
An Ingress Controller is a Kubernetes resource that manages external access to a Kubernetes cluster. Typically, Ingress Controllers offer features such as load balancing, SSL termination, and name-based routing.
This blog post provides an introduction to using Anypoint Flex Gateway as a Kubernetes Ingress Controller in connected mode.
Prerequisites
- Anypoint Platform
- Docker Desktop
- Running Kubernetes
- To set up a local instance, install either k3d or minikube. Alternatively, you can utilize a cloud service provider such as EKS or AKS. In this example, we will be using Minikube.
- Helm with minimum 3.0.0 version
Step 1: Pull Flex Gateway Image
To install Flex Gateway on Minikube, use the following command to pull the Flex Gateway Docker image:
docker pull mulesoft/flex-gateway

Step 2: Register the Flex Gateway
To register the Flex Gateway, we have three authentication mechanisms:
- Connected App
- Auth Token
- Username & Password of Anypoint Platform
Here, we are registering the Flex Gateway using a Connected App. To do so, we should have a Connected App with the following permissions:
- Read Servers
- Manage Servers
- View Organization
Now, refer to the command below and modify it accordingly. Run this command in the cmd, and it will create a registration file in the location you specified in the “$(pwd)” placeholder.
docker run --entrypoint flexctl -v "$(pwd)":/registration mulesoft/flex-gateway register --organization=<organization-id>--client-id=<client-id> --client-secret=<client-secret> --environment=<environment-id> --output-directory=/registration --connected=true <gateway-name>


After executing the command, you will be able to see the Flex Gateway created on the Runtime Manager of the Anypoint Platform. At this stage, the status will be in Disconnected mode.

Step3: Create Namespace
On Minikube, we will create a separate namespace called “gateway” for installing the Flex Gateway.

We can view the Minikube dashboard by running the command below:
minikube dashboard

It will launch the Minikube console in the browser, displaying a drop-down list of namespaces, as shown in the screenshot below.

If you want to delete a namespace, you can run the command “kubectl delete namespace [your-namespace]” from your command prompt.
Step 4: Add Flex Gateway Helm Chart
To add and update the Flex Gateway Helm repository, run the command below:

Step 5: Deploy and Connect the Gateway
To deploy the gateway to your Kubernetes cluster and connect it to the Anypoint Platform, use the following command in cmd from the location where your registration file is located:
helm -n gateway upgrade -i ingress flex-gateway/flex-gateway --set-file registration.content=registration.yaml --set
gateway.mode=connected

After executing the above command, one replica will be created under Flex Gateway on the Anypoint Platform, and the Flex Gateway will now be shown as connected.

We can also verify the health of the replica in the Minikube dashboard.


The command below can be used to view the list of services operating under the “gateway” namespace. This command will return the ingress service data along with a private URL for accessing the ingress.
