- Handle public API traffic with JWT authentication and rate limiting
- Route requests to different microservices based on URL paths
- Apply consistent authentication and authorization policies
- Deploy and test services independently without rewriting routing logic
- Debug distributed request flows from a central gateway
Install the ngrok Kubernetes Operator
Install the ngrok Kubernetes Operator in your cluster.
For detailed installation instructions, see the Kubernetes CRDs getting started guide.
Create AgentEndpoints for your microservices
Create Order service:Notification service:Apply these configurations:
AgentEndpoint CRDs to expose your microservices.
These create internal endpoints that are not publicly accessible but can be routed through your gateway.User service:Reserve a domain
Navigate to the Domains section of the ngrok dashboard and click New + to reserve a free static domain like or a custom domain you already own.This guide refers to this domain as
$NGROK_DOMAIN from here on out.Create a Cloud Endpoint
Navigate to the Endpoints section of the ngrok dashboard, then click New + and Cloud Endpoint.In the URL field, enter the domain you just reserved to finish creating your Cloud Endpoint.
(Optional) Create secrets for authentication
Store your JWT validation keys using Traffic Policy Secrets.
Apply Traffic Policy to your Cloud Endpoint
Configure your Cloud Endpoint with JWT authentication and routing to your microservices.
Make sure you change each of the following values:What’s happening here?
This policy creates a secure, centralized API gateway for your microservices architecture.
On every HTTP request, the policy first applies OWASP Core Rule Set protection to block malicious requests like SQL injection and XSS attacks, then validates JWT tokens to ensure only authenticated users can access your APIs, and applies per-user rate limiting based on the JWT subject to prevent abuse.The gateway intelligently routes traffic to the appropriate microservice based on URL paths—user management requests go to the user service, order-related requests to the order service, and notification requests to the notification service.
On responses, it applies OWASP protection to scan outgoing content for vulnerabilities and adds service tracing headers for observability and debugging across your distributed system.
$JWT_ISSUER: Replace with your JWT issuer URL$JWT_AUDIENCE: Replace with your JWT audience claim$JWT_PUBLIC_KEY_URL: Replace with your JWKS endpoint URL- Service URLs: Replace with your actual internal service endpoints
What’s next?
- Explore other authentication methods like OAuth, OIDC, or Basic Auth.
- Learn about more routing options like routing by header, cookie, or geographic location.
- Read about other gateway shapes you can build with ngrok.
- Learn about AgentEndpoint CRDs for more advanced Kubernetes configurations.
- Use Traffic Inspector to debug microservice request flows.
- Configure endpoint pooling for high availability across multiple service replicas.