Skip to content

Nginx Gateway Fabric setup

Since nginx ingress controller has been deprecated. Nginx gateway fabric is the most easiest gateway integration. Following are the features of gateway API

  • Supports advanced routing, not just host and path
  • No controller-specific annotations
  • Consistent and portable configuration
  • Designed for multi-team and multi-namespace clusters
  • Native traffic splitting and canary deployments
  • Easy to extend in a standard way
  • Built for modern and future use cases

Nginx Gateway Fabric Jargon

Following are key terms used in the nginx gateway fabric

  • GatewayClass defines which Gateway controller will manage the traffic, similar to how an Ingress controller works.
  • You can have multiple GatewayClasses in a cluster, each backed by a different controller.
  • Gateway represents the actual traffic entry point into the cluster.
  • It defines listeners, such as ports (80, 443) and protocols (HTTP, HTTPS).
  • You can create multiple Gateways using the same GatewayClass for different teams or environments.
  • HTTPRoute defines how HTTP traffic is routed to backend services.
  • It supports routing based on hostnames, paths, headers, and methods.
  • Routes can be attached to Gateways across namespaces, with proper permissions.
  • GRPCRoute is used to manage gRPC-based traffic routing.
  • Designed specifically for gRPC services.

install gateway api CRDs

Install gateway api CRDs using the following command.

kubectl apply --server-side -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v1.5.0/standard-install.yaml

view the installed CRDs

kubectl get crds | grep gateway

install using helm oci

helm install ngf oci://ghcr.io/nginx/charts/nginx-gateway-fabric \
  --namespace nginx-gateway \
  --create-namespace \
  --version 2.4.0 \
  --wait

create nginx gateway class

apiVersion: gateway.networking.k8s.io/v1
kind: GatewayClass
metadata:
  name: nginx
spec:
  controllerName: gateway.nginx.org/nginx-gateway-fabric

install nginx gateway class

kubectl apply -f gatewayclass.yaml

create nginx gateway

apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
  name: main-gateway
spec:
  gatewayClassName: nginx
  listeners:
  - name: http
    protocol: HTTP
    port: 80
    allowedRoutes:
      namespaces:
        from: All

install nginx gateway

kubectl apply -f gateway.yaml

create httproute

apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: testing
  namespace: default
spec:
  parentRefs:
    - name: main-gateway
      namespace: nginx-gateway
  hostnames:
    - "gw.roshankhatri8848.com.np"
  rules:
    - matches:
        - path:
            type: PathPrefix
            value: /
      backendRefs:
        - name: nginx-lb
          port: 80

install httproute

kubectl apply -f httproute.yaml