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.
kube
are automatically created when service discovery is enabled in K8sGateway. 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 K8sGateway, 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.
export INGRESS_GW_ADDRESS=$(kubectl get svc -n gloo-system gloo-proxy-http -o jsonpath="{.status.loadBalancer.ingress[0]['hostname','ip']}") echo $INGRESS_GW_ADDRESS
kubectl port-forward deployment/gloo-proxy-http -n gloo-system 8080:8080
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/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
-
Send a request to the Petstore app.
curl -vik http://$INGRESS_GW_ADDRESS:8080/api/pets -H "host: kube.example:8080"
curl -vik localhost:8080/api/pets -H "host: kube.example:8080"
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
You can remove the resources that you created in this guide.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