Host
Redirect requests to a different host.
For more information, see the Kubernetes Gateway API documentation.
Before you begin
Follow the Get started guide to install Gloo Gateway.
Follow the Sample app guide to create a gateway proxy with an HTTP listener and deploy the httpbin sample app.
Get the external address of the gateway and save it in an environment variable.
Set up host redirects
Create an HTTPRoute for the httpbin app. In the following example, requests for the
host.redirect.exampledomain are redirected to thewww.example.comhostname, and a 302 HTTP response code is returned to the user.kubectl apply -f- <<EOF apiVersion: gateway.networking.k8s.io/v1 kind: HTTPRoute metadata: name: httpbin-redirect namespace: httpbin spec: parentRefs: - name: http namespace: gloo-system hostnames: - host.redirect.example rules: - filters: - type: RequestRedirect requestRedirect: hostname: "www.example.com" statusCode: 302 EOFSend a request to the httpbin app on the
host.redirect.exampledomain and verify that you get back a 302 HTTP response code and the redirect locationwww.example.com/headers.Example output:
* Mark bundle as not supporting multiuse < HTTP/1.1 302 Found HTTP/1.1 302 Found < location: http://www.example.com/headers location: http://www.example.com/headers < server: envoy server: envoy < content-length: 0 content-length: 0
Cleanup
You can remove the resources that you created in this guide.
kubectl delete httproute httpbin-redirect -n httpbin