nginx-gateway-cr

by somaz94

Helm chartv0.5.0App 0.1.0Apache-2.0Verified publisher

Custom resources (Gateway, NginxProxy, ReferenceGrant, ClientSettingsPolicy, ServiceMonitor / PodMonitor) for NGINX Gateway Fabric, deployed alongside the upstream NGF controller chart.

About this chart

nginx-gateway-cr

A Helm chart that deploys NGINX Gateway Fabric custom resources alongside the upstream NGF controller chart.

The upstream chart installs the controller and CRDs, but does not create the tenant-level resources you actually route traffic through. This chart fills that gap with a flexible, multi-Gateway-friendly schema.

What it deploys

ResourceAPIPurpose
Gatewaygateway.networking.k8s.io/v1One per entry in gateways[], with shorthand or fully custom listeners
NginxProxygateway.nginx.org/v1alpha2One per Gateway, configures the dataplane Service + nginx-level options
ReferenceGrantgateway.networking.k8s.io/v1beta1Optional. Cross-namespace access (e.g. Gateway → TLS Secret in another ns)
ClientSettingsPolicygateway.nginx.org/v1alpha1Optional. Client-side (downstream) nginx tuning — request body limits and keep-alive behaviour — attached to a Gateway or route
ServiceMonitor (controller)monitoring.coreos.com/v1Optional. Scrapes the NGF control-plane metrics via the Service
ServiceMonitor (dataplane)monitoring.coreos.com/v1Optional. Scrapes nginx pod metrics from the dataplane Service
PodMonitor (controller)monitoring.coreos.com/v1Optional. Scrapes the NGF control-plane Pod directly. Recommended for NGF 2.x (controller /metrics is exposed on the Pod, not the Service)
PodMonitor (dataplane)monitoring.coreos.com/v1Optional. Scrapes the dataplane (nginx) Pods directly

Prerequisites

Install

OCI registry (Helm 3.8+)

helm install ngf-cr oci://ghcr.io/somaz94/charts/nginx-gateway-cr \
  --version 0.5.0 \
  --namespace nginx-gateway \
  -f my-values.yaml

Classic Helm repo

helm repo add somaz94 https://charts.somaz.blog
helm repo update
helm install ngf-cr somaz94/nginx-gateway-cr \
  --namespace nginx-gateway \
  -f my-values.yaml

Quick examples

Single HTTPS gateway

gateways:
  - name: app
    loadBalancerIP: 192.0.2.10
    https:
      enabled: true
      hostname: "*.example.com"
      tlsSecretName: wildcard-example-tls

Multiple gateways with per-gateway overrides

proxy:
  replicas: 1
  externalTrafficPolicy: Cluster

gateways:
  - name: app
    loadBalancerIP: 192.0.2.10
    https:
      enabled: true
      hostname: "*.example.com"
      tlsSecretName: wildcard-example-tls
    proxy:
      replicas: 3                          # override default

  - name: public
    loadBalancerIP: 192.0.2.11
    proxy:
      service:
        annotations:
          metallb.universe.tf/address-pool: prod-pool

Custom listener (TLS passthrough)

gateways:
  - name: tcp
    loadBalancerIP: 192.0.2.12
    listeners:                             # full override; shorthand ignored
      - name: tls-passthrough
        protocol: TLS
        port: 8443
        tls:
          mode: Passthrough
        allowedRoutes:
          kinds:
            - kind: TLSRoute

Cross-namespace TLS secret via ReferenceGrant

gateways:
  - name: app
    loadBalancerIP: 192.0.2.10
    https:
      enabled: true
      hostname: "*.example.com"
      tlsSecretName: wildcard-example-tls

referenceGrants:
  - name: gateway-to-tls
    namespace: tls                         # ReferenceGrant lives in TARGET namespace
    from:
      - group: gateway.networking.k8s.io
        kind: Gateway
        namespace: default
    to:
      - group: ""
        kind: Secret
        name: wildcard-example-tls

Surviving an nginx reload without dropped keep-alive connections

An nginx reload (any config change — including a backend rollout that shifts endpoints) shuts the old workers down gracefully, and graceful shutdown closes idle keep-alive connections with no notice. HTTP/1.1 has no GOAWAY equivalent, so a client that reuses such a connection at that exact moment sees a connection reset instead of a response.

Holding idle connections open for at least as long as the client's own idle timeout removes the race: the client either reuses the connection well inside the window, or drops it first.

clientSettingsPolicies:
  - name: public-keepalive
    targetRef:
      name: public                 # kind defaults to Gateway
    keepAlive:
      minTimeout: 21s              # >= the client's keep-alive idle timeout

Keep minTimeout at or below keepAlive.timeout.server (nginx's keepalive_timeout, default 75s when unset). The trade-off is that shutting-down workers linger for up to minTimeout after each reload.

Prometheus scraping

For NGF 2.x, prefer PodMonitor for the controller because the upstream chart exposes /metrics:9113 only on the Pod, not on the controller Service:

podMonitor:
  namespace: monitoring
  releaseLabel: kube-prometheus-stack
  controller:
    enabled: true
  dataplane:
    enabled: true

ServiceMonitor works only when a Service in the namespace exposes the metrics port (e.g. via custom port config). When in doubt, use PodMonitor.

Values reference

Top-level

KeyTypeDefaultDescription
commonLabelsobject{}Labels added to every resource.
commonAnnotationsobject{}Annotations added to every resource.
gatewayClassNamestringngfDefault GatewayClassName. Per-gateway overridable.

listenerDefaults

Used when a Gateway entry does not set listeners directly.

KeyTypeDefaultDescription
http.enabledbooltrueAdd an HTTP listener.
http.portint80HTTP listener port.
http.allowedRoutesobject{namespaces: {from: All}}allowedRoutes for the HTTP listener.
https.enabledboolfalseAdd an HTTPS listener.
https.portint443HTTPS listener port.
https.hostnamestring""Listener hostname (wildcards supported).
https.tlsSecretNamestring""TLS Secret used for termination.
https.allowedRoutesobject{namespaces: {from: All}}allowedRoutes for the HTTPS listener.

proxy (defaults applied to every NginxProxy)

KeyTypeDefaultDescription
replicasint1Dataplane Deployment replicas.
resourcesobject{}Container resources (requests/limits).
nodeSelectorobject{}Pod nodeSelector.
tolerationslist[]Pod tolerations.
affinityobject{}Pod affinity.
podAnnotationsobject{}Pod template annotations.
podLabelsobject{}Pod template labels.
service.typestringLoadBalancerService type.
service.externalTrafficPolicystringClusterexternalTrafficPolicy (Cluster or Local).
service.loadBalancerClassstring""LoadBalancer class (e.g. service.k8s.aws/nlb).
service.loadBalancerSourceRangeslist[]Restrict source IPs at the LB.
service.annotationsobject{}Service annotations.
service.labelsobject{}Service labels.
logging.errorLevelstring""nginx error_log level.
metricsobject{}Passthrough into spec.metrics.
rewriteClientIPobject{}Passthrough into spec.rewriteClientIP (only emitted if mode set).
telemetryobject{}Passthrough into spec.telemetry.
disableHTTP2boolfalseDisable HTTP/2 on the dataplane.
ipFamilystring""ipv4, ipv6, or dual.
kubernetesExtraobject{}Escape hatch. Merged into spec.kubernetes.
specExtraobject{}Escape hatch. Merged into spec (top-level).

gateways[]

KeyTypeRequiredDescription
namestringyesGateway name. NginxProxy is named <name>-proxy.
loadBalancerIPstringnoStatic LB IP for the dataplane Service.
gatewayClassNamestringnoOverride top-level gatewayClassName.
labelsobjectnoExtra labels on Gateway + NginxProxy.
annotationsobjectnoExtra annotations on Gateway + NginxProxy.
httpobjectnoListener shorthand (overrides listenerDefaults.http).
httpsobjectnoListener shorthand (overrides listenerDefaults.https).
listenerslistnoFull listener list. If set, shorthand is ignored.
proxyobjectnoPer-gateway NginxProxy overrides (deep-merged with top-level proxy).

referenceGrants[]

KeyTypeRequiredDescription
namestringyesReferenceGrant name.
namespacestringyesTarget namespace (the one being granted access TO).
fromlistyesPassthrough into spec.from.
tolistyesPassthrough into spec.to.

clientSettingsPolicies[]

KeyTypeRequiredDescription
namestringyesPolicy name.
namespacestringnoDefaults to the release namespace. A policy must share a namespace with its target.
labelsobjectnoExtra labels on the policy.
annotationsobjectnoExtra annotations on the policy.
targetRef.namestringyesName of the object to attach to.
targetRef.kindstringnoGateway (default), HTTPRoute, or GRPCRoute.
targetRef.groupstringnoDefaults to gateway.networking.k8s.io.
body.maxSizestringnoclient_max_body_size. "0" disables the check.
body.bufferSizestringnoclient_body_buffer_size. A body larger than this is spilled to a temporary file. Requires NGF >= 2.7.0.
body.timeoutstringnoclient_body_timeout.
keepAlive.requestsintnokeepalive_requests.
keepAlive.timestringnokeepalive_time.
keepAlive.minTimeoutstringnokeepalive_min_timeout. Requires NGF >= 2.6.0 (nginx >= 1.27.4).
keepAlive.timeout.serverstringnokeepalive_timeout server value.
keepAlive.timeout.headerstringnoKeep-Alive: timeout=N response header. Only valid alongside timeout.server.

Durations and sizes are strings in the CRD (21s, 500m), so quote anything YAML would otherwise read as a number. The values schema rejects unknown keys inside these blocks on purpose: a mistyped field would otherwise be dropped silently and produce an accepted policy that configures nothing.

Attaching to a Gateway applies the settings to every route on it; attach to an HTTPRoute / GRPCRoute to scope them to one route.

serviceMonitor / podMonitor

Both blocks share the same shape (a controller and a dataplane sub-block plus shared metadata).

KeyTypeDefaultDescription
namespacestringmonitoringNamespace where the monitor objects are created.
releaseLabelstringkube-prometheus-stackrelease label for kube-prometheus-stack discovery.
intervalstring30sScrape interval (shared by both controller and dataplane).
scrapeTimeoutstring""Optional scrape timeout.
additionalLabelsobject{}Extra labels on the monitor metadata.
controller.enabledboolfalseCreate the controller monitor.
controller.pathstring/metricsScrape path.
controller.portstringmetricsService port name (ServiceMonitor) or container port name (PodMonitor).
controller.selectorobjectmatches NGFSelector applied to the Service (ServiceMonitor) or Pod (PodMonitor).
controller.namespaceSelectorobject{}Empty = Release.Namespace only.
controller.additionalEndpointslist[]Extra endpoint entries appended to spec.endpoints / spec.podMetricsEndpoints.
dataplane.*——Same shape as controller.*.

Use podMonitor for NGF 2.x controller (Pod port metrics:9113 is not on the Service). Use serviceMonitor when a Service exposes the metrics port.

Notes on externalTrafficPolicy

  • Use Cluster (default) when in-cluster pods may resolve the LoadBalancer IP and need traffic to reach the dataplane regardless of which node receives it.
  • Use Local when you must preserve the client source IP and accept that only nodes running a dataplane pod will accept traffic.

Escape hatches

If a field exists on NginxProxy but is not surfaced explicitly:

proxy:
  specExtra:
    kubernetes:
      daemonSet: {}                        # use a DaemonSet instead of Deployment

  kubernetesExtra:
    deployment:
      strategy:
        type: RollingUpdate
        rollingUpdate:
          maxUnavailable: 0

mergeOverwrite semantics — escape hatch keys override chart-managed keys when they collide. Prefer first-class fields when available.

License

Apache-2.0

Deploy nginx-gateway-cr with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has nginx-gateway-cr on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartnginx-gateway-cr is pinned at v0.5.0 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below
opentenant validate opentenant.yaml
terraform init && terraform apply