Direct response
Directly respond to incoming requests without routing the requests to services in your service mesh.
Rather than routing a request to a service within your service mesh, you can send back a pre-defined body and HTTP status response to the client. If necessary, you can also specify headers by using the Header Modification feature in the enclosing route.
For more information, see the Gloo Mesh Gateway API docs for route tables.
Create a virtual gateway that opens up port 80 on your ingress gateway.
kubectl apply -f- <<EOF apiVersion: networking.gloo.solo.io/v2 kind: VirtualGateway metadata: name: istio-ingressgateway namespace: bookinfo spec: workloads: # Matches on 'spec.selector' labels for the ingress gateway service - selector: labels: istio: ingressgateway cluster: ${CLUSTER_NAME} listeners: # The port the ingress gateway listens on for incoming requests to route - port: number: 80 http: {} EOFCreate a direct response route table, and specify the status and optional body that is returned. In the following example, the
510status andno longer supportedmessage are immediately returned in response to any requests to the/unsupported-apppath.kubectl apply -n global -f- <<EOF apiVersion: networking.gloo.solo.io/v2 kind: RouteTable metadata: name: direct-response namespace: global spec: hosts: - '*' # Selects the virtual gateway you previously created virtualGateways: - name: istio-ingressgateway namespace: bookinfo cluster: ${CLUSTER_NAME} http: - name: unsupported-app-route # Prefix matching matchers: - uri: prefix: /unsupported-app # Immediately returns this 510 response directResponse: body: '{"message": "no longer supported"}' status: 510 EOFGet the external address of your ingress gateway.
export INGRESS_GW_ADDRESS=$(kubectl get svc -n istio-ingress istio-ingressgateway -o jsonpath="{.status.loadBalancer.ingress[0]['hostname','ip']}") echo $INGRESS_GW_ADDRESSVerify that you receive the expected direct response by curling the ingress gateway address and, if applicable, the path. For example, the following command appends
/unsupported-app.curl http://$INGRESS_GW_ADDRESS/unsupported-app