Behind a Gateway
The chart can create a Gateway API HTTPRoute for the app, under a path prefix such as /app/hello. Several releases can then share one Gateway, each under its own path.
| Needs | Installs into | You get |
|---|---|---|
kubectl, Helm 4, and a Gateway |
the namespace you choose | the app and an HTTPRoute attached to your Gateway |
You bring the Gateway API implementation, such as NGINX Gateway Fabric or Traefik, and a Gateway. The chart doesn’t install either, because the right one depends on your cluster. The Gateway’s listener must allow routes from the app’s namespace (allowedRoutes).
Path prefixes and rewriting
Section titled “Path prefixes and rewriting”rewritePath |
The Gateway | The app |
|---|---|---|
false (recommended) |
passes /app/hello/... on unchanged |
serves under /app/hello |
true (the 1.x default) |
strips /app/hello with the standard URLRewrite filter |
serves at /, and links its assets under /app/hello |
With rewritePath=true, the route needs no settings for your implementation. But URLRewrite is an extended Gateway API feature, so check that your implementation supports it. rewritePath=false works everywhere. The default changes to false in 2.0.
Set service.type=ClusterIP too. The Gateway reaches the Service inside the cluster, and a LoadBalancer Service would give the app a second, public address that bypasses it.
Install
Section titled “Install”Name your Gateway in httpRoute.parentRefs:
helm install hello-gateway oci://ghcr.io/paulbouwer/charts/hello-kubernetes \ --namespace hello-kubernetes --create-namespace \ --set httpRoute.enabled=true \ --set 'httpRoute.parentRefs[0].name=my-gateway' \ --set 'httpRoute.parentRefs[0].namespace=gateway-system' \ --set pathPrefix=/app/hello-gateway \ --set service.type=ClusterIP \ --waitAdd --set rewritePath=false to pass the prefix on, and --set 'httpRoute.hostnames[0]=hello.example.com' for a host name.
Example: Traefik’s Gateway on k3s or k3d
Section titled “Example: Traefik’s Gateway on k3s or k3d”k3s and k3d include the Gateway API resources, and Traefik can serve them. Turn on Traefik’s Gateway API provider, and let its Gateway accept routes from every namespace:
kubectl apply -f - <<'EOF'apiVersion: helm.cattle.io/v1kind: HelmChartConfigmetadata: name: traefik namespace: kube-systemspec: valuesContent: |- providers: kubernetesGateway: enabled: true gateway: listeners: web: namespacePolicy: from: AllEOFuntil kubectl get gateway traefik-gateway --namespace kube-system >/dev/null 2>&1; do sleep 5; donekubectl wait gateway/traefik-gateway --namespace kube-system --for=condition=Programmed --timeout=180sgateway.gateway.networking.k8s.io/traefik-gateway condition metThen install the chart with httpRoute.parentRefs[0].name=traefik-gateway and httpRoute.parentRefs[0].namespace=kube-system. With k3d, create the cluster with -p "8080:80@loadbalancer", and the Gateway’s address is localhost:8080.
Verify
Section titled “Verify”kubectl get httproute --namespace hello-kubernetesYou see the route hello-kubernetes-hello-gateway. Open http://<gateway address>/app/hello-gateway/. You see Hello world!.
If the page doesn’t load, check that the Gateway accepted the route. kubectl describe httproute --namespace hello-kubernetes shows the Accepted and ResolvedRefs conditions for each parent.
Upgrade
Section titled “Upgrade”Change a value with helm upgrade --reset-then-reuse-values, as with Helm. Changing pathPrefix moves the route’s path and the app’s own path together.
Uninstall
Section titled “Uninstall”helm list --namespace hello-kubernetes --short | xargs helm uninstall --namespace hello-kuberneteskubectl delete namespace hello-kubernetesRequirements
Section titled “Requirements”- A Gateway API implementation that serves
gateway.networking.k8s.io/v1HTTPRoutes, and supportsURLRewriteif you keeprewritePath=true. CI tests Traefik on k3d and NGINX Gateway Fabric on kind. - Kubernetes 1.35 or newer, and Helm 4.