Skip to main content

Route

A Route defines how the gateway forwards traffic to a backend. Each route attaches to one or more Gateway CRs and may apply any number of Middleware CRs.

  • API group: gateway.jkaninda.dev
  • Version: v1alpha1
  • Kind: Route

When the goma-k8s-provider sidecar is enabled (default), changes to Route resources are hot-reloaded into the gateway without a pod restart.

Minimal example

A single backend, host-based routing, attached to a Gateway named gateway:

apiVersion: gateway.jkaninda.dev/v1alpha1
kind: Route
metadata:
name: api
namespace: default
spec:
gateways:
- gateway
path: /
hosts:
- api.example.com
target: http://api-service.default.svc.cluster.local:8080
methods:
- GET
- POST

Load-balanced backends

Use backends instead of target to distribute traffic across multiple endpoints. Active health checks remove unhealthy backends from rotation.

apiVersion: gateway.jkaninda.dev/v1alpha1
kind: Route
metadata:
name: api-lb
spec:
gateways:
- gateway
path: /api
rewrite: /
hosts:
- api.example.com
backends:
# 80/20 weighted split between v1 and v2.
- endpoint: http://api-v1.default.svc.cluster.local:8080
weight: 80
- endpoint: http://api-v2.default.svc.cluster.local:8080
weight: 20
# Canary backend — only receives traffic carrying X-Canary: true.
# `exclusive: true` keeps it out of the general LB pool.
- endpoint: http://api-canary.default.svc.cluster.local:8080
exclusive: true
match:
- source: header
name: X-Canary
operator: equals
value: "true"
healthCheck:
path: /healthz
interval: 15s
timeout: 3s
healthyStatuses: [200, 204]

Backend matching

match rules pin requests to a specific backend based on request attributes. Sources: header, cookie, query, ip. Operators: equals, not_equals, contains, not_contains, starts_with, ends_with, regex, in.

When exclusive: true, the backend only receives matched traffic. When false (default), matched traffic is pinned but the backend still participates in normal load balancing.

Per-route TLS

Serve a custom certificate for the route's hosts. Reference a kubernetes.io/tls Secret:

spec:
hosts:
- api.example.com
tls:
secretName: api-example-com-tls

When the K8s provider sidecar is enabled, the cert/key are written to disk and hot-reloaded — no pod restart.

For ACME-managed certificates, configure certManager on the parent Gateway instead.

Backend TLS / mTLS

Control how the gateway connects to backend servers (separate from the cert it serves to clients):

spec:
security:
forwardHostHeaders: true
enableExploitProtection: true # SQLi / XSS heuristics
tls:
insecureSkipVerify: false
rootCAsSecret: backend-ca # Secret with custom CA bundle
clientCertSecret: backend-client # kubernetes.io/tls secret for mTLS

Maintenance mode

Return a static response instead of proxying to the backend:

spec:
maintenance:
enabled: true
status: 503
body: |
{"error":"maintenance","message":"Back at 14:00 UTC."}

Attaching middlewares

List Middleware CR names by metadata.name. They are applied in order:

spec:
middlewares:
- api-jwt
- api-rate-limit

See the Middleware documentation for the supported types and their configuration.

Spec reference

FieldTypeDescription
gateways[]stringRequired. Names of Gateway CRs (same namespace) this route attaches to.
pathstringRequired. URL path matched by this route.
rewritestringPath rewrite (e.g. /api/).
targetstringSingle backend URL. Mutually exclusive with backends.
methods[]stringAllowed HTTP methods (e.g. GET, POST). Empty = all.
enabledboolWhether the route is active. Default: true.
priorityintMatch order — higher matches first.
hosts[]stringHostnames for host-based routing.
backends[]objectMultiple backends for load balancing (see below).
healthCheckobjectActive backend health check (see below).
securityobjectPer-route security settings.
middlewares[]stringMiddleware CR names to apply.
disableMetricsboolSuppress Prometheus per-route metrics for this route.
tlsobjectsecretName of a kubernetes.io/tls Secret to serve for the route's hosts.
maintenanceobjectMaintenance mode (see above).

spec.backends[]

FieldTypeDescription
endpointstringBackend URL.
weightintLoad-balancing weight.
exclusiveboolWhen true, only matched requests reach this backend.
match[].sourceenumheader, cookie, query, ip.
match[].namestringHeader / cookie / query parameter name.
match[].operatorenumequals, not_equals, contains, not_contains, starts_with, ends_with, regex, in.
match[].valuestringComparison value (comma-separated for in).

spec.healthCheck

FieldTypeDefaultDescription
pathstringHealth check path.
intervalstring30sCheck interval.
timeoutstring5sPer-check timeout.
healthyStatuses[]intHTTP statuses considered healthy.

spec.security

FieldTypeDefaultDescription
forwardHostHeadersbooltrueForward X-Forwarded-Host and related headers.
enableExploitProtectionboolfalseBlock common SQLi / XSS patterns.
tls.insecureSkipVerifyboolfalseSkip backend TLS verification (not recommended).
tls.rootCAsSecretstringSecret with CA bundle for backend TLS.
tls.clientCertSecretstringkubernetes.io/tls Secret for backend mTLS.

Status

kubectl get routes
NAME GATEWAYS PATH TARGET READY AGE
api [gateway] / http://api.default.svc.cluster.local true 2m

Ready: true means the route is valid and synced into the parent Gateway's configuration.