Setup Anypoint Flex Gateway on the Kubernetes as an Ingress Controller in Connected Mode — Part I

Jitendra Bafna
6 min readAug 3, 2022

--

Introduction

MuleSoft launched Universal API Management in 2022 and released or improved various components.

  • Flex Gateway
  • API Governance
  • API Community Manager
  • API Experience Hub (coming soon)
  • Anypoint DataGraph
  • API Designer
  • API cataloging with the updated Anypoint Platform CLI (coming soon)
  • API Manager

In this particular tutorial we will be focusing on setting up Flex Gateway on MiniKube as an Ingress controller and how to publish APIs to Flex Gateway.

Before we start with the tutorial, let’s understand what Flex Gateway is and what are the benefits that can be extracted out of Flex gateway?

Flex Gateway is lightweight, super-fast and envoy based API Gateway. Envoy is the CNCF project and it is one of the fastest and high performance services till now. Flex Gateway can be deployed anywhere (Cloud, Customer Hosted, Kubernetes, Docker etc.), doesn’t matter where your APIs exist and its technology agnostic.

Benefits of the Flex Gateway

Below is the list of benefits that you can get out of the Flex Gateway.

  • Flex gateway is an ultra-fast gateway that can be used for any APIs (MuleSoft or Non-MuleSoft APIs), deployed anywhere (Cloud, Docker, Kubernetes, Customer Hosted, etc.).
  • Easily manage all the APIs within your organization from a single platform and under a single umbrella.
  • Extend the Anypoint Platform Capabilities to Mule and non-Mule APIs.
  • Secure, discover, govern, or engage the APIs (Mule and non-Mule APIs).
  • Set up the Flex Gateway easily in 2 modes (Local and Connected).
  • Adapt any architecture with a lightweight and flexible API Gateway to manage and secure the APIs.

In Connected Mode, Flex Gateway configuration and API Metrics are managed by the Anypoint Platform and you don’t required any third-party tools whereas in Local Mode, Flex Gateway in managed locally using yaml descriptors and you may require the third-party monitoring tools like Grafana, Prometheus, Splunk etc, for pushing the metrics.

Now, let’s walk through how to install Flex Gateway on MiniKube as an Ingress Controller in Connected Mode..

For installing the Flex Gateway on MiniKube, make sure you have fulfilled below prerequisites

Installing Flex Gateway on MiniKube as an Ingress Controller

Step 1 — Pull Flex Gateway Image

To install Flex Gateway on MiniKube, first we need to pull the Flex Gateway container image. We can use the below command.

docker pull mulesoft/flex-gateway:1.1.0

After downloading the Flex Gateway container image, we need to register the Flex Gateway either in Local or Connected Mode. But we will be using the Connected Mode for this particular tutorial.

Step 2 — Registering the Flex Gateway as a Kubernetes Ingress Controller

For registering the Flex Gateway in the Connected Mode, we can use one of the three Authentication Mechanisms listed below.

  1. Auth Token
  2. Connected App
  3. Anypoint Username and Password

Now, you can login into your Anypoint Platform and Navigate to the Runtime Manager → Flex Gateways. Click on the Add Gateway button on the console. This will provide us with the three options where we want to set up Flex Gateway.

In our case, we will be using the Kubernetes environment and it will also explains the list of commands that you need to execute on the Kubernetes for setting up Flex Gateway in the Connected Mode.

We will be going to run the below command for registering the Flex Gateway on the Anypoint Platform. We need to replace <gateway-name> with some appropriate name.

In this case, we will be using the gateway name as “demo-mule-flex”.

docker run --entrypoint flexctl -w /registration \
-v “$(pwd)”:/registration mulesoft/flex-gateway:1.0.1 \
register <gateway-name> \
--token=61f90255–74bc-430c-abb6-e76ba4c3cf0f \
--organization=er34e370-ee77–5e53–586f-9eb43fee01af \
--connected=true

This is using Auth Token as an Authentication mechanism for registering the Flex Gateway. Once the above command is executed, it will generate the file registration.yaml and generate below output in the command prompt.

This registration.yaml will generated at current path where you have execute the command or if you provide the path explicitly in the command.

At same time, we can see the Flex Gateway registered on the Anypoint Platform as we have passed --connected=true in the command. This means we are setting up the Flex Gateway in the connected mode.

Step 3 — Add Flex Gateway to Helm

We need to add and update the Flex Gateway helm repository and to do so we have to execute below two commands one by one.

helm repo add flex-gateway https://flex-packages.anypoint.mulesoft.com/helm

helm repo up

Once executing the above command on the command prompt, it will generate below output.

Note — Make sure the helm is available on the machine from where you are installing the Flex Gateway. Helm helps you manage Kubernetes applications — Helm Charts help you define, install, and upgrade even the most complex Kubernetes application.

Step 4 — Install the Ingress using Helm

Using Helm, install the Flex Gateway Helm Chart into the gateway namespace.

helm -n gateway upgrade -i --create-namespace --wait ingress flex-gateway/flex-gateway \
--set-file registration.content=registration.yaml

After executing the above command, we will see a replica created under Flex Gateway on Anypoint Platform and Flex Gateway will be in the connected state.

We can verify API Instances that were created during the installation using the below command.

kubectl -n gateway get apiinstances

This command will be generated below output.

We can also execute the command below and it will open the Kubernetes console on the browser and provide more details under the namespace gateway.

minikube dashboard

To see the service list that is running under the namespace gateway, we can execute the below command.

minikube service list -n gateway

This command will provide ingress service details with a private URL for accessing the ingress.

References

Setup Anypoint Flex Gateway on the Kubernetes as an Ingress Controller in Connected Mode — Part I | by Jitendra Bafna | Aug, 2022 | Medium

Setup Anypoint Flex Gateway on the Kubernetes as an Ingress Controller in Connected Mode — Part II | by Jitendra Bafna | Aug, 2022 | Medium

Setup Anypoint Flex Gateway on the Kubernetes as an Ingress Controller in Connected Mode — Part III | by Jitendra Bafna | Aug, 2022 | Medium

Setup Anypoint Flex Gateway on the Kubernetes as an Ingress Controller in Connected Mode — Part IV | by Jitendra Bafna | Aug, 2022 | Medium

In this tutorial, we have seen how to install Flex Gateway on the MiniKube as an Ingress Controller in the Connected Mode and various MiniKube and Kubectl commands for fetching service details, accessing Kubernetes dashboard, creating secrets etc.

In part 2 of this article we will see how to publish an API to Flex Gateway and accessing API from MiniKube and outside the MiniKube.

--

--

Jitendra Bafna

I am Jitendra Bafna, working as a Senior Solution Architect at EPAM Systems and currently leading APIN Competency Center.