Kubernetes Operator
Overview
The ngrok Kubernetes Operator is the best way to use ngrok if your applications run in Kubernetes environments. It supports both Ingress CRDs as well as the new Gateway API.
The ngrok Kubernetes Operator is deployed to a cluster and allows developers to self-service public endpoints to their apps and services using a shared ngrok account.
The operator watches for Kubernetes objects and creates the corresponding ngrok endpoints and configurations.
More details on how these are derived can be found here.
Other ngrok features such as TCP Edges can be configured via CRDs.
If you are looking to install the controller for the first time, see our deployment-guide. If it's already installed and you are looking to configure ingress for an app or service, see our user-guide.
Install
Installing the ngrok Operator is easy using Helm.
- Ingress Controller
- Gateway API
Add the ngrok Kubernetes Operator repo to Helm:
helm repo add ngrok https://ngrok.github.io/kubernetes-ingress-controller
Install the ngrok Kubernetes Operator:
export NAMESPACE=[YOUR_K8S_NAMESPACE]
export NGROK_AUTHTOKEN=[AUTHTOKEN]
export NGROK_API_KEY=[API_KEY]
helm install ngrok-ingress-controller ngrok/kubernetes-ingress-controller \
--namespace $NAMESPACE \
--create-namespace \
--set credentials.apiKey=$NGROK_API_KEY \
--set credentials.authtoken=$NGROK_AUTHTOKEN
Add the ngrok Kubernetes Operator repo to Helm:
helm repo add ngrok https://ngrok.github.io/kubernetes-ingress-controller
Add the latest Gateway API CRDs to your cluster:
kubectl apply -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v1.0.0/standard-install.yaml
Install the ngrok Kubernetes Operator:
export NAMESPACE=[YOUR_K8S_NAMESPACE]
export NGROK_AUTHTOKEN=[AUTHTOKEN]
export NGROK_API_KEY=[API_KEY]
helm install ngrok-ingress-controller ngrok/kubernetes-ingress-controller \
--namespace $NAMESPACE \
--create-namespace \
--set credentials.apiKey=$NGROK_API_KEY \
--set credentials.authtoken=$NGROK_AUTHTOKEN \
--set useExperimentalGatewayApi=true
Install the GatewayClass object:
apiVersion: gateway.networking.k8s.io/v1
kind: GatewayClass
metadata:
name: ngrok
spec:
controllerName: ngrok.com/gateway-controller
Example Usage
This would create an Edge on with the Domain example.ngrok.app
that routes traffic to the Kubernetes service example-service
running on port 80.
- Ingress Controller
- Gateway API
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: example-ingress
annotations:
k8s.ngrok.com/modules: ngrok-module-set
spec:
ingressClassName: ngrok
rules:
- host: example.ngrok.app
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: example-service
port:
number: 80
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: example-gateway
namespace: default
spec:
gatewayClassName: ngrok
listeners:
- name: example-web
hostname: "example.ngrok.app"
port: 443
protocol: HTTPS
tls:
mode: Terminate
certificateRefs:
- name: ngrokcert #ngrok will generate the cert so this cert does not be defined and will be ignored if defined
allowedRoutes:
kinds:
- kind: HTTPRoute
namespaces:
from: Selector
selector:
matchLabels:
expose-apps: "true"
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: my-route
namespace: default
spec:
parentRefs:
- kind: Gateway
name: example-gateway
namespace: default
hostnames:
- "example.ngrok.app"
rules:
- matches:
- path:
type: PathPrefix
value: /
backendRefs:
- name: example-service
kind: Service
port: 80
Route Traffic based on a path
This would create an Edge on with the Domain example.ngrok.app
that routes traffic from example.ngrok.app/foo to the Kubernetes service example-service
running on port 80.
- Ingress Controller
- Gateway API
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: example-ingress
annotations:
k8s.ngrok.com/modules: ngrok-module-set
spec:
ingressClassName: ngrok
rules:
- host: example.ngrok.app
http:
paths:
- path: /foo
pathType: Prefix
backend:
service:
name: example-service
port:
number: 80
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: my-route
namespace: default
spec:
parentRefs:
- kind: Gateway
name: example-gateway
namespace: default
hostnames:
- "example.ngrok.app"
rules:
- matches:
- path:
type: PathPrefix
value: /foo
backendRefs:
- name: example-service
kind: Service
port: 80
Modify Headers
- Ingress Controller
- Gateway API
kind: NgrokModuleSet
apiVersion: ingress.k8s.ngrok.com/v1alpha1
metadata:
name: ngrok-module-set
modules:
headers:
request:
add:
is-ngrok: "1"
country: "${.ngrok.geo.country_code}"
remove: ["referrer"]
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: example-ingress
annotations:
k8s.ngrok.com/modules: ngrok-module-set
spec:
ingressClassName: ngrok
rules:
- host: your-domain.ngrok.app
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: example-service
port:
number: 80
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: example-route
namespace: ngrok-ingress-controller
spec:
rules:
- backendRefs:
- name: game-2048
port: 80
kind: Service
filters:
- type: RequestHeaderModifier
requestHeaderModifier:
remove: ["x-request-id"]
add:
- name: my-request-header-name
value: my-header-value
set:
- name: my-request-header-to-set
value: set-header-value
Redirect Traffic
- Ingress Controller
- Gateway API
Redirects are not yet supported with the Kubernetes Ingress Controller.
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: redirect-route
namespace: ngrok-ingress-controller
spec:
parentRefs:
- name: ngrok-gateway
hostnames:
- "example.ngrok.app"
rules:
- filters:
- type: RequestRedirect
requestRedirect:
scheme: https
hostname: "example.ngrok.app"
statusCode: 301
path:
type: ReplacePrefixMatch
replacePrefixMatch: /paprika
matches:
- path:
type: PathPrefix
value: /
Pricing
The ngrok Kubernetes Ingress Controller is available to all ngrok users at no additional charge. You only incur costs if the resources provisioned by the controller incur a cost.