DEV Community

Cover image for Kubernetes Gateway API + Traefik + cert-manager
Omar Ahmed
Omar Ahmed

Posted on Edited on

Kubernetes Gateway API + Traefik + cert-manager

A complete example using Gateway API, Traefik as the gateway controller, NGINX as the backend application, and Let's Encrypt for HTTPS.

1. Architecture

flowchart TD
    Client --> LB["Network LoadBalancer: 80 / 443"]
    LB --> TS["Traefik LoadBalancer Service"]
    TS -->|"80 → 8000 / 443 → 8443"| Gateway["Traefik Gateway"]
    Gateway --> Route["HTTPRoute"]
    Route --> Service["NGINX ClusterIP Service: 80"]
    Service --> Pod1["NGINX Pod 1: 80"]
    Service --> Pod2["NGINX Pod 2: 80"]
    CM["cert-manager"] --> LE["Let's Encrypt"]
    CM --> Secret["TLS Secret"]
    Secret -.-> Gateway
Component Responsibility
GatewayClass Selects the Gateway controller
Gateway Defines HTTP and HTTPS listeners
HTTPRoute Routes requests to backend services
Traefik Reverse proxy and TLS termination
cert-manager Certificate issuance and renewal
Let's Encrypt Trusted certificate authority
NGINX Backend application
LoadBalancer Public entry point

2. Prerequisites

  • Running Kubernetes cluster, kubectl, and Helm.
  • Public domain and DNS access. FreeDNS
  • Publicly accessible ports 80 and 443.
  • LoadBalancer implementation.
  • Replace nginx.example.com and admin@example.com with your actual domain and email.

3. Project structure

k8s/
├── traefik-values.yaml
├── cert-manager-values.yaml
├── namespace.yaml
├── gateway-class.yaml
├── gateway.yaml
├── cluster-issuer.yaml
├── certificate.yaml
├── nginx-deployment.yaml
├── nginx-service.yaml
├── nginx-route.yaml
└── https-redirect.yaml
Enter fullscreen mode Exit fullscreen mode
mkdir -p k8s
cd k8s
Enter fullscreen mode Exit fullscreen mode

4. Install Gateway API CRDs

Gateway API isn't built into Kubernetes. the API server only knows the core kinds like Pod, Service and Ingress. GatewayClass, Gateway and HTTPRoute are Custom Resource Definitions (CRDs), Until you install them, the cluster doesn't recognize those kinds:

GATEWAY_API_VERSION=v1.4.1
kubectl apply --server-side -f \
  "https://github.com/kubernetes-sigs/gateway-api/releases/download/${GATEWAY_API_VERSION}/standard-install.yaml"

kubectl get crd gatewayclasses.gateway.networking.k8s.io \
                gateways.gateway.networking.k8s.io \
                httproutes.gateway.networking.k8s.io
Enter fullscreen mode Exit fullscreen mode

5. Install Traefik

Why Traefik acts as a reverse proxy

A reverse proxy stands in front of your backend servers. Clients connect to the proxy, never to the backends. The proxy reads each request, decides which backend should handle it, sends the request on, and returns the response as if it came from the proxy itself.

Forward proxy:  Client → [Proxy] → Internet          (acts for the client)
Reverse proxy:  Client → [Proxy] → Backend servers   (acts for the servers)
Enter fullscreen mode Exit fullscreen mode

1. Gateway API resources are only configuration.
Gateway and HTTPRoute are records in the Kubernetes API, and they don't handle traffic themselves. Something has to open ports, accept connections and forward requests. Traefik is that component, called the data plane. It watches the Gateway API resources and turns them into live routing rules.

Gateway + HTTPRoute (desired config)  →  Traefik watches them  →  Traefik proxies the traffic
Enter fullscreen mode Exit fullscreen mode

2. One public entry point for many apps.
Without a proxy, each app would need its own LoadBalancer Service, which means one public IP and one cloud load balancer per app. With Traefik, a single LoadBalancer IP serves every hostname and path, and Traefik sends each request to the right Service:

nginx.example.com      → nginx-service
api.example.com/users  → users-service
api.example.com/orders → orders-service
Enter fullscreen mode Exit fullscreen mode

3. It works at Layer 7 (HTTP); a Service works at Layer 4 (TCP).
A Kubernetes Service or cloud load balancer only sees IPs and ports. It can't read the Host header or the URL path, and it can't decrypt HTTPS. Traefik can, which is what makes the following possible:

Job Where it happens in this setup
TLS termination HTTPS listener decrypts using the nginx-tls Secret
Host/path routing HTTPRoute hostnames and PathPrefix matches
HTTP → HTTPS redirect RequestRedirect filter returns 301
Load balancing Spreads requests across the NGINX pods
ACME challenge routing Sends /.well-known/acme-challenge/... to cert-manager's solver
Access logs accessLog.enabled: true in the values

4. Backends stay private and simple.
NGINX runs as a ClusterIP Service with no public IP and no certificates. It only serves plain HTTP inside the cluster, while Traefik handles everything facing the internet. Certificates, redirects and logging are managed in one place instead of separately in every app.

In a single request:

Client ──HTTPS :443──► LoadBalancer ──► Traefik :8443
                                         │ 1. Decrypt TLS (nginx-tls)
                                         │ 2. Match Host: nginx.example.com, path /
                                         │ 3. Pick an NGINX pod
                                         ▼
                                    NGINX pod :80 (plain HTTP)
                                         │
Client ◄──────── encrypted response ─────┘ Traefik re-encrypts the reply
Enter fullscreen mode Exit fullscreen mode

Tip

Traefik is the reverse proxy because Gateway API only describes routing; it needs an implementation to accept connections. Traefik provides one public entry point, Layer 7 routing, TLS termination and redirects, so the backend apps stay internal and simple.

Add the Helm repository

helm repo add traefik https://traefik.github.io/charts
helm repo update
Enter fullscreen mode Exit fullscreen mode

traefik-values.yaml

  • This file installs the Traefik engine, enables its Gateway API controller and exposes it to external traffic.
  • When you install Traefik, you install the controller that implements Gateway API. When you install Gateway API CRDs manually in step 4, you teach Kubernetes about the Gateway API resource types.
  • It acts as a reverse proxy:
deployment:
  replicas: 2

providers:
  kubernetesGateway:
    enabled: true
  kubernetesIngress:
    enabled: false
  kubernetesCRD:
    enabled: false

gateway:
  enabled: false

gatewayClass:
  enabled: false

ingressClass:
  enabled: false


service:
  enabled: true
  spec:
    type: LoadBalancer # install loadbalancer service

log:
  level: INFO

accessLog:
  enabled: true
Enter fullscreen mode Exit fullscreen mode
kubectl get pods -n traefik
NAME                       READY   STATUS    RESTARTS   AGE
traefik-7f9ffb85fd-2k9z2   1/1     Running   0          9m50s
traefik-7f9ffb85fd-jqgl2   1/1     Running   0          9m57s

kubectl get svc -n traefik
NAME      TYPE           CLUSTER-IP      EXTERNAL-IP      PORT(S)                      AGE
traefik   LoadBalancer   10.108.50.236   174.138.110.27   80:32157/TCP,443:31292/TCP   18m
Enter fullscreen mode Exit fullscreen mode

Then create a DNS record using DuckDNS

The default config for Traefik:

  • This configuration defines the web entryPoint of Traefik, which is used to receive HTTP traffic.
  • This configuration defines the websecure entryPoint of Traefik, which is used to receive HTTPS traffic.
# Validate values before installing:
helm show values traefik/traefik > default-values.yaml

   web:
     enabled: true
     asDefault: 
     port: 8000
     expose:
       default: true
     exposedPort: 80
   websecure:
     enabled: true
     port: 8443
     hostPort:  
     containerPort: 
     expose:
       default: true
     exposedPort: 443
Enter fullscreen mode Exit fullscreen mode

It configures two different components:

  • Traefik LoadBalancer Service: which port is exposed externally. 80, 443
  • Traefik Pod: which port the Traefik process listens on 8000 , 8443
  • 80=> 8000, 443 => 8443

Keep the chart's default entryPoints:

  • web -> container port 8000, Service port 80
  • websecure -> container port 8443, Service port 443

Traefik runs as non-root (UID 65532), so by default it does not bind 80/443 inside the pod:

  • Traefik runs as a non-root user for security reasons.
  • The chart splits this across the pod-level and container-level security contexts (chart defaults):
podSecurityContext:        # Pod level: which user/group the processes run as
  runAsNonRoot: true
  runAsUser: 65532
  runAsGroup: 65532
  seccompProfile:
    type: RuntimeDefault

securityContext:           # Container level: what the process is allowed to do
  allowPrivilegeEscalation: false
  capabilities:
    drop: [ALL]
  readOnlyRootFilesystem: true
Enter fullscreen mode Exit fullscreen mode

If someone compromises the Traefik process, running as a non-root user with no capabilities limits what they can do.

Why can't it use ports 80 and 443?
Traditionally, Linux divides ports into privileged and unprivileged ports.

  • Privilege Ports: 0:1023
  • Unprivilege Ports: 1024:65535

Binding means that a process opens a network socket on a particular port to receive connections.
The client still uses standard ports 80 and 443, while Traefik listens on unprivileged ports 8000 and 8443

Can Traefik bind to ports 80 and 443 without running as root?
Not just by adding a capability. NET_BIND_SERVICE is the capability that allows binding privileged ports, but Kubernetes does not set ambient capabilities: a capability added in securityContext only becomes effective for a process running as root (UID 0). A non-root process like UID 65532 does not get it, so this alone does not work:

securityContext:
  capabilities:
    drop: [ALL]
    add: [NET_BIND_SERVICE]   # Ignored for a non-root user (UID 65532)
Enter fullscreen mode Exit fullscreen mode

Options if you really need 80/443 inside the pod:

  • Run as root but with only that capability (runAsNonRoot: false, runAsUser: 0, drop: [ALL], add: [NET_BIND_SERVICE]). This is the pattern Traefik's own examples use, e.g. for hostNetwork.
  • Lower the privileged-port boundary with the pod sysctl net.ipv4.ip_unprivileged_port_start=0. Some newer container runtimes set this by default, in which case a non-root process can already bind port 80. Check your runtime's documentation.

The usual answer is neither: keep the unprivileged ports 8000/8443 and let the Service map 80/443 to them.

Important

Gateway listener ports = Traefik entryPoint ports
A Gateway listener's port must match the container port of a Traefik entryPoint (8000 / 8443), not the public Service port (80 / 443).
The LoadBalancer Service maps 80 -> 8000 and 443 -> 8443. If the listener uses 80/443, the Gateway is not programmed and requests return 404.

Client
  |
  | Port 80 / 443
  v
Network LoadBalancer
  |
  v
Traefik Service
  |
  | Port 8000 / 8443
  v
Traefik Pod
  |
  |-- EntryPoint
  |-- Gateway listener configuration
  |-- HTTPRoute matching
  |
  v
NGINX Service / Endpoints
  |
  | Port 80
  v
NGINX Pod
Enter fullscreen mode Exit fullscreen mode
flowchart TD
    Client("Client / Browser")

    LB("Network LoadBalancer")

    Service("Traefik Service<br/>80 → 8000 | 443 → 8443")

    Client -->|"1. HTTP :80"| LB
    Client -->|"3. HTTPS :443"| LB

    LB --- Service

    subgraph Traefik["Traefik Pod"]
        direction TB

        HTTP("HTTP listener<br/>8000")
        HTTPS("HTTPS listener<br/>8443 · TLS")

        Redirect("<b>Redirect Route</b><br/>301 Redirect<br/>No backend")

        Route("<b>NGINX Route</b><br/>Match host / path<br/>Forward to backend")

        HTTP --- Redirect
        HTTPS --- Route
    end

    Service --> HTTP
    Service --> HTTPS

    Redirect -.->|"2. Return 301 to client"| Client

    Route --> Nginx("NGINX Service :80")

    %% Component styles
    classDef neutral fill:#eef0f2,stroke:#94a3b8,color:#111,stroke-width:1.5px
    classDef http fill:#f5ece0,stroke:#d97706,color:#111,stroke-width:1.5px
    classDef https fill:#e5f3eb,stroke:#16a34a,color:#111,stroke-width:1.5px

    class Client,LB,Service neutral
    class HTTP,Redirect http
    class HTTPS,Route,Nginx https

    %% Traefik container
    style Traefik fill:transparent,stroke:#94a3b8,stroke-width:1.5px,stroke-dasharray:5 5

    %% Arrow styles
    linkStyle 1 stroke:#16a34a,color:#16a34a,stroke-width:2px
    linkStyle 7 stroke:#d97706,color:#d97706,stroke-width:2px,stroke-dasharray:5 5
    linkStyle 8 stroke:#16a34a,stroke-width:2px
TRAEFIK_CHART_VERSION=43.0.0   # Traefik v3.8.0

# Validate the values against the chart schema before installing
helm template traefik traefik/traefik \
  --version "${TRAEFIK_CHART_VERSION}" \
  -f traefik-values.yaml > /dev/null

helm upgrade --install traefik traefik/traefik \
  --version "${TRAEFIK_CHART_VERSION}" \
  --namespace traefik --create-namespace \
  -f traefik-values.yaml --wait

kubectl get pods,svc -n traefik
Enter fullscreen mode Exit fullscreen mode

6. Install cert-manager

helm repo add jetstack https://charts.jetstack.io
helm repo update
Enter fullscreen mode Exit fullscreen mode

cert-manager-values.yaml

crds:
  enabled: true

config:
  apiVersion: controller.config.cert-manager.io/v1alpha1
  kind: ControllerConfiguration
  gatewayAPI:
    enabled: true
Enter fullscreen mode Exit fullscreen mode
helm upgrade --install cert-manager jetstack/cert-manager \
  --version v1.21.3 \
  --namespace cert-manager --create-namespace \
  -f cert-manager-values.yaml --wait

kubectl get pods -n cert-manager
NAME                                       READY   STATUS    RESTARTS   AGE
cert-manager-78dd6bb79c-2vjz4              1/1     Running   0          17m
cert-manager-cainjector-557444dc8d-grgfz   1/1     Running   0          17m
cert-manager-webhook-bf7f8b575-jxnzv       1/1     Running   0          17m
Enter fullscreen mode Exit fullscreen mode

7. Application namespace

namespace.yaml

apiVersion: v1
kind: Namespace
metadata:
  name: apps
Enter fullscreen mode Exit fullscreen mode
kubectl apply -f namespace.yaml
Enter fullscreen mode Exit fullscreen mode
  • traefik: controller, LoadBalancer, Gateway, Certificate and TLS Secret.
  • cert-manager: certificate controller, webhook and CA injector.
  • apps: NGINX Deployment, Service and HTTPRoutes.

8. GatewayClass

gateway-class.yaml

It is a configuration resource that specifies which controller should manage a Gateway.

apiVersion: gateway.networking.k8s.io/v1
kind: GatewayClass
metadata:
  name: traefik
spec:
  controllerName: traefik.io/gateway-controller
Enter fullscreen mode Exit fullscreen mode
  • GatewayClass: Identifies the responsible controller.
  • Traefik: The actual controller running inside Kubernetes Pods.
  • Gateway: Defines listeners, ports, protocols and TLS configuration.
  • HTTPRoute: Defines routing rules
kubectl apply -f gateway-class.yaml
kubectl get gatewayclass
NAME      CONTROLLER                      ACCEPTED   AGE
traefik   traefik.io/gateway-controller   True       15m
Enter fullscreen mode Exit fullscreen mode

The GatewayClass is cluster-scoped and selects the controller that implements the Gateway.

9. Gateway

gateway.yaml

  • This file creates a Gateway resource that tells Traefik how to handle traffic after it arrives at the Traefik Pod. - defines how Traefik accepts incoming traffic and which HTTPRoutes are allowed to handle that traffic.
  • It has three main responsibilities:
    • Select the Gateway controller.
    • Configure HTTP and HTTPS listeners.
    • Configure TLS termination and route attachment permissions.
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
  name: public-gateway
  namespace: traefik # Where the Gateway resource exists
  # HTTPRoutes reference this Gateway by name (public-gateway) and namespace (traefik).
spec:
  gatewayClassName: traefik # Selects the controller responsible for implementing the Gateway.
  # Gateway: public-gateway
  #       ↓
  # GatewayClass: traefik
  #       ↓
  # Controller: traefik.io/gateway-controller
  #       ↓
  # Traefik Pods
  listeners: # A listener defines an entry point through which the Gateway accepts traffic.
    # HTTP listener: handles traffic arriving at Traefik's internal port 8000.
    - name: http
      protocol: HTTP
      port: 8000 # Traefik "web" entryPoint (public port 80)
      # Client :80
      #     ↓
      # Network LoadBalancer :80
      #     ↓
      # Traefik Service :80
      #     ↓
      # Traefik Pod :8000
      #     ↓
      # Gateway HTTP listener configuration
      # The Gateway does not perform port mapping. The Kubernetes Service already handles that.
      allowedRoutes: # Which namespaces are permitted to attach HTTPRoutes to this listener.
        namespaces:
          from: All
          # All: Accept routes from all namespaces
          # Same: Accept routes from the Gateway's namespace only
          # Selector: Accept routes from namespaces matching specific labels

    # HTTPS listener: handles TLS connections arriving at port 8443 for the specified hostname.
    - name: https
      protocol: HTTPS
      port: 8443 # Traefik "websecure" entryPoint (public port 443)
      hostname: nginx.example.com # Restrict the listener to one domain
      # The HTTP listener has no hostname: it is a shared entry point and the HTTPRoute decides
      # which hostname to handle. The HTTPS listener is dedicated to one domain and its TLS certificate.
      # Client :443
      #     ↓
      # Network LoadBalancer :443
      #     ↓
      # Traefik Service :443
      #     ↓
      # Traefik Pod :8443
      #     ↓
      # Gateway HTTPS listener configuration
      tls: # Terminate HTTPS using the certificate and private key stored in the nginx-tls Secret.
        mode: Terminate # Terminate TLS at Traefik; traffic to the backend is plain HTTP
        certificateRefs:
          - group: "" # Kubernetes core API group
            kind: Secret # Resource kind that holds the certificate
            name: nginx-tls # Secret containing tls.crt and tls.key (created by cert-manager)
      allowedRoutes:
        namespaces:
          from: All
Enter fullscreen mode Exit fullscreen mode
kubectl apply -f gateway.yaml

kubectl get gateway -n traefik
NAME             CLASS     ADDRESS          PROGRAMMED   AGE
public-gateway   traefik   174.138.110.27   True         12m
# Pass if: PROGRAMMED is True and ADDRESS matches the Load Balancer IP from step 3.

kubectl describe gateway public-gateway -n traefik
Enter fullscreen mode Exit fullscreen mode

10. Configure DNS

kubectl get svc traefik -n traefik
dig +short nginx.example.com
# Pass if: the IP matches the Load Balancer EXTERNAL-IP from step 3.
Enter fullscreen mode Exit fullscreen mode

11. Let's Encrypt ClusterIssuer

cluster-issuer.yaml

apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
  name: letsencrypt-prod
spec:
  acme:
    email: admin@example.com
    server: https://acme-v02.api.letsencrypt.org/directory
    privateKeySecretRef:
      name: letsencrypt-prod-account-key
    solvers:
      - http01:
          gatewayHTTPRoute:
            serviceType: ClusterIP
            parentRefs:
              - name: public-gateway
                namespace: traefik
                kind: Gateway
                sectionName: http
Enter fullscreen mode Exit fullscreen mode
kubectl apply -f cluster-issuer.yaml
kubectl get clusterissuer
NAME               READY   AGE
letsencrypt-prod   True    11m
Enter fullscreen mode Exit fullscreen mode

12. Request TLS certificate

certificate.yaml

apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
  name: nginx-certificate
  namespace: traefik
spec:
  secretName: nginx-tls
  issuerRef:
    name: letsencrypt-prod
    kind: ClusterIssuer
    group: cert-manager.io
  dnsNames:
    - nginx.example.com
  privateKey:
    algorithm: RSA
    size: 2048
    rotationPolicy: Always
Enter fullscreen mode Exit fullscreen mode
kubectl apply -f certificate.yaml
kubectl get certificate,certificaterequest,order,challenge -n traefik
kubectl wait --for=condition=Ready certificate/nginx-certificate \
  -n traefik --timeout=300s
kubectl get secret nginx-tls -n traefik
Enter fullscreen mode Exit fullscreen mode

Certificate lifecycle

  1. Certificate declares the domain and issuer.
  2. cert-manager creates a CertificateRequest and ACME Order.
  3. Let's Encrypt requests proof of domain ownership.
  4. cert-manager creates a temporary HTTPRoute, Service and solver Pod.
  5. Let's Encrypt validates /.well-known/acme-challenge/... through Traefik.
  6. cert-manager stores the certificate and key in nginx-tls (tls.crt and tls.key).
  7. Traefik reads the TLS Secret and serves HTTPS.
  8. cert-manager automatically renews the certificate.

13. NGINX Deployment

nginx-deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
  namespace: apps
spec:
  replicas: 2
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
        - name: nginx
          image: nginx:stable-alpine
          ports:
            - name: http
              containerPort: 80
          resources:
            requests:
              cpu: 100m
              memory: 64Mi
            limits:
              cpu: 250m
              memory: 128Mi
          readinessProbe:
            httpGet:
              path: /
              port: http
            initialDelaySeconds: 2
            periodSeconds: 5
          livenessProbe:
            httpGet:
              path: /
              port: http
            initialDelaySeconds: 5
            periodSeconds: 10
Enter fullscreen mode Exit fullscreen mode
kubectl apply -f nginx-deployment.yaml
kubectl rollout status deployment/nginx -n apps
Enter fullscreen mode Exit fullscreen mode

14. NGINX Service

nginx-service.yaml

apiVersion: v1
kind: Service
metadata:
  name: nginx-service
  namespace: apps
spec:
  type: ClusterIP
  selector:
    app: nginx
  ports:
    - name: http
      port: 80
      targetPort: http
      protocol: TCP
Enter fullscreen mode Exit fullscreen mode
kubectl apply -f nginx-service.yaml
Enter fullscreen mode Exit fullscreen mode

NGINX is internal. Traefik is the public entry point.

15. HTTPRoute

nginx-route.yaml

  • This file defines an HTTPRoute, which is responsible for making routing decisions inside Traefik.
  • While the Gateway defines how to accept traffic, the HTTPRoute defines what to do with that traffic and where to forward it.
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: nginx-route
  namespace: apps
spec:
  parentRefs: # Connects this HTTPRoute to a specific Gateway listener.
    - name: public-gateway # Gateway resource name
      namespace: traefik # Gateway namespace (cross-namespace attachment is allowed by the Gateway's allowedRoutes)
      sectionName: https # Name of the Gateway listener
  hostnames:
    - nginx.example.com # This route handles requests for nginx.example.com.
  rules:
    - matches:
        - path: # After matching the hostname, Traefik checks the request path.
            type: PathPrefix
            value: / # Matches all URL paths: /, /products, /api/users, etc.
      backendRefs:
        - name: nginx-service
          port: 80
      # Example: split traffic across multiple backends with weights (relative proportions):
      # backendRefs:
      #   - name: nginx-v1-service
      #     port: 80
      #     weight: 80
      #   - name: nginx-v2-service
      #     port: 80
      #     weight: 20
Enter fullscreen mode Exit fullscreen mode

Remember the configuration in gateway.yaml:

allowedRoutes:
  namespaces:
    from: All
Enter fullscreen mode Exit fullscreen mode

This allows the HTTPRoute from the apps namespace to attach to the Gateway in the traefik namespace.

Why specify the hostname in both Gateway and HTTPRoute?

Gateway hostname HTTPRoute hostname
Restricts which hostname the listener handles Restricts which hostname the route handles
Connection and listener configuration Application routing configuration

Note: The two hostnames must be compatible for the route to attach.

kubectl apply -f nginx-route.yaml
Enter fullscreen mode Exit fullscreen mode

HTTPS traffic is decrypted at the Gateway and forwarded to NGINX over HTTP. Cross-namespace route attachment is permitted by the Gateway's allowedRoutes configuration.

16. Redirect HTTP to HTTPS

https-redirect.yaml

Traefik returns an HTTP 301 response to the client, telling it to send a new HTTPS request on port 443
Traefik returns this response to the client:

HTTP/1.1 301 Moved Permanently
Location: https://nginx.example.com/products
Enter fullscreen mode Exit fullscreen mode

and Client sends a new HTTPS request: GET https://nginx.example.com/products, The redirect happens automatically. The user doesn't need to write https:// manually.

apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: nginx-https-redirect
  namespace: apps
spec:
  parentRefs:
    - name: public-gateway
      namespace: traefik
      sectionName: http
  hostnames:
    - nginx.example.com
  rules:
    - matches:
        - path:
            type: PathPrefix
            value: /
      filters:
        - type: RequestRedirect
          requestRedirect:
            scheme: https
            port: 443
            statusCode: 301
Enter fullscreen mode Exit fullscreen mode
kubectl apply -f https-redirect.yaml

kubectl get httproute -n apps
NAME                   HOSTNAMES                   AGE
nginx-https-redirect   ["<DNS>"]                  6m10s
nginx-route            ["<DNS>"]                  6m33s

kubectl get gateway public-gateway -n traefik \
  -o jsonpath='{range .status.listeners[*]}{.name}: attachedRoutes={.attachedRoutes} {range .conditions[*]}{.type}={.status} {end}{"\n"}{end}'
# Pass if: both listeners are all True and each has attachedRoutes=1. On the https listener, ResolvedRefs=True also means the nginx-tls secret was found.
http: attachedRoutes=1 Accepted=True ResolvedRefs=True Programmed=True
https: attachedRoutes=1 Accepted=True ResolvedRefs=True Programmed=True

kubectl get httproute -n apps \
  -o jsonpath='{range .items[*]}{.metadata.name}{": "}{range .status.parents[*].conditions[*]}{.type}={.status} {end}{"\n"}{end}'
# Pass if: both routes are Accepted=True (attached to the Gateway) and ResolvedRefs=True (nginx-service was found).
nginx-https-redirect: Accepted=True ResolvedRefs=True
nginx-route: Accepted=True ResolvedRefs=True
Enter fullscreen mode Exit fullscreen mode

Use an HTTPRoute redirect rather than a global entryPoint redirect so the more specific ACME challenge route can take precedence during renewal.

Why redirect to port 443 instead of 8443?
Because the redirect instructs the external client, not the internal Traefik process.

Port Responsibility
80 Public HTTP port
8000 Internal Traefik HTTP port
443 Public HTTPS port
8443 Internal Traefik HTTPS port

17. Test everything

kubectl get gateway -n traefik
kubectl get httproute -n apps
kubectl get certificate -n traefik

curl -I http://nginx.example.com
# Pass if: the status is 301 and Location is the https:// address with the same path (/test).
HTTP/1.1 301 Moved Permanently
Location: https://nginx.example.com:443/test
Date: Fri, 27 Nov 2026 11:43:07 GMT
Content-Length: 17

curl -sIL http://nginx.example.com | grep -E '^HTTP|^location'
HTTP/1.1 301 Moved Permanently
HTTP/2 200
# Pass if: you get a 301 followed by a 200.

curl -I https://nginx.example.com
# Pass if: the status is HTTP/2 200 without -k. That means curl trusted the certificate. server: nginx shows the response came from the app pods.
HTTP/2 200
accept-ranges: bytes
content-type: text/html
date: Fri, 27 Nov 2026 11:43:08 GMT
etag: "6b096bf9-1cc"
last-modified: Fri, 27 Nov 2026 11:39:37 GMT
server: nginx/1.30.8
content-length: 460

# Certificate served to clients
echo | openssl s_client -connect nginx.example.com:443 -servername nginx.example.com 2>/dev/null \
  | openssl x509 -noout -subject -issuer -dates
# This command connects to an HTTPS server and retrieves information about its SSL/TLS certificate, including who issued it and when it expires.
# Pass if: subject is your domain, issuer is Let’s Encrypt without (STAGING), and today is between notBefore and notAfter. cert-manager renews the certificate automatically about 30 days before it expires.
subject=CN=nginx.example.com
issuer=C=US, O=Let's Encrypt, CN=YR1
notBefore=Nov 27 10:34:54 2026 GMT
notAfter=Feb 25 10:34:53 2027 GMT

# subject: The certificate's subject, commonly containing the domain name.
# issuer: The Certificate Authority (CA).
# notBefore: When the certificate becomes valid.
# notAfter: When the certificate expires.
Enter fullscreen mode Exit fullscreen mode

18. Request flows

HTTPS:

flowchart TD
    A[HTTPS client] --> B[LoadBalancer 443]
    B --> C[Gateway HTTPS listener: TLS termination]
    C --> D[NGINX HTTPRoute]
    D --> E[NGINX Service 80]
    E --> F[NGINX Pods]

HTTP:

flowchart TD
    A[HTTP client] --> B[LoadBalancer 80]
    B --> C[Gateway HTTP listener]
    C --> D[Redirect HTTPRoute]
    D --> E[301 HTTPS redirect]

Request a Certificate:

flowchart TD
    A[Let's Encrypt] --> B[LoadBalancer 80]
    B --> C[Gateway HTTP listener]
    C --> D[Temporary ACME HTTPRoute]
    D --> E[Solver Service]
    E --> F[Solver Pod]

19. Troubleshooting

Problem Possible reason
helm install fails: additional properties ... not allowed Invalid chart value keys; validate with helm template
Traefik CrashLoopBackOff: bind: permission denied EntryPoint set to port 80/443 while running as non-root (depends on the runtime's ip_unprivileged_port_start)
External IP pending No LoadBalancer implementation (or K3s built-in Traefik holds 80/443)
Gateway not accepted / listeners not programmed GatewayClass controllerName wrong, or listener port ≠ entryPoint port (8000/8443)
Challenge pending, no solver HTTPRoute created cert-manager Gateway API support not enabled, or Gateway CRDs installed after cert-manager (restart it)
Certificate not ready DNS, firewall or ACME challenge failure
404 HTTPRoute hostname or parentRefs mismatch
503 Backend Service has no ready endpoints
Invalid TLS certificate Missing Secret, wrong hostname or staging issuer
HTTPRoute not accepted Namespace restrictions
kubectl describe gateway public-gateway -n traefik
kubectl describe httproute nginx-route -n apps
kubectl describe certificate nginx-certificate -n traefik
kubectl get certificaterequests,orders,challenges -A
kubectl logs -n cert-manager deployment/cert-manager
kubectl logs -n traefik deployment/traefik --tail=100
kubectl get endpointslices -n apps -l kubernetes.io/service-name=nginx-service
Enter fullscreen mode Exit fullscreen mode

Check Accepted, ResolvedRefs, Programmed (Gateway), and Ready (Certificate) conditions as appropriate.

20. Gateway API vs Ingress

Feature Ingress Gateway API
Controller selection IngressClass GatewayClass
Entry point Controller configuration Gateway
Routing Ingress HTTPRoute
TLS configuration Ingress Gateway
Redirect Controller-specific RequestRedirect
Traffic splitting Controller-specific Backend weights
Cross-namespace routes Limited Explicit access controls
gRPC Controller-specific GRPCRoute

Top comments (0)