Skip to content
Hands-on IT IT Drills

Day 11: TLS for the Gateway API

Goal: You build your own CA with cert-manager, terminate HTTPS at the Gateway for several hostnames, redirect HTTP to HTTPS, renew certificates while running and also encrypt the path from the Gateway to the backend. · Duration: approx. 90 min · Prerequisite: Day 10 (Gateway API CRDs, controller on)

Briefing

  • CKNE: Advanced Traffic Management – Gateway API with TLS; plus Network Security (encryption on the way to the backend).
  • An HTTPS listener points via certificateRefs to a Secret of type kubernetes.io/tls. The Gateway doesn’t care where it comes from – here from cert-manager.
  • cert-manager chain: selfSigned issuer → CA certificate → ca issuer → any number of server certificates.
  • Cilium copies used Secrets into the namespace cilium-secrets, Envoy reloads them without a restart.
 curl (SNI shop/api) ──TLS──> Gateway web :443 ──HTTP──> echo:8080
                    └─HTTP──> Gateway web :80  ──301──> https://…
                                    :443 /secure ──TLS (BackendTLSPolicy)──> secure:443
 ClusterIssuer tag11-selfsigned ─> Certificate lab-ca ─> ClusterIssuer tag11-ca
                                                          └─> shop-tls, api-tls, …

Drill 1: Install cert-manager

The current release is cert-manager v1.21.3. The chart is an OCI artifact; the Gateway API integration is a configuration switch of the controller:

mkdir -p ~/ckne/tag11 && cd ~/ckne/tag11
helm install cert-manager oci://quay.io/jetstack/charts/cert-manager \
  --version v1.21.3 -n cert-manager --create-namespace \
  --set crds.enabled=true \
  --set config.apiVersion=controller.config.cert-manager.io/v1alpha1 \
  --set config.kind=ControllerConfiguration \
  --set config.gatewayAPI.enabled=true
k -n cert-manager rollout status deploy
k -n cert-manager get pods
k -n cert-manager logs deploy/cert-manager | grep -o '"enabling the sig-network.*"'

Expected (abridged):

Pulled: quay.io/jetstack/charts/cert-manager:v1.21.3
STATUS: deployed
deployment "cert-manager" successfully rolled out
deployment "cert-manager-cainjector" successfully rolled out
deployment "cert-manager-webhook" successfully rolled out
NAME                                       READY   STATUS    RESTARTS   AGE
cert-manager-78dd6bb79c-vbnml              1/1     Running   0          20s
cert-manager-cainjector-557444dc8d-8cv8s   1/1     Running   0          20s
cert-manager-webhook-bf7f8b575-4wt5m       1/1     Running   0          20s
"enabling the sig-network Gateway API certificate-shim and HTTP-01 solver" logger="cert-
manager"

Plus the CLI cmctl (renewal, status) – as a single binary per architecture:

ARCH=$(dpkg --print-architecture)
CM=https://github.com/cert-manager/cmctl/releases/download/v2.6.2
curl -fsSLO $CM/cmctl_linux_${ARCH}
curl -fsSL $CM/checksums.txt | grep " cmctl_linux_${ARCH}$" | sha256sum -c
sudo install -m 0755 cmctl_linux_${ARCH} /usr/local/bin/cmctl
cmctl check api

Expected:

cmctl_linux_amd64: OK
The cert-manager API is ready

Save your progress? Sign up for free

Drill 2: Your own CA

A selfSigned issuer only signs itself – exactly right for the one CA certificate. A ClusterIssuer reads Secrets from the namespace cert-manager, which is why the CA lives there:

k create namespace tag11
k config set-context --current --namespace=tag11
cat > ca.yaml <<'EOF'
apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
  name: tag11-selfsigned
spec:
  selfSigned: {}
---
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
  name: lab-ca
  namespace: cert-manager
spec:
  isCA: true
  commonName: CKNE Lab CA
  secretName: lab-ca
  duration: 87600h
  privateKey:
    algorithm: ECDSA
    size: 256
  issuerRef:
    name: tag11-selfsigned
    kind: ClusterIssuer
---
apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
  name: tag11-ca
spec:
  ca:
    secretName: lab-ca
EOF
k apply -f ca.yaml
k -n cert-manager wait --for=condition=Ready certificate lab-ca
k get clusterissuer
k -n cert-manager get secret lab-ca -o jsonpath='{.data.tls\.crt}' | base64 -d \
  | openssl x509 -noout -subject -issuer -enddate

Expected:

clusterissuer.cert-manager.io/tag11-selfsigned created
certificate.cert-manager.io/lab-ca created
clusterissuer.cert-manager.io/tag11-ca created
certificate.cert-manager.io/lab-ca condition met
NAME               READY   AGE
tag11-ca           True    0s
tag11-selfsigned   True    0s
subject=CN = CKNE Lab CA
issuer=CN = CKNE Lab CA
notAfter=Nov 15 23:54:08 2036 GMT

Subject equals issuer: self-signed, valid for ten years.

Save your progress? Sign up for free

Drill 3: Certificate and HTTPS listener

Backend and NodePort GatewayClass as on Day 10 (reasoning there):

cp ~/ckne/tag10/echo.yaml .
k apply -f echo.yaml
k expose deployment echo-v1 --name=echo --port=8080 --target-port=3000
cat > nodeport.yaml <<'EOF'
apiVersion: cilium.io/v2alpha1
kind: CiliumGatewayClassConfig
metadata:
  name: nodeport
spec:
  service:
    type: NodePort
---
apiVersion: gateway.networking.k8s.io/v1
kind: GatewayClass
metadata:
  name: tag11-nodeport
spec:
  controllerName: io.cilium/gateway-controller
  parametersRef:
    group: cilium.io
    kind: CiliumGatewayClassConfig
    name: nodeport
    namespace: tag11
EOF
k apply -f nodeport.yaml

The server certificate – deliberately short-lived so that Drill 6 has something to renew:

cat > cert-shop.yaml <<'EOF'
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
  name: shop
spec:
  secretName: shop-tls
  dnsNames:
  - shop.example.com
  duration: 24h
  renewBefore: 8h
  issuerRef:
    name: tag11-ca
    kind: ClusterIssuer
EOF
k apply -f cert-shop.yaml
k wait --for=condition=Ready certificate shop
k get certificate,certificaterequest
k get secret shop-tls -o jsonpath='{.data.tls\.crt}' | base64 -d \
  | openssl x509 -noout -issuer -ext subjectAltName -dates

Expected (abridged):

certificate.cert-manager.io/shop condition met
NAME                               READY   SECRET     AGE
certificate.cert-manager.io/shop   True    shop-tls   1s
NAME                                        APPROVED   DENIED   READY   ISSUER     ...
certificaterequest.cert-manager.io/shop-1   True                True    tag11-ca   ...
issuer=CN = CKNE Lab CA
X509v3 Subject Alternative Name: critical
    DNS:shop.example.com
notBefore=Nov 18 23:54:33 2026 GMT
notAfter=Nov 19 23:54:33 2026 GMT

Now the Gateway with two listeners. tls.mode: Terminate means: Envoy decrypts, the backend sees HTTP. The route attaches via sectionName to the HTTPS listener only:

cat > gw.yaml <<'EOF'
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
  name: web
spec:
  gatewayClassName: tag11-nodeport
  listeners:
  - name: http
    protocol: HTTP
    port: 80
  - name: https-shop
    protocol: HTTPS
    port: 443
    hostname: shop.example.com
    tls:
      mode: Terminate
      certificateRefs:
      - name: shop-tls
EOF
cat > route-shop.yaml <<'EOF'
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: shop
spec:
  parentRefs:
  - name: web
    sectionName: https-shop
  hostnames:
  - shop.example.com
  rules:
  - backendRefs:
    - name: echo
      port: 8080
EOF
k apply -f gw.yaml -f route-shop.yaml
k wait --for=condition=Programmed gateway web
k get svc cilium-gateway-web
k -n cilium-secrets get secrets

Expected (abridged):

gateway.gateway.networking.k8s.io/web condition met
NAME                 TYPE       CLUSTER-IP     EXTERNAL-IP   PORT(S)
cilium-gateway-web   NodePort   10.103.44.25   <none>        80:32739/TCP,443:31589/TCP
NAME                                                    TYPE                DATA   AGE
cilium-sync-secret-1b5fe3bec1b1e9fc34e4350baee3d9c...   kubernetes.io/tls   3      2s

Testing with SNI: --resolve makes curl resolve shop.example.com to the node IP and send the name in the TLS handshake. The CA certificate is in ca.crt of every issued Secret:

NPS=$(k get svc cilium-gateway-web -o jsonpath='{.spec.ports[?(@.port==443)].nodePort}')
NPH=$(k get svc cilium-gateway-web -o jsonpath='{.spec.ports[?(@.port==80)].nodePort}')
k get secret shop-tls -o jsonpath='{.data.ca\.crt}' | base64 -d > ca.crt
R="--resolve shop.example.com:$NPS:172.16.0.228"
curl -s $R https://shop.example.com:$NPS/; echo "exit=$?"
curl -s $R --cacert ca.crt https://shop.example.com:$NPS/ | grep -E '"(host|pod)"'
curl -sv $R --cacert ca.crt https://shop.example.com:$NPS/ -o /dev/null 2>&1 \
  | grep -E 'SSL connection|subjectAltName|issuer:'

Expected:

exit=60
 "host": "shop.example.com:31589",
 "pod": "echo-v1-5dbcd994f5-rxm7p"
* SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384 / X25519 / RSASSA-PSS
*  subjectAltName: host "shop.example.com" matched cert's "shop.example.com"
*  issuer: CN=CKNE Lab CA

Exit 60 means: the certificate cannot be verified – curl doesn’t know the lab CA. With --cacert the chain works.

Save your progress? Sign up for free

Drill 4: Redirect HTTP to HTTPS

curl -s -o /dev/null -w '%{http_code}\n' -H 'Host: shop.example.com' \
  http://172.16.0.228:$NPH/
cat > route-redirect.yaml <<'EOF'
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: to-https
spec:
  parentRefs:
  - name: web
    sectionName: http
  rules:
  - filters:
    - type: RequestRedirect
      requestRedirect:
        scheme: https
        statusCode: 301
EOF
k apply -f route-redirect.yaml
curl -si -H 'Host: shop.example.com' http://172.16.0.228:$NPH/cart \
  | grep -iE '^HTTP|^location'

Expected:

404
httproute.gateway.networking.k8s.io/to-https created
HTTP/1.1 301 Moved Permanently
location: https://shop.example.com:443/cart

Without hostnames the redirect route applies to every host on the listener http. Path and host stay, only scheme and port change. In the lab you reach 443 only via the NodePort – with a real LB IP (Day 15) curl -L follows directly.

Save your progress? Sign up for free

Drill 5: Several hostnames via SNI

A second certificate, a second HTTPS listener on the same port 443 – Envoy picks the certificate based on the SNI name:

sed -e 's/name: shop$/name: api/' -e 's/shop-tls/api-tls/' \
  -e 's/shop.example.com/api.example.com/' cert-shop.yaml > cert-api.yaml
cat >> gw.yaml <<'EOF'
  - name: https-api
    protocol: HTTPS
    port: 443
    hostname: api.example.com
    tls:
      mode: Terminate
      certificateRefs:
      - name: api-tls
EOF
sed -e 's/name: shop$/name: api/' -e 's/https-shop/https-api/' \
  -e 's/shop.example.com/api.example.com/' route-shop.yaml > route-api.yaml
k apply -f cert-api.yaml -f gw.yaml -f route-api.yaml
k wait --for=condition=Ready certificate api
for h in shop api; do
  openssl s_client -connect 172.16.0.228:$NPS -servername $h.example.com \
    -CAfile ca.crt </dev/null 2>/dev/null | grep 'Verify return code'
  openssl s_client -connect 172.16.0.228:$NPS -servername $h.example.com \
    </dev/null 2>/dev/null | openssl x509 -noout -ext subjectAltName | tail -1
done
curl -sS --cacert ca.crt --resolve other.example.com:$NPS:172.16.0.228 \
  https://other.example.com:$NPS/; echo "exit=$?"

Expected:

certificate.cert-manager.io/api created
gateway.gateway.networking.k8s.io/web configured
httproute.gateway.networking.k8s.io/api created
certificate.cert-manager.io/api condition met
Verify return code: 0 (ok)
    DNS:shop.example.com
Verify return code: 0 (ok)
    DNS:api.example.com
curl: (35) Recv failure: Connection reset by peer
exit=35

An unknown SNI name matches no listener – Envoy aborts the handshake instead of presenting a wrong certificate. A wildcard certificate (*.example.com) on a listener without hostname would be the alternative.

Save your progress? Sign up for free

Drill 6: Renew a certificate

cert-manager renews on its own as soon as renewalTime is reached (expiry minus renewBefore). For tests or after a key leak, cmctl renew triggers it immediately:

k get certificate shop -o jsonpath='{.status.revision} {.status.renewalTime}{"\n"}'
openssl s_client -connect 172.16.0.228:$NPS -servername shop.example.com \
  </dev/null 2>/dev/null | openssl x509 -noout -serial
cmctl renew shop
k wait --for=condition=Ready certificate shop
k get certificaterequest
k get certificate shop -o jsonpath='{.status.revision}{"\n"}'
openssl s_client -connect 172.16.0.228:$NPS -servername shop.example.com \
  </dev/null 2>/dev/null | openssl x509 -noout -serial
cmctl status certificate shop | grep -E 'Generated|Requested'

Expected (abridged):

1 2026-11-19T15:54:33Z
serial=5085F82A41E8965AB8D3A22B3B1CFCBAE928D8CF
Manually triggered issuance of Certificate tag11/shop
certificate.cert-manager.io/shop condition met
NAME     APPROVED   DENIED   READY   ISSUER     ...
api-1    True                True    tag11-ca   ...
shop-2   True                True    tag11-ca   ...
2
serial=4405D4DC31312314DE1E8D98B782310D4FBADF12
  Normal  Generated  95s  cert-manager-certificates-key-manager      Stored new ...
  Normal  Requested  95s  cert-manager-certificates-request-manager  Created new ...
  Normal  Generated  17s  cert-manager-certificates-key-manager      Stored new ...
  Normal  Requested  17s  cert-manager-certificates-request-manager  Created new ...

New serial number, new private key (default rotationPolicy: Always), and Envoy serves the new certificate on the very next handshake – no restart, no dropped connections for existing clients.

Save your progress? Sign up for free

Drill 7: Wrong Secret, foreign namespace

First a typo in the Secret name on the listener https-shop (index 1):

LC='{range .status.listeners[*]}{.name}: {.conditions[?(@.type=="Programmed")].status}'\
' {.conditions[?(@.type=="ResolvedRefs")].reason}{"\n"}{end}'
k patch gateway web --type=json -p '[{"op":"replace",
 "path":"/spec/listeners/1/tls/certificateRefs/0/name","value":"shop-tsl"}]'
k get gateway web -o jsonpath="$LC"
k get gateway web
k get gateway web -o \
  jsonpath='{.status.listeners[1].conditions[?(@.type=="Accepted")].message}'
echo
curl -sS --cacert ca.crt $R https://shop.example.com:$NPS/ -o /dev/null; echo "exit=$?"
k patch gateway web --type=json -p '[{"op":"replace",
 "path":"/spec/listeners/1/tls/certificateRefs/0/name","value":"shop-tls"}]'

Expected:

gateway.gateway.networking.k8s.io/web patched
http: True ResolvedRefs
https-shop: False InvalidCertificateRef
https-api: True ResolvedRefs
NAME   CLASS            ADDRESS       PROGRAMMED   AGE
web    tag11-nodeport   172.16.0.83   True         2m12s
Listener not valid. Invalid CertificateRef, Secret "shop-tsl" not found
curl: (35) Recv failure: Connection reset by peer
exit=35
gateway.gateway.networking.k8s.io/web patched

Tricky: the Gateway as a whole stays PROGRAMMED True, only the one listener fails. Give the status a few seconds – right after the patch it still shows the old value. Now the certificate for api lives centrally in a namespace of its own:

k create namespace tag11-certs
k -n tag11-certs apply -f cert-api.yaml
k -n tag11-certs wait --for=condition=Ready certificate api
k patch gateway web --type=json -p '[{"op":"replace",
 "path":"/spec/listeners/2/tls/certificateRefs/0",
 "value":{"name":"api-tls","namespace":"tag11-certs"}}]'
k get gateway web -o jsonpath="$LC"
k get gateway web -o jsonpath='{.status.listeners[2].conditions[0].message}{"\n"}'

Expected:

namespace/tag11-certs created
certificate.cert-manager.io/api created
certificate.cert-manager.io/api condition met
gateway.gateway.networking.k8s.io/web patched
http: True ResolvedRefs
https-shop: True ResolvedRefs
https-api: False RefNotPermitted
CertificateRef is not permitted

As with routes to Services on Day 10: the namespace holding the Secret has to agree – this time for the kind Gateway and the target Secret:

cat > grant-secret.yaml <<'EOF'
apiVersion: gateway.networking.k8s.io/v1
kind: ReferenceGrant
metadata:
  name: tag11-gateway-secrets
  namespace: tag11-certs
spec:
  from:
  - group: gateway.networking.k8s.io
    kind: Gateway
    namespace: tag11
  to:
  - group: ""
    kind: Secret
EOF
k apply -f grant-secret.yaml
k get gateway web -o jsonpath="$LC"
curl -s --cacert ca.crt --resolve api.example.com:$NPS:172.16.0.228 \
  https://api.example.com:$NPS/ | grep '"host"'

Expected:

referencegrant.gateway.networking.k8s.io/tag11-gateway-secrets created
http: True ResolvedRefs
https-shop: True ResolvedRefs
https-api: True ResolvedRefs
 "host": "api.example.com:31589",

Save your progress? Sign up for free

Drill 8: BackendTLSPolicy – TLS all the way to the Pod

So far TLS ends at the Gateway, the last leg is plain text. Here is a backend that itself only speaks HTTPS (echo-basic with HTTPS_PORT), with a certificate for its Service name:

cat > secure.yaml <<'EOF'
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
  name: secure
spec:
  secretName: secure-tls
  dnsNames:
  - secure.tag11.svc
  issuerRef:
    name: tag11-ca
    kind: ClusterIssuer
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: secure
spec:
  selector:
    matchLabels: {app: secure}
  template:
    metadata:
      labels: {app: secure}
    spec:
      containers:
      - name: echo
        image: registry.k8s.io/gateway-api/echo-basic:v1.5.1
        env:
        - name: POD_NAME
          valueFrom: {fieldRef: {fieldPath: metadata.name}}
        - name: HTTPS_PORT
          value: "8443"
        - name: TLS_SERVER_CERT
          value: /tls/tls.crt
        - name: TLS_SERVER_PRIVKEY
          value: /tls/tls.key
        volumeMounts:
        - name: tls
          mountPath: /tls
      volumes:
      - name: tls
        secret:
          secretName: secure-tls
EOF
k apply -f secure.yaml
k expose deployment secure --port=443 --target-port=8443
k rollout status deployment secure
cat > route-secure.yaml <<'EOF'
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: secure
spec:
  parentRefs:
  - name: web
    sectionName: https-shop
  hostnames:
  - shop.example.com
  rules:
  - matches:
    - path:
        type: PathPrefix
        value: /secure
    backendRefs:
    - name: secure
      port: 443
EOF
k apply -f route-secure.yaml
curl -s -w ' %{http_code}\n' $R --cacert ca.crt https://shop.example.com:$NPS/secure

Expected:

deployment "secure" successfully rolled out
httproute.gateway.networking.k8s.io/secure created
Client sent an HTTP request to an HTTPS server.
 400

Envoy speaks plain text to a TLS port. The BackendTLSPolicy (in the Standard channel since Gateway API v1.4, Cilium 1.20 reports BackendTLSPolicy as a supported feature) tells it: TLS to the Service secure, verify the certificate against the lab CA, expected name secure.tag11.svc. The CA comes from a ConfigMap:

k create configmap lab-ca --from-file=ca.crt=ca.crt
cat > btls.yaml <<'EOF'
apiVersion: gateway.networking.k8s.io/v1
kind: BackendTLSPolicy
metadata:
  name: secure
spec:
  targetRefs:
  - group: ""
    kind: Service
    name: secure
  validation:
    caCertificateRefs:
    - group: ""
      kind: ConfigMap
      name: lab-ca
    hostname: secure.tag11.svc
EOF
k apply -f btls.yaml
k get backendtlspolicy secure -o jsonpath=\
'{range .status.ancestors[*].conditions[*]}{.type}={.status} {.reason}{"\n"}{end}'
curl -s $R --cacert ca.crt https://shop.example.com:$NPS/secure \
  | sed -n '/"tls"/,/}/p'

Expected:

configmap/lab-ca created
backendtlspolicy.gateway.networking.k8s.io/secure created
Accepted=True Accepted
ResolvedRefs=True ResolvedRefs
 "tls": {
  "version": "TLSv1.3",
  "serverName": "secure.tag11.svc",
  "negotiatedProtocol": "http/1.1",
  "cipherSuite": "TLS_AES_128_GCM_SHA256"
 }

The backend confirms: TLS 1.3, SNI secure.tag11.svc. Cross-check with a wrong expected name – Envoy then refuses the connection:

k patch backendtlspolicy secure --type=merge \
  -p '{"spec":{"validation":{"hostname":"falsch.tag11.svc"}}}'
curl -s -w ' %{http_code}\n' $R --cacert ca.crt https://shop.example.com:$NPS/secure
k patch backendtlspolicy secure --type=merge \
  -p '{"spec":{"validation":{"hostname":"secure.tag11.svc"}}}'

Expected:

backendtlspolicy.gateway.networking.k8s.io/secure patched
upstream connect error or disconnect/reset before headers. reset reason: remote
connection failure 503
backendtlspolicy.gateway.networking.k8s.io/secure patched

Save your progress? Sign up for free

Exercise: Speed Drills

  1. Issue a certificate docs for docs.example.com and www.docs.example.com via tag11-ca into the Secret docs-tls. Target time: 2 min
  2. Show expiry and next renewal time for all Certificates in tag11. Target time: 60 s
  3. Check which certificate (issuer, SAN, expiry) the Gateway serves for SNI api.example.com. Target time: 60 s
  4. Show for each listener of web whether it is Programmed and why. Target time: 60 s

Solution

cat > cert-docs.yaml <<'EOF'
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
  name: docs
spec:
  secretName: docs-tls
  dnsNames:
  - docs.example.com
  - www.docs.example.com
  issuerRef:
    name: tag11-ca
    kind: ClusterIssuer
EOF
k apply -f cert-docs.yaml
k wait --for=condition=Ready certificate docs
k get secret docs-tls -o jsonpath='{.data.tls\.crt}' | base64 -d \
  | openssl x509 -noout -ext subjectAltName
k get certificate -o custom-columns=\
NAME:.metadata.name,NOTAFTER:.status.notAfter,RENEW:.status.renewalTime
openssl s_client -connect 172.16.0.228:$NPS -servername api.example.com \
  </dev/null 2>/dev/null | openssl x509 -noout -issuer -ext subjectAltName -enddate
k get gateway web -o jsonpath="$LC"

Expected (abridged):

certificate.cert-manager.io/docs condition met
X509v3 Subject Alternative Name: critical
    DNS:docs.example.com, DNS:www.docs.example.com
NAME     NOTAFTER               RENEW
api      2026-11-19T23:55:13Z   2026-11-19T15:55:13Z
docs     2027-02-16T23:58:18Z   2027-01-17T23:58:18Z
secure   2027-02-16T23:57:11Z   2027-01-17T23:57:11Z
shop     2026-11-19T23:55:51Z   2026-11-19T15:55:51Z
issuer=CN = CKNE Lab CA
X509v3 Subject Alternative Name: critical
    DNS:api.example.com
notAfter=Nov 19 23:56:22 2026 GMT
http: True ResolvedRefs
https-shop: True ResolvedRefs
https-api: True ResolvedRefs

Without duration cert-manager issues for 90 days and renews after two thirds. The served api certificate comes from tag11-certs (Drill 7) – which is why its expiry differs from the Certificate of the same name in tag11.

Save your progress? Sign up for free

Checkpoint

k -n cert-manager get deploy

Expected: cert-manager, cert-manager-cainjector, cert-manager-webhook, all 1/1 – cert-manager stays installed for Day 21 (Round 6) and Appendix B (Task 9).

k get clusterissuer tag11-ca

Expected: READY True.

curl -s $R --cacert ca.crt https://shop.example.com:$NPS/ | grep '"pod"'

Expected: a Pod echo-v1-…, without certificate errors.

curl -si -H 'Host: shop.example.com' http://172.16.0.228:$NPH/ | head -1

Expected: HTTP/1.1 301 Moved Permanently.

k get backendtlspolicy secure -o jsonpath='{.status.ancestors[0].conditions[0].status}'

Expected: True.

Challenge

Let cert-manager create the certificate itself: a second Gateway auto with an HTTPS listener for auto.example.com should serve a valid lab CA certificate without a Certificate object of its own.

Hint: The Gateway API integration (Drill 1) reacts to the annotation cert-manager.io/cluster-issuer on the Gateway.

Solution

cat > gw-auto.yaml <<'EOF'
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
  name: auto
  annotations:
    cert-manager.io/cluster-issuer: tag11-ca
spec:
  gatewayClassName: tag11-nodeport
  listeners:
  - name: https
    protocol: HTTPS
    port: 443
    hostname: auto.example.com
    tls:
      mode: Terminate
      certificateRefs:
      - name: auto-tls
EOF
sed -e 's/name: shop$/name: auto/' -e 's/- name: web/- name: auto/' \
  -e 's/sectionName: https-shop/sectionName: https/' \
  -e 's/shop.example.com/auto.example.com/' route-shop.yaml > route-auto.yaml
k apply -f gw-auto.yaml -f route-auto.yaml
k wait --for=condition=Programmed gateway auto
k get certificate auto-tls -o jsonpath='{.metadata.ownerReferences[0].kind}/'\
'{.metadata.ownerReferences[0].name} {.spec.dnsNames}'
echo
NPA=$(k get svc cilium-gateway-auto -o jsonpath='{.spec.ports[0].nodePort}')
curl -s --cacert ca.crt --resolve auto.example.com:$NPA:172.16.0.228 \
  https://auto.example.com:$NPA/ | grep '"host"'

Expected:

gateway.gateway.networking.k8s.io/auto created
httproute.gateway.networking.k8s.io/auto created
gateway.gateway.networking.k8s.io/auto condition met
Gateway/auto ["auto.example.com"]
 "host": "auto.example.com:32488",

The Certificate auto-tls is owned by the Gateway (ownerReference) and takes the listener hostname as SAN. Don’t mix: a manually created Certificate for the same Secret and the annotation on the same Gateway fight over the Secret.

Save your progress? Sign up for free

Cleanup

k delete namespace tag11 tag11-certs
k delete gatewayclass tag11-nodeport
k delete clusterissuer tag11-ca tag11-selfsigned
k -n cert-manager delete certificate lab-ca
k -n cert-manager delete secret lab-ca
k config set-context --current --namespace=default

cert-manager (Helm release cert-manager) and cmctl stay for Day 21 (Round 6) and Appendix B (Task 9); so do the Gateway API CRDs and gatewayAPI.enabled=true (Day 18, Day 21 Round 6, Appendix B Tasks 8 and 9).

Exam Tip

  • HTTPS listeners need tls.certificateRefs (mode: Terminate is the default, writing it explicitly doesn’t hurt); a Secret in another namespace needs a ReferenceGrant there (kind: Gateway → Secret).
  • Read the status per listener (.status.listeners[*].conditions): the Gateway can be Programmed while one listener fails with InvalidCertificateRef.
  • Documentation: gateway-api.sigs.k8s.io “TLS” and “BackendTLSPolicy”, cert-manager.io “Gateway”, docs.cilium.io “Gateway API – HTTPS Example”.

Enterprise Note

  • Public names get ACME certificates (Let’s Encrypt, HTTP-01 via the Gateway API or DNS-01); internal names get a corporate CA via Vault or a CA issuer.
  • The CA root does not belong in a lab’s cluster Secret but in an HSM/KMS; at most a short-lived intermediate CA lives in the cluster.
  • trust-manager distributes CA bundles as ConfigMaps into all namespaces – a good match for caCertificateRefs of the BackendTLSPolicy.
  • Monitor certificate expiry: cert-manager exports certmanager_certificate_expiration_timestamp_seconds for Prometheus (Day 19).
  • For mTLS between all Pods instead of only Gateway→backend: mutual authentication or a service mesh (Day 14).