NGINX Gateway Fabric is an open source project that provides an implementation of the Gateway API using NGINX as the data plane. The goal of this project is to implement the core Gateway APIs – Gateway, GatewayClass, HTTPRoute, GRPCRoute, TCPRoute, TLSRoute, and UDPRoute – to configure an HTTP or TCP/UDP load balancer, reverse proxy, or API gateway for applications running on Kubernetes. NGINX Gateway Fabric supports a subset of the Gateway API.
## Install CRD and Implementation (Nginx Gateway Fabric) of Kubernetes Gateway API - By Cluster Operator
task gateway:nginx-install
ℹ️ When Nginx Gateway Fabric is installed, a GatewayClass
nginx
is provisioned for us. To show it :kubectl describe gc/nginx
## Deploy Workload - By Application Developer
kubectl apply -f gateway/nginx/coffee.workload.yml
## Deploy Gateway - By Cluster Operator
kubectl apply -f gateway/nginx/coffee.gateway.yml
## Deploy Routes HTTP - By Application Developer
kubectl apply -f gateway/nginx/coffee.routes.yml
## Call API - /coffee
curl --connect-to coffee.nzuguem.me:80:localhost:9080 http://coffee.nzuguem.me/coffee
## or
curl -H "Host: coffee.nzuguem.me" localhost:9080/coffee
## Call API - /tea
curl --connect-to coffee.nzuguem.me:80:localhost:9080 http://coffee.nzuguem.me/tea
## or
curl -H "Host: coffee.nzuguem.me" localhost:9080/tea
ℹ️ Using the
--connect-to
option with curl is closely related to the--resolve
option. This command instructscurl
to resolve the domain name in the URL by replacing it with the specified one. In the case of an HTTPS request, this option also sends theSNI
(the domain name specified in the URL). The use of theHost
header will also work, but only for unencrypted requests, as in the case of HTTPS requests, this header will not be considered as SNI (Cf. Name resolve tricks)
## Deploy All Resources
kubectl apply -f gateway/nginx/advanced/routing
## Curl to "coffee-v1-svc"
curl --connect-to cafe.nzuguem.me:80:localhost:9080 http://cafe.nzuguem.me/coffee
## Curl to "coffee-v2-svc"
curl --connect-to cafe.nzuguem.me:80:localhost:9080 http://cafe.nzuguem.me/coffee -H "version:v2"
curl --connect-to cafe.nzuguem.me:80:localhost:9080 http://cafe.nzuguem.me/coffee?TEST=v2
## Curl to "tea-post-svc"
curl --connect-to cafe.nzuguem.me:80:localhost:9080 http://cafe.nzuguem.me/tea -X POST
## Curl to "tea-svc"
curl --connect-to cafe.nzuguem.me:80:localhost:9080 http://cafe.nzuguem.me/tea
## Deploy Workload
kubectl apply -f gateway/nginx/advanced/grpc/helloworld.yml
kubectl apply -f gateway/nginx/advanced/grpc/exact-method.yml
grpcurl -plaintext -proto gateway/nginx/advanced/grpc/grpc.proto -d '{"name": "GRPC"}' localhost:9080 helloworld.Greeter/SayHello
kubectl delete -f gateway/nginx/advanced/grpc/exact-method.yml
kubectl apply -f gateway/nginx/advanced/grpc/hostname.yml
# Test bar hostname
grpcurl -plaintext -proto gateway/nginx/advanced/grpc/grpc.proto -authority bar.nzuguem.me -d '{"name": "bar server"}' localhost:9080 helloworld.Greeter/SayHello
# Test foo-bar hostname
grpcurl -plaintext -proto gateway/nginx/advanced/grpc/grpc.proto -authority foo-bar.nzuguem.me -d '{"name": "foo-bar server"}' localhost:9080 helloworld.Greeter/SayHello
kubectl delete -f gateway/nginx/advanced/grpc/hostname.yml
kubectl apply -f gateway/nginx/advanced/grpc/headers.yml
# Test Version One
grpcurl -plaintext -proto gateway/nginx/advanced/grpc/grpc.proto -d '{"name": "version one"}' -H 'version: one' localhost:9080 helloworld.Greeter/SayHello
# Test Version Two
grpcurl -plaintext -proto gateway/nginx/advanced/grpc/grpc.proto -d '{"name": "version two"}' -H 'version: two' localhost:9080 helloworld.Greeter/SayHello
# Test Version Two And Color Orange
grpcurl -plaintext -proto gateway/nginx/advanced/grpc/grpc.proto -d '{"name": "version two color orange"}' -H 'version: two' -H 'color: orange' localhost:9080 helloworld.Greeter/SayHello
task gateway:nginx-uninstall