All Products
Search
Document Center

Alibaba Cloud Service Mesh:Configure path redirection

Last Updated:Oct 12, 2023

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

  1. Configure a virtual service for the HTTPBin service to forward requests destined for the HTTPBin service to the NGINX service.

    1. Log on to the ASM console. In the left-side navigation pane, choose Service Mesh > Mesh Management.

    2. On the Mesh Management page, click the name of the ASM instance. In the left-side navigation pane, choose Traffic Management Center > VirtualService. On the page that appears, click Create.

    3. On the Create page, configure the following parameters, and click Preview. Confirm that the YAML content is correct, click Submit, and then click Create.

      image.png

      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
  2. 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 to http://httpbin:8000/get, which indicates that the request is redirected to the /get path of the HTTPBin service.