- 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
- Argo CD installed locally.
- An existing remote or local Kubernetes cluster OR minikube to create a new demo cluster locally, which will be referred to as
<YOUR-CLUSTER>. - An AWS EKS cluster.
- An ngrok account.
- kubectl and Helm 3.0.0+ installed on your local workstation.
- The ngrok Kubernetes Operator installed on your cluster.
- A reserved domain, which you can get in the ngrok dashboard or with the ngrok API.
- You can choose from an ngrok subdomain or bring your own custom branded domain, like
https://api.example.com. - This guide refers to this domain as
<NGROK_DOMAIN>.
- You can choose from an ngrok subdomain or bring your own custom branded domain, like
Deploy Argo CD
Set up Argo CD on your cluster to enable GitOps.-
Create a namespace for Argo CD:
-
Apply Argo CD’s default manifest to your Kubernetes cluster.
-
Verify you’ve deployed Argo CD successfully via a single running pod.
-
Log into the Argo CD web UI by creating a new port-forwarding session.
When you navigate to
http://<YOUR-CLUSTER>:8080, you’ll first see a warning about self-signed certificates, which you can accept to proceed. Finally, Argo CD prompts you to login with a username and password. The username isadmin, and you can retrieve the automatically generated administrator password with the following:Once logged in, you’ll have access to the Argo CD UI. -
Log in to Argo CD via the CLI to enable administration.
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 step 4 while adopting the Argo CD CLI commands to your Git repository.-
Create a new ngrok static domain.
Go to the Domains section of the ngrok dashboard and click Create Domain or New Domain.
This static domain (for example,
example.ngrok.app) will be 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 Edges view of your ngrok dashboard, then click the Edge associated with the ngrok domain you created earlier, to see that the ngrok Kubernetes Operator pushed its definitions to the ngrok Edge 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.
See traffic-policy.yaml for details.
Because rate limiting is typically the first step in protecting any API from abuse, that process is outlined below.
-
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 definitions to your ngrok Edge—you can verify those changes 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.