Kubernetes service
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.
Upstreams of type kube
are automatically created when service discovery is enabled in Gloo Gateway. However, you can also manually create the Upstream in your cluster as shown in this guide.
Before you begin
Follow the Get started guide to install Gloo Gateway, set up a gateway resource, and deploy the httpbin sample app.
Get the external address of the gateway and save it in an environment variable.
Set up the Upstream
Create the Petstore sample app.
kubectl apply -f https://raw.githubusercontent.com/solo-io/gloo/v1.16.x/example/petstore/petstore.yaml
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
Create an HTTPRoute resource that references the Upstream that you created.
kubectl apply -f- <<EOF apiVersion: gateway.networking.k8s.io/v1 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
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