After you configure path redirection for a service, the service will respond to a specific request with an HTTP 301 status code to redirect the request to another path of the service. This topic describes how to configure path redirection.
Prerequisites
The preparations are completed, and the HTTPBin, sleep, and NGINX services are deployed. For more information, see Preparations.
Procedure
Configure a virtual service for the HTTPBin service to forward requests destined for the HTTPBin service to the NGINX service.
Log on to the ASM console. In the left-side navigation pane, choose .
On the Mesh Management page, click the name of the ASM instance. In the left-side navigation pane, choose . On the page that appears, click Create.
On the Create page, configure the following parameters, and click Preview. Confirm that the YAML content is correct, click Submit, and then click Create.
The YAML preview is as follows.
apiVersion: networking.istio.io/v1beta1 kind: VirtualService metadata: name: httpbin namespace: default spec: hosts: - httpbin.default.svc.cluster.local http: - match: - uri: exact: / redirect: uri: /get
Use kubectl to connect to the Container Service for Kubernetes (ACK) cluster based on the information in the kubeconfig file, and then run the following command to check whether the path redirection configuration takes effect:
kubectl exec -it deploy/sleep -- curl httpbin:8000 -I
Expected output:
HTTP/1.1 301 Moved Permanently location: http://httpbin:8000/get date: Mon, 14 Aug 2023 02:51:52 GMT server: envoy transfer-encoding: chunked
You can see that a request is sent to the root path of the HTTPBin service in the sleep container and is responded with an HTTP 301 status code. In the response, the
location
field is set tohttp://httpbin:8000/get
, which indicates that the request is redirected to the/get
path of the HTTPBin service.