Configure a wildcard hostname on Envoy Gateway

2026-12-03来源 dev.toEnglish

1. Issue a TLS certificate

This guide uses app.example.com as the base hostname and tenant-a.app.example.com as a tenant hostname. Replace example.com with a domain you manage. Request both app.example.com and *.app.example.com: a TLS wildcard covers exactly one label, so it matches tenant-a.app.example.com but not app.example.com or region.tenant-a.app.example.com.

Use a cert-manager issuer configured for ACME DNS-01 validation. DNS-01 is required for ACME wildcard certificates and lets you issue the certificate before publishing the application's DNS records. The issuer must be able to create challenge TXT records in the authoritative DNS zone.

apiVersion: cert-manager.io/v1 kind: Certificate metadata: name: wildcard-app namespace: gateway-system spec: secretName: wildcard-app-tls issuerRef: name: dns01-issuer kind: ClusterIssuer dnsNames: - app.example.com - '*.app.example.com' 

Replace dns01-issuer with your configured ClusterIssuer. Keep the Certificate and resulting Secret in the Gateway's namespace for this example. After syncing the manifest, check certificate readiness:

kubectl -n gateway-system wait --for=condition=Ready certificate/wildcard-app --timeout=10m 

2. Configure the Gateway and HTTPRoute

On the existing Envoy Gateway, configure an HTTPS listener that can accept both hostnames. The listener below omits hostname, so the HTTPRoute supplies the hostname restrictions. On a shared Gateway, reuse a compatible listener and add the certificate reference rather than creating a conflicting listener. A listener restricted to *.app.example.com does not accept app.example.com itself.

# Fragment of the existing Gateway named public-gateway in gateway-system. spec: listeners: - name: https port: 443 protocol: HTTPS tls: mode: Terminate certificateRefs: - kind: Secret name: wildcard-app-tls allowedRoutes: namespaces: from: Selector selector: matchLabels: kubernetes.io/metadata.name: app 

Create an HTTPRoute in the app namespace. Quote wildcard hostnames in YAML. This example sends /api and /api/... to app-api and everything else to app-web; substitute the names and ports of your Services.

apiVersion: gateway.networking.k8s.io/v1 kind: HTTPRoute metadata: name: wildcard-app namespace: app spec: parentRefs: - name: public-gateway namespace: gateway-system sectionName: https hostnames: - app.example.com - '*.app.example.com' rules: - matches: - path: type: PathPrefix value: /api backendRefs: - name: app-api port: 80 - matches: - path: type: PathPrefix value: / backendRefs: - name: app-web port: 80 

After syncing, check that the Gateway is programmed and the HTTPRoute reports Accepted=True and ResolvedRefs=True for the intended listener.

3. Test HTTPS before publishing DNS

Retrieve the Gateway's load balancer hostname and connect to it directly while preserving the original hostname for TLS and routing. Test both the base hostname and a tenant hostname. Do not bypass certificate verification: this checks what the Gateway actually serves, not just whether cert-manager issued a certificate.

lb=$(kubectl -n gateway-system get gateway public-gateway \ -o jsonpath='{.status.addresses[0].value}') for host in app.example.com tenant-a.app.example.com; do curl --connect-to "$host:443:$lb:443" -sS -o /dev/null \ -w "$host: %{http_code}\n" "https://$host/" done 

Check that each status matches the application’s expected response. Also test a known /api/... endpoint if the route has a separate API backend.

4. Publish DNS and verify

In the public Route 53 hosted zone for example.com, create two CNAME records pointing to the Gateway's load balancer hostname:

Record name Type Example TTL
app.example.com CNAME 300 seconds
*.app.example.com CNAME 300 seconds

The wildcard record does not replace the explicit base record. These CNAMEs are valid because neither sits at the apex of the example.com hosted zone. If the base hostname is itself a hosted-zone apex, use a supported Route 53 alias instead of a CNAME.

After the Route 53 change is INSYNC, verify both names and repeat the HTTPS checks without --connect-to:

dig +short app.example.com CNAME dig +short tenant-a.app.example.com CNAME 

If DNS resolves but certificate verification fails, check the certificate served by the HTTPS listener. If TLS succeeds but you get an unexpected 404 or 503, check hostname matching, route status, and Service endpoints. For a migration, keep the old DNS target handy for rollback and allow for cached answers until the previous TTL expires.

原文:https://www.a8q9.cn/en/article/configure-a-wildcard-hostname-on-envoy-gateway-8755bc.html

相关文章