Skip to content

For the complete documentation index, see llms.txt. Markdown versions of all docs pages are available by appending .md to any docs URL.

Page as Markdown

    

HTTP

Create an HTTP listener on your API Gateway. Then, your API Gateway listens for HTTP traffic on the specified port and hostname that you configure. This Gateway can be used as the main ingress for the apps in your cluster. You can also create multiple Gateways to listen for traffic on different ports and hostnames.

Next, you set up an HTTPRoute resource to route requests through the Gateway to backing services in your cluster. HTTPRoutes can refer to any gateway independent of the namespace they are in.

Before you begin

  1. Follow the Get started guide to install kgateway.

  2. Deploy a sample httpbin app.

  3. Decide whether to set up a listener inline on the Gateway resource or as a separate ListenerSet resource. For more information, see the Listener overview.

    ListenerSets: This feature is available in kgateway version 2.1.x or later. Also, you must install the experimental channel of the Kubernetes Gateway API at version 1.3 or later.

Set up an HTTP listener

Set up an HTTP listener on your Gateway.

  1. Create a Gateway resource with an HTTP listener.

    kubectl apply -f- <<EOF
    apiVersion: gateway.networking.k8s.io/v1
    kind: Gateway
    metadata:
      name: my-http-gateway
      namespace: kgateway-system
      labels:
        example: httpbin-mydomain
    spec:
      gatewayClassName: kgateway
      listeners:
      - protocol: HTTP
        port: 8080
        hostname: mydomain.com
        name: http
        allowedRoutes:
          namespaces:
            from: All
    EOF

    Review the following table to understand this configuration.

    Setting Description
    spec.gatewayClassNameThe name of the Kubernetes GatewayClass that you want to use to configure the Gateway. When you set up kgateway, a default GatewayClass is set up for you.
    spec.listenersConfigure the listeners for this Gateway. In this example, you configure an HTTP Gateway that listens for incoming traffic for the mydomain.com domain on port 8080. The Gateway can serve HTTP routes from any namespace.
  2. Check the status of the Gateway to make sure that your configuration is accepted. Note that in the output, a NoConflicts status of False indicates that the Gateway is accepted and does not conflict with other Gateway configuration.

    kubectl get gateway my-http-gateway -n kgateway-system -o yaml
  3. Create an HTTPRoute resource for the httpbin app that is served by the Gateway that you created.

    kubectl apply -f- <<EOF
    apiVersion: gateway.networking.k8s.io/v1
    kind: HTTPRoute
    metadata:
      name: httpbin-mydomain
      namespace: httpbin
      labels:
        example: httpbin-mydomain
    spec:
      parentRefs:
        - name: my-http-gateway
          namespace: kgateway-system
      rules:
        - backendRefs:
            - name: httpbin
              port: 8000
    EOF
  4. Verify that the HTTPRoute is applied successfully.

    kubectl get httproute/httpbin-mydomain -n httpbin -o yaml

    Example output: Notice in the status section that the parentRef is either the Gateway or the ListenerSet, depending on how you attached the HTTPRoute.

    ...
    status:
      parents:
      - conditions:
        - lastTransitionTime: "2025-04-29T20:48:51Z"
          message: ""
          observedGeneration: 3
          reason: Accepted
          status: "True"
          type: Accepted
        - lastTransitionTime: "2025-04-29T20:48:51Z"
          message: ""
          observedGeneration: 3
          reason: ResolvedRefs
          status: "True"
          type: ResolvedRefs
        controllerName: kgateway.dev/kgateway
      parentRef:
        group: gateway.networking.k8s.io
        kind: Gateway
        name: my-http-gateway
        namespace: kgateway-system
  5. Verify that the listener now has a route attached.

    kubectl get gateway -n kgateway-system my-http-gateway -o yaml

    Example output:

    ...
    listeners:
    - attachedRoutes: 1
  6. Get the external address of the gateway and save it in an environment variable.

    export INGRESS_GW_ADDRESS=$(kubectl get svc -n kgateway-system my-http-gateway -o jsonpath="{.status.loadBalancer.ingress[0]['hostname','ip']}")
    echo $INGRESS_GW_ADDRESS   

  7. Send a request to the httpbin app and verify that you get back a 200 HTTP response code.

    curl -vi http://$INGRESS_GW_ADDRESS:8080/status/200 -H "host: mydomain.com:8080" 

    Example output:

    * Mark bundle as not supporting multiuse
    < HTTP/1.1 200 OK
    HTTP/1.1 200 OK
    < access-control-allow-credentials: true
    access-control-allow-credentials: true
    < access-control-allow-origin: *
    access-control-allow-origin: *
    < date: Fri, 03 Nov 2023 20:02:48 GMT
    date: Fri, 03 Nov 2023 20:02:48 GMT
    < content-length: 0
    content-length: 0
    < x-envoy-upstream-service-time: 1
    x-envoy-upstream-service-time: 1
    < server: envoy
    server: envoy
    

Cleanup

You can remove the resources that you created in this guide.
kubectl delete -A gateways,httproutes -l example=httpbin-mydomain
Was this page helpful?