Skip to content

Latest commit

 

History

History

gke-gateway-api-https

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

README.md

GKE Gateway API with HTTPS Setup

This repository contains the Kubernetes manifests required to expose applications on GKE using the native Kubernetes Gateway API (gke-l7-global-external-managed).

By using the native GKE Gateway instead of standard Ingress, we achieve:

  1. Google-Managed Wildcard Certificates: Zero-maintenance, auto-renewing wildcard SSL (*.yourdomain.com) backed by Google Cloud Certificate Manager.
  2. Global Edge Infrastructure: Traffic routes through Google's Global External Application Load Balancer (Envoy-based) with Cloud Armor DDoS protection.
  3. Decoupled Routing: Platform admins manage the Gateway; Developers manage their own HTTPRoute files.
flowchart TD
    %% Styling Definitions
    classDef dns fill:#FFF3E0,stroke:#EF6C00,stroke-width:2px,color:#000;
    classDef cert fill:#E3F2FD,stroke:#1565C0,stroke-width:2px,color:#000;
    classDef k8s fill:#F3E5F5,stroke:#6A1B9A,stroke-width:2px,color:#000;
    classDef app fill:#E8F5E9,stroke:#2E7D32,stroke-width:2px,color:#000;

    %% TOP LEFT
    subgraph DNS ["🌐 DNS Server"]
        direction TB
        CNAME["CNAME Record<br/>(_acme-challenge)"]:::dns
        AREC["A-Record<br/>(my-app.yourdomain.com)"]:::dns
    end

    %% TOP RIGHT
    subgraph CERT_MGR ["🛡️ GCP Certificate Manager"]
        direction TB
        AUTH["DNS Authorization"]:::cert
        CERT["Wildcard Certificate<br/>(*.yourdomain.com)"]:::cert
        MAP["Certificate Map"]:::cert
        
        AUTH -->|Validates| CERT
        CERT -->|Added to| MAP
    end

    %% BOTTOM LEFT
    subgraph EDGE["🚦 K8s Namespace: edge-routing"]
        direction TB
        GW["Gateway CRD<br/>(gke-l7-global-external-managed)"]:::k8s
        GXLB{{"Google Cloud L7<br/>Load Balancer"}}:::cert
        GW -.- GXLB
    end

    %% BOTTOM RIGHT
    subgraph APP_NS ["📦 K8s Namespace: my-app"]
        direction TB
        HR["HTTPRoute<br/>(Host: my-app.yourdomain.com)"]:::k8s
        HCP["HealthCheckPolicy<br/>(Path: /api/v1/health)"]:::k8s
        SVC["Service<br/>(my-app-svc)"]:::k8s
        POD["My App Pod<br/>+ Envoy Sidecar"]:::app
        
        HR -->|backendRefs| SVC
        HCP -.->|targetRef| SVC
        SVC -->|Routes to| POD
    end

    %% CROSS-BOUNDARY RELATIONSHIPS
    
    %% 1. DNS to Cert Validation
    CNAME -.->|Proves Domain Ownership| AUTH
    
    %% 2. Cert to Gateway Binding
    MAP ===|networking.gke.io/certmap| GW
    
    %% 3. DNS to Load Balancer
    AREC ===|1. HTTPS User Traffic| GXLB
    
    %% 4. Gateway to Route Binding
    GW ===|2. parentRefs| HR
    
    %% 5. GXLB directly to Pods (Health & Traffic)
    GXLB -.->|3. Plain HTTP Health Check| HCP
    GXLB ===|"4. App Traffic (PERMISSIVE mTLS)"| POD
Loading

⚠️ Cloud Service Mesh Note: Because the Google Cloud Load Balancer initiates traffic from outside the cluster, it does not possess an Istio mTLS certificate. To use this native architecture with Cloud Service Mesh, your application namespaces must be left in PERMISSIVE mTLS mode so the load balancer's traffic and health checks are not rejected by the Envoy sidecars.

Step 1: Create the Wildcard Certificate (Google Cloud CLI)

Because we want a Wildcard Certificate, we must use DNS Authorization via the Google Cloud Certificate Manager. This allows Google to verify domain ownership via a DNS record, which is perfect if your DNS is hosted externally (like Vercel, Cloudflare, or Route53).

1. Create the DNS Authorization:

gcloud certificate-manager dns-authorizations create my-dns-auth \
    --domain="yourdomain.com"

2. Retrieve the CNAME Record:

gcloud certificate-manager dns-authorizations describe my-dns-auth

Action: Copy the dnsResourceRecord (Name and Data) from the output. Go to your DNS provider (e.g., Vercel) and create this CNAME record.

3. Request the Wildcard Certificate:

gcloud certificate-manager certificates create my-wildcard-cert \
    --domains="*.yourdomain.com,yourdomain.com" \
    --dns-authorizations=my-dns-auth

4. Create the Certificate Map & Entry: This groups the certificate so the Gateway API can easily attach it.

gcloud certificate-manager maps create my-wildcard-map

gcloud certificate-manager maps entries create wildcard-entry \
    --map="my-wildcard-map" \
    --certificates="my-wildcard-cert" \
    --hostname="*.yourdomain.com"

Step 2: Deploy the Gateway (The Edge)

Deploy the Gateway infrastructure. It is best practice to place this in a dedicated networking namespace (e.g., edge-routing) rather than the default namespace.

kubectl apply -f namespace.yaml
kubectl apply -f gateway.yaml

Step 3: Deploy the Application Routes

Developers can now expose their applications by simply dropping an HTTPRoute into their app's namespace. The Gateway dynamically picks this up and routes the traffic securely using the wildcard certificate.

kubectl apply -f http-route.yaml

Step 4: Fix the "No Healthy Upstream" Trap (Health Checks)

Unlike legacy GKE Ingress, the Kubernetes Gateway API does not infer health checks from your Deployment's readinessProbe. By default, it blindly pings the root path (/) on your Service port.

If your application redirects users (e.g., 301 Redirect to /login), the Load Balancer will mark your app as dead and throw a 502 Bad Gateway or no healthy upstream error.

The Fix: You must explicitly define a HealthCheckPolicy to tell the Load Balancer which endpoint returns a 200 OK.

kubectl apply -f hc-policy.yaml

Step 5: Verification & Cutover

  1. Retrieve the Public IP address of your new Gateway:
    kubectl get gateway external-gateway -n edge-routing
  2. Open the Google Cloud Console -> Load Balancing. Wait until the Backend Services show a green checkmark (indicating the HealthCheckPolicy successfully reached your pods).
  3. Update your DNS provider (A-Records) to point your subdomains to the new Gateway IP address.
  4. Enjoy your infinitely scalable, wildcard-secured Gateway architecture!