Skip to main content
This guide walks you through deploying a demo API to a Kubernetes cluster using an APIOps workflow. It consolidates the backend API service, Kubernetes configurations, and API policy definitions into a single repository that defines the desired state of your deployment. It covers:
  • 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 argocd CLI 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 the argocd 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.
  1. Reserve a static domain from the ngrok dashboard or API. This static domain (for example, example.ngrok.app) is your NGROK_DOMAIN for the remainder of this guide.
  2. Fork the repository for the demo API at ngrok-samples/apiops-demo.
  3. In your fork, open gateway.yaml and replace the values of lines 18 and 37 with the ngrok domain you just created (for example, one-two-three.ngrok.app).
  4. 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.
  1. 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.
  2. 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 curl your deployed API; ngrok’s API gateway handles ingress and TLS automatically. You’ll only see null in 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.
  1. 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.
  2. Optionally, test auto sync by editing the number of replicas of the demo API in your cluster. In your Git repository, open the deployment.yaml file and edit the replicas value:
    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 single NgrokTrafficPolicy 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.
  1. 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 the capacity value to your needs in production.
  2. Insert the YAML below into the HTTPRoute in your deployment.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.
  3. 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 NgrokTrafficPolicy CRD and HTTPRoute. Once the ngrok Kubernetes Operator picks up those changes, it will push them, and you can verify them directly in your ngrok dashboard.
  4. Optionally, test your new rate limiting policy by curl-ing your API in a quick loop.
    You should see 429 response codes as your ngrok API gateway rate-limits your IP address.

What’s next?

You’ve now built a proof of concept for deploying an API to production using ngrok and Argo CD. You can use this combination to deploy real-world APIs behind a production-grade gateway without complex configuration or extra external infrastructure. In a real-world deployment, you would also integrate your Git repository with a proper CI/CD pipeline, which would run tests for security, governance, and code quality. By only merging changes that pass your CI/CD pipeline, you can better guarantee the production-readiness of your API. For more Traffic Policy options, see the Auth0 JWT integration and the Traffic Policy docs for the full list of actions and syntax. The library of “drop-in” examples contains additional use cases like blocking traffic from specific countries, deprecating API versions, event logging, and more.