Day 10: Gateway API
Goal: You enable Cilium’s Gateway controller, publish services through a Gateway and steer traffic with HTTPRoute and GRPCRoute by path, header and weight – and read from the status conditions why a route doesn’t take effect. · Duration: approx. 90 min · Prerequisite: Day 6
Briefing
- CKNE: Advanced Traffic Management – “Managing Traffic with the Gateway API”.
- Roles: the GatewayClass belongs to the platform team (which controller), the Gateway to cluster operations (which ports and hosts), the routes to the app teams.
- Cilium implements every Gateway in Envoy (DaemonSet
cilium-envoy) and creates a Servicecilium-gateway-<name>for it. - Reading status is half the exam:
Accepted,Programmed,ResolvedRefs.
cp1/router ── Host: shop.example.com ──> <Node-IP>:<NodePort>
│ Service cilium-gateway-web
v
Envoy (Gateway web, Listener http:80)
HTTPRoute match/canary/filter ─┬─> echo-v1 / echo-v2 (tag10)
HTTPRoute billing + ReferenceGrant ─> billing (tag10-backend)
GRPCRoute grpc ─────────────────────> grpc-echo (tag10)
Drill 1: Enable CRDs and controller
The Gateway API is not part of Kubernetes – its CRDs ship separately. According to the docs, Cilium 1.20.5 requires Gateway API v1.6.3; the standard bundle already contains GRPCRoute, TLSRoute and BackendTLSPolicy, so the experimental channel isn’t needed:
mkdir -p ~/ckne/tag10 && cd ~/ckne/tag10
GWAPI=https://github.com/kubernetes-sigs/gateway-api/releases/download/v1.6.3
k apply --server-side -f $GWAPI/standard-install.yaml
k get crd | grep gateway.networkingExpected (abridged):
customresourcedefinition.apiextensions.k8s.io/gatewayclasses.gateway.networking.k8s.io
serverside-applied
...
validatingadmissionpolicy.admissionregistration.k8s.io/safe-upgrades.gateway.networking
.k8s.io serverside-applied
backendtlspolicies.gateway.networking.k8s.io Namespaced v1(storage)
gatewayclasses.gateway.networking.k8s.io Cluster v1(storage),v1beta1
gateways.gateway.networking.k8s.io Namespaced v1(storage),v1beta1
grpcroutes.gateway.networking.k8s.io Namespaced v1(storage)
httproutes.gateway.networking.k8s.io Namespaced v1(storage),v1beta1
listenersets.gateway.networking.k8s.io Namespaced v1(storage)
referencegrants.gateway.networking.k8s.io Namespaced v1,v1beta1(storage)
tcproutes.gateway.networking.k8s.io Namespaced v1(storage)
tlsroutes.gateway.networking.k8s.io Namespaced v1(storage)
udproutes.gateway.networking.k8s.io Namespaced v1(storage)
Now the controller in Cilium. The lab has met the prerequisites since
Day 0: kubeProxyReplacement=true and the L7 proxy
(default). The agent reads its configuration only at startup, so restart
both components afterwards:
helm get values cilium -n kube-system -o yaml > values-vorher.yaml
helm upgrade cilium cilium/cilium -n kube-system --version 1.20.5 \
--reuse-values --set gatewayAPI.enabled=true
k -n kube-system rollout restart deployment/cilium-operator
k -n kube-system rollout restart ds/cilium
k -n kube-system rollout status ds/cilium
cilium status --wait
cilium config view | grep -E '^enable-gateway-api |gateway-api-hostnetwork-enabled'
k get gatewayclassExpected (abridged):
daemon set "cilium" successfully rolled out
/¯¯\
/¯¯\__/¯¯\ Cilium: OK
\__/¯¯\__/ Operator: OK
/¯¯\__/¯¯\ Envoy DaemonSet: OK
enable-gateway-api true
gateway-api-hostnetwork-enabled false
NAME CONTROLLER ACCEPTED AGE
cilium io.cilium/gateway-controller True 91s
The Helm chart creates the GatewayClass cilium itself.
What the controller can do is listed in its status:
k get gatewayclass cilium -o jsonpath='{.status.supportedFeatures[*].name}' \
| tr ' ' '\n' \
| grep -E '^(GRPCRoute|BackendTLSPolicy|HTTPRouteRequestMirror|TLSRoute)$'Expected:
BackendTLSPolicy
GRPCRoute
HTTPRouteRequestMirror
TLSRoute
Save your progress? Sign up for free
Drill 2: First Gateway – and why it doesn’t become “Programmed”
The backend is echo-basic from the Gateway API
conformance tests (amd64 and arm64; the image has its own tags – there
is no v1.6.3, and v1.5.1 runs unchanged with the v1.6.3 CRDs): it
replies with path, host, headers and Pod name as JSON. It reads the Pod
name from the variable POD_NAME, hence a short manifest
instead of k create deployment:
k create namespace tag10
k config set-context --current --namespace=tag10
cat > echo.yaml <<'EOF'
apiVersion: apps/v1
kind: Deployment
metadata:
name: echo-v1
spec:
selector:
matchLabels: {app: echo, version: v1}
template:
metadata:
labels: {app: echo, version: v1}
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: NAMESPACE
valueFrom: {fieldRef: {fieldPath: metadata.namespace}}
EOF
sed -e 's/echo-v1/echo-v2/' -e 's/version: v1/version: v2/g' echo.yaml > echo-v2.yaml
k apply -f echo.yaml -f echo-v2.yaml
k expose deployment echo-v1 --port=8080 --target-port=3000
k expose deployment echo-v2 --port=8080 --target-port=3000
k rollout status deployment echo-v2Now the Gateway. There is no k create gateway – YAML
from the docs or k explain gateway.spec.listeners
helps:
cat > gw.yaml <<'EOF'
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: web
spec:
gatewayClassName: cilium
listeners:
- name: http
protocol: HTTP
port: 80
allowedRoutes:
namespaces:
from: Same
EOF
k apply -f gw.yaml
k get gateway web
k get svc cilium-gateway-web
k get gateway web -o jsonpath=\
'{range .status.conditions[*]}{.type}={.status} {.reason}: {.message}{"\n"}{end}'Expected:
gateway.gateway.networking.k8s.io/web created
NAME CLASS ADDRESS PROGRAMMED AGE
web cilium False 11s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
cilium-gateway-web LoadBalancer 10.109.212.37 <pending> 80:30285/TCP 11s
Accepted=True Accepted: Gateway successfully scheduled
Programmed=False AddressNotAssigned: Gateway waiting for address
The first typical error: Cilium builds a LoadBalancer Service for the
Gateway, and without an LB IPAM pool (Day 15) it gets no IP. You
deliberately don’t create a pool from the lab network
172.16.0.0/24 here – on a home network the router hands out
addresses via DHCP, so free addresses aren’t guaranteed. Host network
mode (gatewayAPI.hostNetwork.enabled) is also out: it
applies cluster-wide, rules out LoadBalancer mode for all Gateways and
again requires agent restarts. That leaves the clean per-GatewayClass
approach – a CiliumGatewayClassConfig with Service type
NodePort:
k explain ciliumgatewayclassconfig.spec.service.type
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: tag10-nodeport
spec:
controllerName: io.cilium/gateway-controller
parametersRef:
group: cilium.io
kind: CiliumGatewayClassConfig
name: nodeport
namespace: tag10
EOF
k apply -f nodeport.yaml
sed -i 's/gatewayClassName: cilium/gatewayClassName: tag10-nodeport/' gw.yaml
k apply -f gw.yaml
k get gatewayclass
k get gateway web
k get svc cilium-gateway-webExpected (abridged):
enum: LoadBalancer, NodePort
ciliumgatewayclassconfig.cilium.io/nodeport created
gatewayclass.gateway.networking.k8s.io/tag10-nodeport created
gateway.gateway.networking.k8s.io/web configured
NAME CONTROLLER ACCEPTED AGE
cilium io.cilium/gateway-controller True 4m23s
tag10-nodeport io.cilium/gateway-controller True 17s
NAME CLASS ADDRESS PROGRAMMED AGE
web tag10-nodeport 172.16.0.83 True 73s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
cilium-gateway-web NodePort 10.109.212.37 <none> 80:30285/TCP 73s
The Gateway now reports the node IPs as addresses, and listener port
80 becomes a NodePort. Cilium 1.20 rejects the obvious shortcut,
spec.infrastructure.parametersRef directly on the Gateway
(“InvalidParameters: spec.infrastructure.parametersRef is
not supported”) – parameters only via the GatewayClass.
NP=$(k get svc cilium-gateway-web -o jsonpath='{.spec.ports[0].nodePort}')
G=172.16.0.228:$NP; echo $G
k get ciliumenvoyconfig
k get endpointslices -l io.cilium.gateway/owning-gateway=web
k -n kube-system exec ds/cilium -c cilium-agent -- cilium-dbg service list \
| grep -A1 ":$NP/"Expected:
172.16.0.228:30285
NAME AGE
cilium-gateway-web 4m44s
NAME ADDRESSTYPE PORTS ENDPOINTS AGE
cilium-gateway-web IPv4 9999 192.192.192.192 4m45s
31 0.0.0.0:30285/TCP NodePort 1 => 127.0.0.1:18532/TCP (active)
The Service has only a placeholder endpoint; in reality Cilium
forwards the port via eBPF to the Envoy listener
(127.0.0.1:18532). The Envoy configuration itself lives in
the CiliumEnvoyConfig of the same name.
Save your progress? Sign up for free
Drill 3: HTTPRoute by host, path and header
Rules aren’t evaluated in order but by specificity: first the most
exact or longest path, on a tie the one with more header matches; the
rule without matches catches the rest.
cat > route-match.yaml <<'EOF'
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: match
spec:
parentRefs:
- name: web
hostnames:
- shop.example.com
rules:
- matches:
- headers:
- name: x-version
value: v2
backendRefs:
- name: echo-v2
port: 8080
- matches:
- path:
type: PathPrefix
value: /v2
backendRefs:
- name: echo-v2
port: 8080
- backendRefs:
- name: echo-v1
port: 8080
EOF
k apply -f route-match.yaml
H='Host: shop.example.com'
curl -s -H "$H" http://$G/ | grep -E '"(path|pod)"'
curl -s -H "$H" http://$G/v2/cart | grep -E '"(path|pod)"'
curl -s -H "$H" http://$G/v2x | grep -E '"(path|pod)"'
curl -s -H "$H" -H 'x-version: v2' http://$G/ | grep -E '"(path|pod)"'
curl -s -o /dev/null -w '%{http_code}\n' -H 'Host: other.example.com' http://$G/Expected:
httproute.gateway.networking.k8s.io/match created
"path": "/",
"pod": "echo-v1-5dbcd994f5-vq56q"
"path": "/v2/cart",
"pod": "echo-v2-5484b4fc56-bq4sg"
"path": "/v2x",
"pod": "echo-v1-5dbcd994f5-vq56q"
"path": "/",
"pod": "echo-v2-5484b4fc56-bq4sg"
404
PathPrefix compares whole path segments:
/v2x doesn’t match /v2. Envoy answers unknown
hosts with 404. The same from outside the cluster – from the
router, this time via worker2:
ssh [email protected] \
"curl -s -H 'Host: shop.example.com' http://172.16.0.83:$NP/v2/" \
| grep -E '"pod"|X-Forwarded-For' -A1
k get httproute match -o jsonpath=\
'{range .status.parents[*].conditions[*]}{.type}={.status} {.reason}{"\n"}{end}'
k get gateway web -o jsonpath='{.status.listeners[0].attachedRoutes}{"\n"}'Expected:
"X-Forwarded-For": [
"172.16.0.123"
--
"pod": "echo-v2-5484b4fc56-bq4sg"
Accepted=True Accepted
ResolvedRefs=True ResolvedRefs
1
Save your progress? Sign up for free
Drill 4: Canary 90/10 with counting
cat > route-canary.yaml <<'EOF'
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: canary
spec:
parentRefs:
- name: web
hostnames:
- canary.example.com
rules:
- backendRefs:
- name: echo-v1
port: 8080
weight: 90
- name: echo-v2
port: 8080
weight: 10
EOF
k apply -f route-canary.yaml
for i in $(seq 200); do
curl -s -H 'Host: canary.example.com' http://$G/
done | grep -o '"pod": "echo-v[12]' | sort | uniq -cExpected (numbers vary):
httproute.gateway.networking.k8s.io/canary created
183 "pod": "echo-v1
17 "pod": "echo-v2
Weights are relative (90:10 = 9:1) and apply per request, not per client – no stickiness. Weight 0 takes a backend out of the distribution without changing the route.
Save your progress? Sign up for free
Drill 5: Filters – header, redirect, rewrite
cat > route-filter.yaml <<'EOF'
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: filter
spec:
parentRefs:
- name: web
hostnames:
- api.example.com
rules:
- matches:
- path:
type: PathPrefix
value: /old
filters:
- type: RequestRedirect
requestRedirect:
path:
type: ReplacePrefixMatch
replacePrefixMatch: /new
statusCode: 301
- matches:
- path:
type: PathPrefix
value: /api/v1
filters:
- type: URLRewrite
urlRewrite:
path:
type: ReplacePrefixMatch
replacePrefixMatch: /
backendRefs:
- name: echo-v1
port: 8080
- filters:
- type: RequestHeaderModifier
requestHeaderModifier:
add:
- name: x-team
value: blue
set:
- name: user-agent
value: gateway
remove:
- x-debug
backendRefs:
- name: echo-v1
port: 8080
EOF
k apply -f route-filter.yaml
H='Host: api.example.com'
curl -si -H "$H" http://$G/old/page | grep -iE '^HTTP|^location'
curl -s -H "$H" http://$G/api/v1/users | grep '"path"'
curl -s -H "$H" -H 'x-debug: 1' http://$G/ | sed -n '/headers/,/httpPort/p'Expected (abridged):
HTTP/1.1 301 Moved Permanently
location: http://api.example.com:80/new/page
"path": "/users",
"headers": {
"User-Agent": [
"gateway"
],
"X-Envoy-Internal": [
"true"
],
"X-Forwarded-For": [
"172.16.0.126"
],
"X-Team": [
"blue"
]
},
A redirect goes back to the client, a rewrite stays invisible to it –
the backend sees /users. x-debug is gone,
X-Team is new. The location names port 80, the
listener port; behind a NodePort you would set
requestRedirect.port.
Save your progress? Sign up for free
Drill 6: Across namespaces with ReferenceGrant
k create namespace tag10-backend
k -n tag10-backend apply -f echo.yaml
k -n tag10-backend expose deployment echo-v1 --name=billing --port=8080 \
--target-port=3000
cat > route-billing.yaml <<'EOF'
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: billing
spec:
parentRefs:
- name: web
hostnames:
- billing.example.com
rules:
- backendRefs:
- name: billing
namespace: tag10-backend
port: 8080
EOF
k apply -f route-billing.yaml
RC='{range .status.parents[*].conditions[*]}{.type}={.status} '\
'{.reason}: {.message}{"\n"}{end}'
k get httproute billing -o jsonpath="$RC"
curl -s -w ' %{http_code}\n' -H 'Host: billing.example.com' http://$G/Expected:
httproute.gateway.networking.k8s.io/billing created
Accepted=True Accepted: Accepted HTTPRoute
ResolvedRefs=False RefNotPermitted: Cross namespace references are not allowed
500
A reference into another namespace needs that namespace’s consent: the target namespace creates a ReferenceGrant that says who may point at what.
cat > grant.yaml <<'EOF'
apiVersion: gateway.networking.k8s.io/v1
kind: ReferenceGrant
metadata:
name: tag10-routes
namespace: tag10-backend
spec:
from:
- group: gateway.networking.k8s.io
kind: HTTPRoute
namespace: tag10
to:
- group: ""
kind: Service
EOF
k apply -f grant.yaml
k get httproute billing -o jsonpath=\
'{range .status.parents[*].conditions[*]}{.type}={.status} {.reason}{"\n"}{end}'
curl -s -H 'Host: billing.example.com' http://$G/ | grep -E '"(namespace|pod)"'Expected:
referencegrant.gateway.networking.k8s.io/tag10-routes created
Accepted=True Accepted
ResolvedRefs=True ResolvedRefs
"namespace": "tag10-backend",
"pod": "echo-v1-5dbcd994f5-7tfsx"
The opposite direction – a route from tag10-backend to
the Gateway in tag10 – isn’t governed by the ReferenceGrant
but by allowedRoutes on the listener (Drill 8).
Save your progress? Sign up for free
Drill 7: GRPCRoute
With GRPC_ECHO_SERVER=1, echo-basic speaks
gRPC (including reflection). Envoy must know that the backend expects
HTTP/2 without TLS – that’s what
appProtocol: kubernetes.io/h2c on the Service port is
for:
sed -e 's/echo-v1/grpc-echo/' -e 's/version: v1/version: grpc/g' echo.yaml \
> grpc-echo.yaml
cat >> grpc-echo.yaml <<'EOF'
- name: GRPC_ECHO_SERVER
value: "1"
EOF
k apply -f grpc-echo.yaml
k expose deployment grpc-echo --port=8080 --target-port=3000 $do > grpc-svc.yaml
sed -i 's/^ - port: 8080/ - port: 8080\n appProtocol: kubernetes.io\/h2c/' \
grpc-svc.yaml
k apply -f grpc-svc.yaml
cat > grpcroute.yaml <<'EOF'
apiVersion: gateway.networking.k8s.io/v1
kind: GRPCRoute
metadata:
name: grpc
spec:
parentRefs:
- name: web
hostnames:
- grpc.example.com
rules:
- matches:
- method:
service: gateway_api_conformance.echo_basic.grpcecho.GrpcEcho
backendRefs:
- name: grpc-echo
port: 8080
EOF
k apply -f grpcroute.yaml
k get grpcroute
k run grpcurl --image=fullstorydev/grpcurl:v1.9.3 --restart=Never -- \
-plaintext -authority grpc.example.com $G list
k logs grpcurl; k delete pod grpcurlExpected (abridged):
grpcroute.gateway.networking.k8s.io/grpc created
NAME HOSTNAMES AGE
grpc ["grpc.example.com"] 3s
pod/grpcurl created
Failed to list services: server does not support the reflection API
The route is correct – but it only lets the GrpcEcho
service through. grpcurl list queries the reflection
service, and nobody routes that. So add a second rule:
cat >> grpcroute.yaml <<'EOF'
- matches:
- method:
service: grpc.reflection.v1.ServerReflection
- method:
service: grpc.reflection.v1alpha.ServerReflection
backendRefs:
- name: grpc-echo
port: 8080
EOF
k apply -f grpcroute.yaml
k run grpcurl --image=fullstorydev/grpcurl:v1.9.3 --restart=Never -- \
-plaintext -authority grpc.example.com $G list
k logs grpcurl; k delete pod grpcurl
k run grpcurl --image=fullstorydev/grpcurl:v1.9.3 --restart=Never -- \
-plaintext -authority grpc.example.com $G \
gateway_api_conformance.echo_basic.grpcecho.GrpcEcho/Echo
k logs grpcurl | grep -E 'fullyQualifiedMethod|"pod"'; k delete pod grpcurlExpected (abridged):
gateway_api_conformance.echo_basic.grpcecho.GrpcEcho
grpc.reflection.v1.ServerReflection
grpc.reflection.v1alpha.ServerReflection
"fullyQualifiedMethod": "/gateway_api_conformance.echo_basic.grpcecho.GrpcEcho/Echo",
"pod": "grpc-echo-55f498c9b8-wlv5s"
If k logs comes too early (“ContainerCreating”), wait
briefly – the Pod runs for only a few seconds. HTTP and gRPC routes
share the same HTTP listener here; the only difference is the match
(service/method instead of path).
Save your progress? Sign up for free
Drill 8: Reading status and typical errors
Three typical errors: in route-bad.yaml a listener name
that doesn’t exist and a missing Service, then a route from another
namespace:
cat > route-bad.yaml <<'EOF'
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: bad
spec:
parentRefs:
- name: web
sectionName: https
rules:
- backendRefs:
- name: echo-v3
port: 8080
EOF
k apply -f route-bad.yaml
k get httproute bad -o jsonpath="$RC"
sed -i '/sectionName/d' route-bad.yaml
k apply -f route-bad.yaml
k get httproute bad -o jsonpath="$RC"Expected:
httproute.gateway.networking.k8s.io/bad created
Accepted=False NoMatchingParent: No matching listener with sectionName https
ResolvedRefs=False BackendNotFound: Service "echo-v3" not found
httproute.gateway.networking.k8s.io/bad configured
Accepted=True Accepted: Accepted HTTPRoute
ResolvedRefs=False BackendNotFound: Service "echo-v3" not found
k -n tag10-backend apply -f - <<'EOF'
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: fremd
spec:
parentRefs:
- name: web
namespace: tag10
rules:
- backendRefs:
- name: billing
port: 8080
EOF
k -n tag10-backend get httproute fremd -o jsonpath="$RC"
k delete httproute bad; k -n tag10-backend delete httproute fremdExpected:
httproute.gateway.networking.k8s.io/fremd created
Accepted=False NotAllowedByListeners: HTTPRoute is not allowed to attach to this Gateway
due to namespace restrictions
ResolvedRefs=True ResolvedRefs: Service reference is valid
| Condition | Object | Typical reason for False |
|---|---|---|
Accepted |
Gateway | InvalidParameters, unknown GatewayClass |
Programmed |
Gateway | AddressNotAssigned (no LB IPAM pool) |
Accepted |
Route | NoMatchingParent,
NotAllowedByListeners |
ResolvedRefs |
Route | BackendNotFound, RefNotPermitted |
Who actually sends the traffic? Hubble shows Gateway traffic with the
reserved identity ingress – important for policies on Day
12 and Day 14:
for i in 1 2 3; do curl -s -o /dev/null -H 'Host: shop.example.com' http://$G/v2/x; done
hubble observe -P --port-forward-port 0 --to-namespace tag10 \
--to-label version=v2 --type l7 --last 2Expected (abridged):
Nov 18 23:49:29.563: 127.0.0.1:53126 (ingress) -> tag10/echo-v2-5484b4fc56-bq4sg:3000
(ID:25858) http-request FORWARDED (HTTP/1.1 GET http://shop.example.com/v2/x)
Nov 18 23:49:29.597: 127.0.0.1:53136 (ingress) -> tag10/echo-v2-5484b4fc56-bq4sg:3000
(ID:25858) http-request FORWARDED (HTTP/1.1 GET http://shop.example.com/v2/x)
Save your progress? Sign up for free
Exercise: Speed Drills
- Create an HTTPRoute
docsfordocs.example.comthat sends onlyGETon the exact path/infotoecho-v2. Target time: 3 min - Switch
canaryto 50/50 without opening the file. Target time: 60 s - Add the response header
x-served-by: gatewaytodocs. Target time: 2 min - Show name,
Acceptedstatus andResolvedRefsreason for all HTTPRoutes intag10in one table. Target time: 90 s
Solution
cat > route-docs.yaml <<'EOF'
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: docs
spec:
parentRefs:
- name: web
hostnames:
- docs.example.com
rules:
- matches:
- path:
type: Exact
value: /info
method: GET
backendRefs:
- name: echo-v2
port: 8080
EOF
k apply -f route-docs.yaml
for p in /info /info/x; do
curl -s -o /dev/null -w '%{http_code}\n' -H 'Host: docs.example.com' http://$G$p
done
curl -s -o /dev/null -w '%{http_code}\n' -X POST -H 'Host: docs.example.com' \
http://$G/info
k patch httproute canary --type=json -p '[
{"op":"replace","path":"/spec/rules/0/backendRefs/0/weight","value":50},
{"op":"replace","path":"/spec/rules/0/backendRefs/1/weight","value":50}]'
for i in $(seq 100); do curl -s -H 'Host: canary.example.com' http://$G/; done \
| grep -o '"pod": "echo-v[12]' | sort | uniq -c
k patch httproute docs --type=json -p '[{"op":"add","path":"/spec/rules/0/filters",
"value":[{"type":"ResponseHeaderModifier",
"responseHeaderModifier":{"add":[{"name":"x-served-by","value":"gateway"}]}}]}]'
curl -si -H 'Host: docs.example.com' http://$G/info | grep -i x-served-by
k get httproute -o custom-columns='NAME:.metadata.name,'\
'ACCEPTED:.status.parents[0].conditions[?(@.type=="Accepted")].status,'\
'REFS:.status.parents[0].conditions[?(@.type=="ResolvedRefs")].reason'Expected (abridged):
200
404
404
httproute.gateway.networking.k8s.io/canary patched
41 "pod": "echo-v1
59 "pod": "echo-v2
httproute.gateway.networking.k8s.io/docs patched
x-served-by: gateway
NAME ACCEPTED REFS
billing True ResolvedRefs
canary True ResolvedRefs
docs True ResolvedRefs
filter True ResolvedRefs
match True ResolvedRefs
Be careful with test paths: echo-basic itself answers
/status with a 301 to /status/ – in that case
the Gateway isn’t to blame.
Save your progress? Sign up for free
Checkpoint
k get gatewayclassExpected: cilium and
tag10-nodeport, both ACCEPTED True.
k get gateway webExpected: CLASS tag10-nodeport, a node
IP as ADDRESS, PROGRAMMED True.
curl -s -H 'Host: shop.example.com' http://$G/v2/ | grep '"pod"'Expected: a Pod echo-v2-….
k get httproute billing -o jsonpath='{.status.parents[0].conditions[1].reason}{"\n"}'Expected: ResolvedRefs (thanks to the
ReferenceGrant).
cilium config view | grep '^enable-gateway-api 'Expected: enable-gateway-api true –
stays on for Day 11 and Day 18, as do the Gateway API CRDs v1.6.3.
Challenge
Mirror all traffic to mirror.example.com additionally to
echo-v2, while the responses still come from
echo-v1. Prove that the mirrored requests arrive.
Hint: The filter is called
RequestMirror; echo-basic logs every
request.
Solution
cat > route-mirror.yaml <<'EOF'
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: mirror
spec:
parentRefs:
- name: web
hostnames:
- mirror.example.com
rules:
- filters:
- type: RequestMirror
requestMirror:
backendRef:
name: echo-v2
port: 8080
backendRefs:
- name: echo-v1
port: 8080
EOF
k apply -f route-mirror.yaml
for i in 1 2 3; do
curl -s -H 'Host: mirror.example.com' http://$G/schatten-$i | grep '"pod"'
done
k logs deploy/echo-v2 --tail=3Expected:
httproute.gateway.networking.k8s.io/mirror created
"pod": "echo-v1-5dbcd994f5-vq56q"
"pod": "echo-v1-5dbcd994f5-vq56q"
"pod": "echo-v1-5dbcd994f5-vq56q"
Echoing back request made to /schatten-1 to client (10.0.0.88:32848)
Echoing back request made to /schatten-2 to client (10.0.0.88:32850)
Echoing back request made to /schatten-3 to client (10.0.0.88:32864)
Envoy sends the copy “fire and forget” – it discards its response. That’s how you test a new version with real traffic without any user seeing it.
Save your progress? Sign up for free
Cleanup
k delete namespace tag10 tag10-backend
k delete gatewayclass tag10-nodeport
k config set-context --current --namespace=defaultThe Gateway API CRDs and gatewayAPI.enabled=true stay
for Day 11 and Day 18. To revert completely (only if you’re not doing
the following days):
helm upgrade cilium cilium/cilium -n kube-system --version 1.20.5 --reuse-values --set gatewayAPI.enabled=false,
then restart the operator and agents.
Exam Tip
- No
k createfor Gateway objects: copy examples from gateway-api.sigs.k8s.io (“Guides”), check fields withk explain httproute.spec.rules. - Read
Accepted/Programmedon the Gateway first, thenAccepted/ResolvedRefson the route – thereasonalmost always says what’s missing (listener name, Service, ReferenceGrant,allowedRoutes). - The ReferenceGrant lives in the target’s namespace;
allowedRoutesis set on the Gateway.
Enterprise Note
- In production the Gateway gets a real LoadBalancer IP (LB IPAM with BGP or L2, Day 15, or a cloud LB); NodePort is a lab and emergency solution.
- One Gateway per team or environment, shared Gateways with
allowedRoutes.namespaces.from: Selectorand namespace labels. - The Gateway API CRDs belong to the platform team: couple their
version to the controller version, upgrade via
--server-sideand the bundledsafe-upgradesValidatingAdmissionPolicy. - Tools like Argo Rollouts or Flagger steer canary weights
automatically via the same
weightfields. - Envoy runs as its own DaemonSet
cilium-envoy: plan resource limits and updates separately from the agent.