Lesson 11 Gateway API
Theme:

Homework

Apply what you learned about Gateway API by building Helm templates for real-world routing scenarios.

Task 1

Helm-Templated Gateway and HTTPRoute

Create a Helm chart called gateway-app that templates a Gateway and an HTTPRoute as separate resources in the templates/ directory. The chart should support the following values.yaml structure:

gateway:
  enabled: true
  className: envoy
  listeners:
    - name: http
      port: 80
      protocol: HTTP
    - name: https
      port: 443
      protocol: HTTPS
      tls:
        mode: Terminate
        certificateRef: wildcard-cert

httproute:
  enabled: true
  hostnames:
    - "app.example.com"
  rules:
    - path: /api
      serviceName: api-svc
      servicePort: 8080
    - path: /
      serviceName: frontend-svc
      servicePort: 80

Requirements:

Self-Check

  • helm template gateway-app ./gateway-app renders valid YAML with no errors.
  • Setting gateway.enabled=false suppresses the Gateway resource entirely.
  • The HTTPS listener includes a tls section; the HTTP listener does not.
  • Each rule in the HTTPRoute has type: PathPrefix and correct backendRefs.
  • helm template output passes kubectl apply --dry-run=server against a cluster with Gateway API CRDs installed.
Task 2

HTTPRoute with Filters

Extend the chart from Task 1 (or create a new one) to support HTTPRoute filters. Add the following capabilities to the values.yaml:

httproute:
  enabled: true
  hostnames:
    - "shop.example.com"
  rules:
    - path: /old-api
      filters:
        - type: RequestRedirect
          requestRedirect:
            scheme: https
            hostname: shop.example.com
            path:
              type: ReplacePrefixMatch
              replacePrefixMatch: /api/v2
            statusCode: 301
    - path: /api
      filters:
        - type: RequestHeaderModifier
          requestHeaderModifier:
            set:
              - name: x-request-id
                value: "{{ .Release.Name }}"
            add:
              - name: x-forwarded-prefix
                value: /api
      serviceName: api-svc
      servicePort: 8080

Requirements:

Self-Check

  • The redirect rule renders RequestRedirect filter with no backendRefs.
  • The API rule renders both the RequestHeaderModifier filter and a backendRefs entry.
  • Adding a new filter type (e.g., URLRewrite) to values.yaml works without changing the template.
  • helm lint ./gateway-app passes with no errors or warnings.
Task 3

ReferenceGrant for Cross-Namespace Routing

Create a Helm template for a ReferenceGrant that allows HTTPRoutes in specified source namespaces to reference Services in the chart's release namespace. Support the following values:

referenceGrant:
  enabled: true
  grants:
    - name: allow-frontend
      fromNamespaces:
        - frontend
        - staging-frontend
      toKinds:
        - group: ""
          kind: Service
    - name: allow-monitoring
      fromNamespaces:
        - monitoring
      toKinds:
        - group: ""
          kind: Service
        - group: ""
          kind: Secret

Requirements:

Self-Check

  • helm template produces two separate ReferenceGrant resources (one per grant).
  • The allow-frontend grant has two from entries (frontend and staging-frontend).
  • The allow-monitoring grant has two to entries (Service and Secret).
  • All ReferenceGrants use apiVersion: gateway.networking.k8s.io/v1beta1.
  • Disabling referenceGrant.enabled suppresses all ReferenceGrant resources.

Grading Rubric

CriterionPointsDescription
Task 1 — Gateway template15Conditional TLS block, listener iteration, proper gating
Task 1 — HTTPRoute template15Rule iteration, PathPrefix matches, correct backendRefs
Task 2 — Filter support20Conditional filters section, redirect without backendRefs, toYaml passthrough
Task 3 — ReferenceGrant20Multiple grants via range, from/to iteration, correct apiVersion
Helm best practices15Named templates for labels/fullname, consistent metadata, lint passes
Validation15All templates pass helm template and kubectl dry-run, toggle flags work

Bonus challenge: Add a dualStack toggle to your values that, when enabled, templates both an Ingress resource and a Gateway API HTTPRoute from the same values. This mirrors the real-world migration pattern where teams run both side by side during the transition from Ingress to Gateway API.