Skip to content

Custom And Experimental Resources

Nantian Gateway uses standard Gateway API resources for routing. It also understands experimental extension resources when the relevant feature flags and CRDs are installed.

ResourceAPI versionScopePurpose
AIServicegateway.nantian.dev/v1alpha1NamespacedConfigure one AI provider/model target for AI gateway routing.
TokenPolicygateway.nantian.dev/v1alpha1NamespacedAttach token and request limits to local Gateway API target resources.
WasmPlugingateway.nantian.dev/v1alpha1NamespacedLoad a Wasm module and bind it to target resources.
BackendLBPolicygateway.networking.k8s.io/v1alpha2NamespacedConfigure backend load-balancing strategy and session persistence.
RoutePolicygateway.nantian.dev/v1alpha1NamespacedConfigure per-route timeout, body limit, proxy buffering, and connection keepalive.

Read Experimental Features before creating these resources.

AIService configures one AI provider/model target.

FieldRequiredNotes
spec.providerYesProvider name, such as openai, anthropic, or ollama.
spec.formatNoRequest/response format hint.
spec.modelYesModel name used by the provider.
spec.endpointNoCustom provider endpoint or base URL.
spec.auth.typeNoAuth type understood by the runtime.
spec.auth.secretNoKubernetes Secret name.
spec.auth.keyNoKey inside the Secret.
spec.auth.headerNoHeader used for credentials.
spec.timeoutNoTimeout duration string.
spec.retry.maxRetriesNoRetry count.
spec.retry.backoffNoRetry backoff duration string.
spec.observability.langfuse.*NoLangfuse integration fields.
spec.observability.otel.*NoOpenTelemetry integration fields.

Example:

apiVersion: gateway.nantian.dev/v1alpha1
kind: AIService
metadata:
name: openai-gpt4o
namespace: nantian-demo
spec:
provider: openai
format: openai
model: gpt-4o
auth:
type: bearer
secret: openai-api-key
key: token
header: Authorization
timeout: 60s
retry:
maxRetries: 2
backoff: 500ms

TokenPolicy attaches token and request limits to local Gateway API target resources.

FieldRequiredNotes
spec.targetRefsYesList of LocalPolicyTargetReference; group, kind, and name are required.
spec.tokensPerMinuteNoToken limit per minute.
spec.tokensPerHourNoToken limit per hour.
spec.requestsPerMinuteNoRequest limit per minute.
spec.scopeNoScope string interpreted by runtime policy.
spec.burstNoBurst multiplier.
spec.onLimitNoLimit behavior such as reject.

Example:

apiVersion: gateway.nantian.dev/v1alpha1
kind: TokenPolicy
metadata:
name: ai-route-quota
namespace: nantian-demo
spec:
targetRefs:
- group: gateway.networking.k8s.io
kind: HTTPRoute
name: ai-route
tokensPerMinute: 100000
tokensPerHour: 5000000
requestsPerMinute: 1000
scope: route
burst: 1.5
onLimit: reject

WasmPlugin declares a Wasm source and optional target bindings.

FieldRequiredNotes
spec.wasmYesWasm source object.
spec.wasm.urlNoURL source for a Wasm module.
spec.wasm.configMap.nameNoConfigMap source name.
spec.wasm.configMap.keyNoConfigMap data key; default behavior depends on translator.
spec.wasm.inlineNoInline base64 module content.
spec.wasm.sha256NoSHA-256 checksum.
spec.targetRefsNoTarget refs with group, kind, and name.
spec.hooksNoonRequest, onResponse, onStreamChunk.
spec.configNoPlugin config string.
spec.sandbox.*NoRuntime sandbox limits.

Example:

apiVersion: gateway.nantian.dev/v1alpha1
kind: WasmPlugin
metadata:
name: request-audit
namespace: nantian-demo
spec:
wasm:
url: https://example.com/plugins/request-audit.wasm
sha256: 0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef
targetRefs:
- group: gateway.networking.k8s.io
kind: HTTPRoute
name: echo
hooks:
- onRequest
- onResponse
config: |
{"mode":"audit"}
sandbox:
maxMemoryBytes: 67108864
maxExecutionTimeMs: 100
allowNetwork: false
allowFileSystem: false

BackendLBPolicy is a Gateway API experimental policy, not a Nantian API group resource.

FieldRequiredNotes
spec.targetRefsYesLocal policy target refs.
spec.loadBalancing.typeNoRoundRobin, ConsistentHash, LeastRequest, or Random.
spec.loadBalancing.consistentHash.keyTypeNoSourceIP, Header, or Hostname.
spec.loadBalancing.consistentHash.headerNameNoRequired when key type is Header.
spec.sessionPersistenceNoGateway API v1alpha2 session persistence object.
spec.circuitBreaker.maxInflightRequestsNoMaximum concurrent inflight requests to the backend; excess requests are rejected.

Example:

apiVersion: gateway.networking.k8s.io/v1alpha2
kind: BackendLBPolicy
metadata:
name: echo-lb
namespace: nantian-demo
spec:
targetRefs:
- group: ""
kind: Service
name: echo
loadBalancing:
type: ConsistentHash
consistentHash:
keyType: Header
headerName: x-session-id

RoutePolicy attaches per-route defaults for timeout, body limit, proxy buffering, and connection keepalive to local Gateway API target resources.

FieldRequiredNotes
spec.targetRefsYesList of LocalPolicyTargetReference; group, kind, and name are required.
spec.default.timeout.requestNoTimeout for the entire request-response cycle.
spec.default.timeout.backendRequestNoTimeout for a single backend request attempt.
spec.default.timeout.connectNoTimeout to establish a TCP connection to the backend.
spec.default.timeout.nextUpstreamNoTime spent finding a viable upstream during retries.
spec.default.bodyLimit.maxRequestBodyBytesNoMaximum request body size in bytes.
spec.default.bodyLimit.requestBodyBufferBytesNoBuffer size for reading the request body before spilling to a temporary file.
spec.default.bodyLimit.maxRequestHeaderBytesNoMaximum combined size of all request headers in bytes.
spec.default.proxy.requestBufferingNoWhether to buffer the client request body before proxying.
spec.default.proxy.responseBufferingNoWhether to buffer the backend response before sending to the client.
spec.default.proxy.bufferSizeNoSize of each response buffer in bytes.
spec.default.proxy.bufferCountNoNumber of response buffers to allocate.
spec.default.connection.keepaliveRequestsNoMaximum requests on a single keepalive client connection.
spec.default.connection.upstreamKeepalivePoolSizeNoMaximum idle upstream keepalive connections to maintain in the pool.
spec.default.connection.keepaliveTimeNoMaximum lifetime of a keepalive client connection.
spec.default.connection.keepaliveTimeoutNoMaximum idle time before closing a keepalive client connection.
spec.default.connection.upstreamKeepaliveIdleNoMaximum idle time before closing an upstream keepalive connection.

Example:

apiVersion: gateway.nantian.dev/v1alpha1
kind: RoutePolicy
metadata:
name: echo-route-policy
namespace: nantian-demo
spec:
targetRefs:
- group: gateway.networking.k8s.io
kind: HTTPRoute
name: echo
default:
timeout:
request: 30s
backendRequest: 15s
connect: 2s
nextUpstream: 5s
bodyLimit:
maxRequestBodyBytes: 2097152
requestBodyBufferBytes: 65536
maxRequestHeaderBytes: 8192
proxy:
requestBuffering: false
responseBuffering: true
bufferSize: 16384
bufferCount: 4
connection:
keepaliveRequests: 1000
upstreamKeepalivePoolSize: 128
keepaliveTime: 1h
keepaliveTimeout: 75s
upstreamKeepaliveIdle: 60s