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​

spec.tls controls the certificate served for the route's hosts. It mirrors the gateway's route tls block: secretName supplies the certificate (rendered as tls.certificate), and provider selects automatic issuance (rendered as tls.provider).

Serve a custom certificate from a kubernetes.io/tls Secret in the Route's namespace:

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. With several named providers, pick one per route, or opt out with none (for example when TLS is terminated upstream):

spec:
hosts:
- internal.example.com
tls:
provider: none
note

tls.provider requires an operator release newer than v0.2.0.

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

The gateway reads the CA bundle from the ca.crt key of rootCAsSecret, and the client pair from tls.crt / tls.key of clientCertSecret.

Known limitation

The current operator renders these paths under /etc/goma/certs/<secret>/ but does not yet mount rootCAsSecret or clientCertSecret into the gateway pod.

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."}
Known limitation

The operator renders these as status and body, while Goma Gateway v1.0 reads statusCode and message. Until this is aligned, the gateway ignores both and answers with its default 503 Service temporarily unavailable.

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 (http or https). Set either target or backends, not both.
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.
tls.secretNamestringkubernetes.io/tls Secret served for the route's hosts.
tls.providerstringCertificate provider from the Gateway's certManager.providers, or none to opt out of automatic issuance. Empty uses defaultProvider.
maintenanceobjectMaintenance mode: enabled, status (default 503), body (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
pathstring—Required when healthCheck is set. Health check path.
intervalstring30sCheck interval.
timeoutstring5sPer-check timeout.
healthyStatuses[]int—HTTP 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.rootCAsSecretstring—Secret with the CA bundle (key ca.crt) for backend TLS.
tls.clientCertSecretstring—kubernetes.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.