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
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: - route: - destination: host: nginx.default.svc.cluster.local
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.