- ngrok’s out-of-the-box API Gateway
- The ngrok Kubernetes Operator, which adds secure public ingress and middleware execution with declarative CRDs
- The Kubernetes Gateway API, for role-oriented load balancing and routing with developer-defined paths to production APIs
- Argo CD, a declarative GitOps tool for Kubernetes that version-controls definitions, configurations, and environments, including an API gateway
What you’ll need
- An ngrok account.
- A Kubernetes cluster.
For a local cluster, use minikube; this guide refers to your cluster as
<YOUR-CLUSTER>. - Argo CD installed on your cluster, with the
argocdCLI installed and logged in on your local workstation. - kubectl and Helm 3.0.0+ installed on your local workstation.
- The ngrok Kubernetes Operator installed on your cluster.
- A reserved domain from the ngrok dashboard or API.
You can use an ngrok subdomain or a custom branded domain like
https://api.example.com; this guide refers to it as<NGROK_DOMAIN>.
Deploy Argo CD
This guide uses Argo CD to sync your Git repository to your cluster. If you don’t have it yet, follow Argo CD’s getting started guide to install it on your cluster and log in with theargocd CLI.
Confirm Argo CD is running before continuing:
Set up the demo API
Next, you need to set up the Git repository for the API you’ll deploy behind your ngrok API gateway. GitOps (and thus APIOps) requires declarative and version-controlled configuration, and that includes the hostname for your deployment. You can’t simply clone the demo API repository and apply it to your cluster, as the ngrok-supplied hostname will already be in use. If you have an existing API and GitOps configuration, you can skip to Deploy your demo API with Argo CD and adapt the Argo CD CLI commands to your Git repository.-
Reserve a static domain from the ngrok dashboard or API.
This static domain (for example,
example.ngrok.app) is yourNGROK_DOMAINfor the remainder of this guide. - Fork the repository for the demo API at ngrok-samples/apiops-demo.
-
In your fork, open
gateway.yamland replace the values of lines 18 and 37 with the ngrok domain you just created (for example,one-two-three.ngrok.app). - Add, commit, and push these changes to your fork.
Deploy your demo API with Argo CD
Now that your demo API is forked and properly configured on GitHub, you can connect it to Argo CD to sync, reconcile, and deploy.-
Register the demo app with Argo CD, replacing
<YOUR-GITHUB-USERNAME>with your fork of the demo API repository.Refresh the Argo CD UI to see your app. The Missing and OutOfSync status report are not errors; they reflect that Argo CD doesn’t automatically sync and deploy a newly registered app. You can click the app to view additional details about the deployment and the Git repository on which it is based. -
Use the Argo CD CLI to perform a manual first sync of your registered app against your Git repository.
Refresh the UI to see that your demo API is properly synced and deployed. You can also navigate to the Endpoints section of the ngrok dashboard to see the endpoint the ngrok Kubernetes Operator created via secure tunnel. You can
curlyour deployed API; ngrok’s API gateway handles ingress and TLS automatically. You’ll only seenullin response, but that confirms your demo API is working.
Enable APIOps in Argo CD
A fundamental component of GitOps, and thus APIOps, is that because your Git repository contains the latest version of your desired state, your deployment toolkit should automatically update the production deployment without any manual processes.-
Enable auto sync of your app to the Git repository that stores your desired state.
You can confirm this change in the Argo CD UI.The default interval at which Argo CD looks for changes to the desired state in your Git repo is 3 minutes. You can alter this in Argo CD’s configuration.
-
Optionally, test auto sync by editing the number of replicas of the demo API in your cluster.
In your Git repository, open the
deployment.yamlfile and edit thereplicasvalue:To push these changes to your production cluster, add, commit, and push them to your Git repository.Argo CD will soon poll your repository, identify changes, and reconcile the deployed state to increase the number of replicas.
Configure your API gateway with Traffic Policies
The Traffic Policy module can be used alongside the Kubernetes Gateway API. This lets you place all your Traffic Policy actions into a singleNgrokTrafficPolicy CRD and control your ngrok-powered API gateway with an APIOps workflow using version-controlled, declarative manifests.
The project includes a basic example in traffic-policy.yaml.
The steps below add rate limiting with the rate-limit action, a common first step in protecting an API from abuse.
-
In your fork of the demo API project, create a new file called
rate-limiting.yaml. Open the file and add the following YAML:This example policy includes a low limit for demonstration purposes, but you can change thecapacityvalue to your needs in production. -
Insert the YAML below into the
HTTPRoutein yourdeployment.yaml. This defines a filter that runs during the request or response lifecycle, letting you inject policy into all traffic arriving at your API through your ngrok API gateway. -
Add, commit, and push this change to your Git repository.
Argo CD will auto sync and reconcile the deployed state with the changes to the
NgrokTrafficPolicyCRD andHTTPRoute. Once the ngrok Kubernetes Operator picks up those changes, it will push them, and you can verify them directly in your ngrok dashboard. -
Optionally, test your new rate limiting policy by
curl-ing your API in a quick loop.You should see429response codes as your ngrok API gateway rate-limits your IP address.