Endpoint pooling is the concept of creating two or more endpoints that share the same URL and have pooling enabled (if you don’t enable pooling for an endpoint it cannot have the same URL as another endpoint).
The endpoint pooling page goes over concepts and details of pooling in more depth.
This guide focuses on how to use and configure endpoint pooling while using the ngrok Kubernetes operator.
Note that while endpoint pooling is supported by the ngrok Kubernetes operator, endpoint pools are not specific to the environment in which they were created.
This means that you can pool endpoints created with the Kubernetes operator with endpoints started using the CLI, etc. This is a powerful and important concept to keep in mind to avoid unwanted pooling.
Pooling must be enabled by all endpoints that share the same URL. Any attempt to create a pooled endpoint for a URL already in-use by a non-pooled endpoint will fail.
Similarly, any endpoint attempting to create an endpoint that does not enable pooling and uses a URL that is already in-use by one or more endpoints with pooling enabled will fail.
Endpoint Pooling with AgentEndpoints
Within the Kubernetes operator, AgentEndpoint
resources are currently Always Pooled.
This means that if you create the same AgentEndpoint
in two different Kubernetes clusters, or with a URL shared by any other type of endpoint that has pooling enabled, then they will all be part of the same pool.
When the Kubernetes operator creates AgentEndpoint
resources for you by translating Ingress
and Gateway API resources, it will prefix the generated AgentEndpoint
URL with a special hash to avoid unintended pooling.
Endpoint Pooling with CloudEndpoints
CloudEndpoint
resources default to having pooling disabled, but you can enable it with the spec.poolingEnabled: true
field such as with the following example.
apiVersion: ngrok.k8s.ngrok.com/v1alpha1
kind: NgrokTrafficPolicy
metadata:
name: static-response
namespace: default
spec:
policy:
on_http_request:
- name: example-rule
actions:
- type: custom-response
config:
body: Example response from traffic policy
headers:
content-type: text/plain
status_code: 200
---
apiVersion: ngrok.k8s.ngrok.com/v1alpha1
kind: CloudEndpoint
metadata:
name: example-cloud-endpoint
spec:
poolingEnabled: true
url: https://example-cloud-endpoint.ngrok.io
trafficPolicyName: static-response
Endpoint Pooling with Ingresses
If you are using Ingress
resources with the operator, you can enable endpoint pooling for an Ingress
using the k8s.ngrok.com/pooling-enabled: "true"
annotation.
The following will create an Ingress
that creates a CloudEndpoint
with pooling enabled. Any other endpoint created with the same URL and pooling enabled will be pooled with the CloudEndpoint
that this Ingress
creates.
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
k8s.ngrok.com/pooling-enabled: "true"
name: example-ingress
namespace: default
spec:
ingressClassName: ngrok
rules:
- host: example-ingresses.ngrok.io
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: example-service
port:
number: 80
Since the operator collapses Ingress
resources that share the same hostname, you must make sure that all Ingress
resources that use a given hostname use the same pooling enabled or disabled configuration.
See the using Ingresses guide for more information.
Endpoint Pooling with Gateway API
If you are using Gateway API for configuration, you can enable pooling using the using the k8s.ngrok.com/pooling-enabled: "true"
annotation on Gateway
resources.
The following will create a CloudEndpoint
with pooling enabled. Any other endpoint created with the same URL and pooling enabled will be pooled with the CloudEndpoint
.
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: example-gateway
namespace: default
annotations:
k8s.ngrok.com/pooling-enabled: "true"
spec:
gatewayClassName: ngrok
listeners:
- name: example-hostname
hostname: "example-hostname.ngrok.io"
port: 443
protocol: HTTPS
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: example-route
namespace: default
spec:
hostnames:
- example-hostname.ngrok.io
parentRefs:
- group: gateway.networking.k8s.io
kind: Gateway
name: example-gateway
namespace: default
rules:
- matches:
- path:
type: PathPrefix
value: /
backendRefs:
- group: ""
kind: Service
name: example-service
port: 80
weight: 1