All Products
Search
Document Center

Alibaba Cloud Service Mesh:Configure host redirection

Last Updated:Oct 12, 2023

After you configure host redirection for a host, the host can redirect requests to another host. This topic describes how to configure host 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:
          - route:
              - destination:
                  host: nginx.default.svc.cluster.local
  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 host redirection configuration takes effect:

    kubectl exec -it deploy/sleep -- curl httpbin:8000|grep -o "<title>.*</title>"

    Expected output:

    <title>Welcome to nginx!</title>

    You can see that a request is destined to the root path of the HTTPBin service in the sleep container and a response page of the NGINX service is returned. This indicates that the request is redirected to the NGINX service.