NgrokTrafficPolicy Custom Resource

apiVersion: ngrok.k8s.ngrok.com/v1alpha1

kind: NgrokTrafficPolicy

The NgrokTrafficPolicy resource allows you to define your traffic policy configuration in a resource that can by used by reference on other resources such as Ingress, Gateway, CloudEndpoint, and AgentEndpoint. Ingress and Gateway have no direct method for configuring an ngrok traffic policy, so to use a traffic policy with those resources, you would create an NgrokTrafficPolicy resource and add the k8s.ngrok.com/traffic-policy annotation on your Ingress/Gateway to add the traffic policy configuration to it. CloudEndpoint and AgentEndpoint both give you the option to either define the traffic policy configuration inline, or as a reference to an NgrokTrafficPolicy resource, enabling the efficient reuse of common traffic policies such as enforcing ratelimiting/authentication across all of your endpoints without needing to redefine the traffic policy on each individual resource that needs to use it. For more information about writing ngrok traffic policies, refer to the traffic policy section

NgrokTrafficPolicy Structure and Types

The following outlines the high level structure and typings of a NgrokTrafficPolicy
apiVersion: ngrok.k8s.ngrok.com/v1alpha1
kind: NgrokTrafficPolicy
metadata:
  name: <string>
  namespace: <string>
spec:
  policy: <json.RawMessage> # required

NgrokTrafficPolicy Fields

The following sections outline each field of the NgrokTrafficPolicy custom resource, whether they are required, what their default values are (if applicable), and a description of their purpose/constraints.

spec

spec defines the desired state of the NgrokTrafficPolicy Type: Object Required: yes Default: none Fields:
Field NameTypeRequiredDefaultDescription
spec.policyjson.RawMessageyesnoneConfiguration for the traffic policy rules and actions

spec.policy

Defines the phases, rules, actions, and expressions of the traffic policy configuration. Type: json.RawMessage Required: yes Default: none

Example NgrokTrafficPolicy

The following NgrokTrafficPolicy will return a static response when the request query parameter ?debug=true is present. On its own, this NgrokTrafficPolicy will not do anything, and must be attached to an Ingress/Gateway/CloudEndpoint/AgentEndpoint
apiVersion: ngrok.k8s.ngrok.com/v1alpha1
kind: NgrokTrafficPolicy
metadata:
  name: example-ngroktrafficpolicy
  namespace: default
spec:
  policy:
    on_http_request:
    - name: debug
      expressions:
      - req.url.query_params['debug'][0]=='true'
      actions:
      - type: custom-response
        config:
          body: Custom response from traffic policy
          headers:
            content-type: text/plain
          status_code: 200