
Environment status
At the start of the lab only thecoffee application and its Service are running — no Gateways or HTTPRoutes are present.
What we’ll deploy
- A Gateway (in
default) with:- HTTP listener on port 80
- HTTPS listener on port 443 with TLS termination using a Secret
- Two HTTPRoutes:
- One on the HTTP listener that redirects requests to HTTPS (301)
- One on the HTTPS listener that forwards
/coffeeto thecoffeeService
- A
certificatenamespace with a TLS Secretcafe-secret(self-signed) - A
ReferenceGrantthat allows the Gateway indefaultto reference the Secret incertificate
Quick reference — manifests and purpose
Relevant docs:
- Gateway API overview: https://gateway-api.sigs.k8s.io/
- ReferenceGrant: https://gateway-api.sigs.k8s.io/spec/#referencegrant
Gateway manifest (gateway.yaml)
This Gateway uses thenginx GatewayClass and terminates TLS using a Secret in the certificate namespace.
Notes on TLS mode
Terminatemeans TLS is terminated at the Gateway; traffic to backend pods will be plain HTTP.- Because the Secret is in a different namespace (
certificate) than the Gateway (default), aReferenceGrantis required to allow cross-namespace references.
Namespace and Secret (ns.yaml & cert.yaml)
ns.yamlcreates thecertificatenamespace.cert.yamlcontains thekubeTLS Secretcafe-secretwith base64-encodedtls.crtandtls.key(self-signed for lab/testing).
ReferenceGrant (ref-grant.yaml)
A ReferenceGrant in thecertificate namespace grants permission for Gateways in default to use the Secret.
Create the Gateway
HTTPRoutes (routes.yaml)
We create two HTTPRoute resources:cafe-tls-redirect— attached to the Gateway’s HTTP listener; issues a 301 redirect to HTTPS.coffee— attached to the Gateway’s HTTPS listener; matches path prefix/coffeeand forwards requests to thecoffeeService on port 80.
Verify resources
Check the Secret, ReferenceGrant, and HTTPRoutes:Testing behavior with curl
In this lab the Gateway ports are exposed on localhost using mapped ports (example: 8080 for HTTP and 8443 for HTTPS). We use--resolve so cafe.example.com resolves to 127.0.0.1 at the chosen port.
- Access HTTP (expect a 301 redirect to HTTPS)
- Access HTTPS (Gateway terminates TLS; the cert is self-signed so
--insecureis used here)
The HTTPS curl uses
--insecure because this lab uses a self-signed certificate. In production, use certificates signed by a trusted CA (for example via Let’s Encrypt or an internal PKI) and proper DNS; you won’t need --resolve or --insecure.Summary
- The Gateway is configured to terminate TLS with a Secret stored in a separate namespace.
- A
ReferenceGrantallows the Gateway to reference that cross-namespace Secret. - An HTTPRoute on the HTTP listener performs a 301 redirect to HTTPS.
- The HTTPS listener forwards
/coffeeto thecoffeebackend Service. - For production deployments use a trusted certificate and real DNS so clients can validate TLS without bypassing checks.