Instead of referencing a Kubernetes service in your HTTPRoute directly, you can create an Upstream resource that represents your Kubernetes service and reference that Upstream in your HTTPRoute. With Kubernetes Upstream resources, you can configure additional settings for your Kubernetes service that cannot be configured when using the KubernetesService resource. For example, you can require communication to your Kubernetes service to use the HTTP/2 protocol, or add health checks. Because Upstreams bypass the kube-proxy, you can also improve load balancing times for your workloads.

Before you begin

  1. Follow the Get started guide to install Gloo Gateway, set up a gateway resource, and deploy the httpbin sample app.

  2. Get the external address of the gateway and save it in an environment variable.

Set up the Upstream

  1. Create the Petstore sample app.

      kubectl apply -f https://raw.githubusercontent.com/solo-io/gloo/v1.16.x/example/petstore/petstore.yaml
      
  2. Create an Upstream resource for the Petstore app.

      kubectl apply -f- <<EOF
    apiVersion: gloo.solo.io/v1
    kind: Upstream
    metadata:
      name: petstore
      namespace: gloo-system
    spec:
      kube:
        serviceName: petstore
        serviceNamespace: default
        servicePort: 8080
    EOF
      
  3. Create an HTTPRoute resource that references the Upstream that you created.

      kubectl apply -f- <<EOF
    apiVersion: gateway.networking.k8s.io/v1beta1
    kind: HTTPRoute
    metadata:
      name: kube-upstream
      namespace: gloo-system
    spec:
      parentRefs:
      - name: http
        namespace: gloo-system
      hostnames:
        - kube.example
      rules:
        - backendRefs:
          - name: petstore
            kind: Upstream
            group: gloo.solo.io
    EOF
      
  4. Send a request to the Petstore app.

    Example output:

      ...
    * Mark bundle as not supporting multiuse
    < HTTP/1.1 200 OK
    HTTP/1.1 200 OK
    ...
    [{"id":1,"name":"Dog","status":"available"},{"id":2,"name":"Cat","status":"pending"}]
      

Cleanup

Remove the resources that you created.

  kubectl delete httproute kube-upstream -n gloo-system
kubectl delete upstream petstore -n gloo-system
kubectl delete -f https://raw.githubusercontent.com/solo-io/gloo/v1.16.x/example/petstore/petstore.yaml