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.

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.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.

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