This use case shows how to publish two sample applications using URI-based routing
cd into the lab directory
cd ~/NGINX-Gateway-Fabric-Lab/labs/1.basic-app
Deploy two sample web applications
kubectl apply -f 0.cafe.yaml
Verify that all pods are in the Running state
kubectl get all
Output should be similar to
NAME READY STATUS RESTARTS AGE
pod/coffee-56b44d4c55-nm5rx 1/1 Running 0 8m39s
pod/tea-596697966f-lk2gp 1/1 Running 0 8m39s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/coffee ClusterIP 10.102.183.198 <none> 80/TCP 8m39s
service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 38d
service/tea ClusterIP 10.111.232.2 <none> 80/TCP 8m39s
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/coffee 1/1 1 1 8m39s
deployment.apps/tea 1/1 1 1 8m39s
NAME DESIRED CURRENT READY AGE
replicaset.apps/coffee-56b44d4c55 1 1 1 8m39s
replicaset.apps/tea-596697966f 1 1 1 8m39s
Create the gateway object. This deploys the NGINX Gateway Fabric dataplane pod in the current namespace
kubectl apply -f 1.gateway.yaml
Check the NGINX Gateway Fabric dataplane pod status
kubectl get pods
The gateway-nginx-c9bcdf4d4-4hl7c pod is the NGINX Gateway Fabric dataplane
NAME READY STATUS RESTARTS AGE
coffee-56b44d4c55-6drv2 1/1 Running 0 47s
gateway-nginx-c9bcdf4d4-4hl7c 1/1 Running 0 24s
tea-596697966f-fwf2r 1/1 Running 0 47s
Check the gateway
kubectl get gateway
Output should be similar to
NAME CLASS ADDRESS PROGRAMMED AGE
gateway nginx 10.102.76.40 True 5s
Check the NGINX Gateway Fabric Service
kubectl get service
gateway-nginx is the NGINX Gateway Fabric dataplane service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
coffee ClusterIP 10.107.171.2 <none> 80/TCP 2s
gateway-nginx NodePort 10.100.81.10 <none> 80:32604/TCP 15s
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 268d
tea ClusterIP 10.96.115.255 <none> 80/TCP 2s
Create the HTTP routes
kubectl apply -f 2.httproute.yaml
Check the HTTP routes
kubectl get httproute
Output should be similar to
NAME HOSTNAMES AGE
coffee ["cafe.example.com"] 8s
tea ["cafe.example.com"] 8s
Get NGINX Gateway Fabric dataplane instance IP and HTTP port
export NGF_IP=`kubectl get pod -l app.kubernetes.io/instance=ngf -o json|jq '.items[0].status.hostIP' -r`
export HTTP_PORT=`kubectl get svc gateway-nginx -o jsonpath='{.spec.ports[0].nodePort}'`
Check NGINX Gateway Fabric dataplane instance IP and HTTP port
echo -e "NGF address: $NGF_IP\nHTTP port : $HTTP_PORT"
Test application access: to access coffee
curl --resolve cafe.example.com:$HTTP_PORT:$NGF_IP http://cafe.example.com:$HTTP_PORT/coffee
Output should be similar to
Server address: 192.168.36.115:8080
Server name: coffee-56b44d4c55-nm5rx
Date: 24/Mar/2025:21:08:19 +0000
URI: /coffee
Request ID: 5136f3dd98058fc9edcad13998902e79
To access tea
curl --resolve cafe.example.com:$HTTP_PORT:$NGF_IP http://cafe.example.com:$HTTP_PORT/tea
Output should be similar to
Server address: 192.168.36.116:8080
Server name: tea-596697966f-lk2gp
Date: 24/Mar/2025:21:08:23 +0000
URI: /tea
Request ID: 09603099f3ad42da023a6184019ffbb6
Delete the lab
kubectl delete -f .