Non-containerized applications cannot be run in containers. This topic describes how to add a non-containerized application that is run on a virtual machine to an Alibaba Cloud Service Mesh (ASM) instance. In this topic, the sample application Bookinfo that Istio provides is used.

Prerequisites

Step 1: Deploy the data plane

  1. Create a namespace named bookinfo.
    1. Run the following command to delete the existing bookinfo namespace:
      kubectl delete namespace bookinfo
    2. Run the following command to create a namespace named bookinfo:
      kubectl create ns bookinfo
    3. Run the following command to enable automatic sidecar injection for the bookinfo namespace:
      kubectl label ns bookinfo istio-injection=enabled
  2. Deploy the Bookinfo application.
    1. Go to the directory of Istio and deploy Bookinfo.
      ISTIO_HOME={Local path of Bookinfo}cd $ISTIO_HOMEkubectl apply -f samples/bookinfo/platform/kube/bookinfo.yaml -n bookinfo
    2. Query microservices of Bookinfo.
      kubectl get services -n bookinfo -o wide
      NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTORdetails ClusterIP 172. **. *.* <none> 9080/TCP 20s app=detailsproductpage ClusterIP 172.1*. *.** <none> 9080/TCP 19s app=productpageratings ClusterIP 172.19. *.*** <none> 9080/TCP 19s app=ratingsreviews ClusterIP 172.19. *.*** <none> 9080/TCP 19s app=reviews
    3. View the pods in the bookinfo namespace. Make sure that the values of READY in the command output are 2/2.
      kubectl get pods -n bookinfo -o wide
      NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATESdetails-v1-5974b67c8-tmhwq 2/2 Running 0 54s 172.18. *.*** cn-beijing.192.168.0.244 <none> <none>productpage-v1-64794f5db4-lxdbd 2/2 Running 0 54s 172.18. *.*** cn-beijing.192.168.0.244 <none> <none>ratings-v1-c6cdf8d98-z67t4 2/2 Running 0 54s 172.18. *.*** cn-beijing.192.168.0.246 <none> <none>reviews-v1-7f6558b974-pxm2g 2/2 Running 0 54s 172.18. *.*** cn-beijing.192.168.0.243 <none> <none>reviews-v2-6cb6ccd848-nm5pk 2/2 Running 0 54s 172.1*. *.** cn-beijing.192.168.0.243 <none> <none>reviews-v3-cc56b578-zf76z 2/2 Running 0 54s 172.18. *.*** cn-beijing.192.168.0.244 <none> <none>
  3. Check whether Bookinfo is deployed.
    kubectl -n bookinfo exec "$(kubectl -n bookinfo get pod -l app=ratings -o jsonpath='{.items[0].metadata.name}')" -c ratings -- curl -s productpage:9080/productpage | grep -o "<title>.*</title>"
    If Bookinfo is deployed, the following command output is returned:
    <title>Simple Bookstore App</title>

Step 2: Deploy the control plane

  1. Create a namespace named bookinfo.
    1. Run the following command to delete the existing bookinfo namespace:
      kubectl --kubeconfig ~/shop_config/asm_bj delete namespace bookinfo
    2. Run the following command to create a namespace named bookinfo:
      kubectl --kubeconfig ~/shop_config/asm_bj create ns bookinfo
    3. Run the following command to enable automatic sidecar injection for the bookinfo namespace:
      kubectl --kubeconfig ~/shop_config/asm_bj label ns bookinfo istio-injection=enabled
  2. Deploy an ingress gateway.
    ISTIO_HOME={Local path of Bookinfo}cd $ISTIO_HOMEkubectl --kubeconfig ~/shop_config/asm_bj apply -f samples/bookinfo/networking/bookinfo-gateway.yaml -n bookinfo
  3. Query the address that is used for external access to Bookinfo.
    export INGRESS_HOST=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.status.loadBalancer.ingress[0].ip}')export INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?( @.name=="http2")].port}')export GATEWAY_URL=$INGRESS_HOST:$INGRESS_PORTecho http://"$GATEWAY_URL/productpage"
  4. Enter the address that is used for external access to Bookinfo in the address bar of a browser. Refresh the page that appears. The page displays ratings without stars, with black stars, and with red stars in turns.
    The following figure shows the architecture of the microservices of Bookinfo. All requests that are sent from the Productpage microservice to the Reviews microservice are evenly routed to the three versions of Reviews.V3

Step 3: Deploy MySQL on virtual machines.

  1. Install MySQL on an ECS instance.
    # alios | centosyum install -y mariadb-server# ubuntuapt-get install -y mariadb-server
  2. Start MySQL.
    systemctl start mariadb
  3. Configure MySQL.
    mysqlGRANT ALL PRIVILEGES ON *. * TO 'root'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;quit;
    The following command output indicates the expected result:
    MariaDB [(none)]> GRANT ALL PRIVILEGES ON *. * TO 'root'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;Query OK, 0 rows affected (0.00 sec)MariaDB [(none)]> quit;Bye
  4. Restart MySQL to make the configuration take effect.
    systemctl restart mariadb
  5. Prepare sample data.
    1. Copy the following code to the mysqldb-init.sql file of the ECS instance where MySQL is installed.
      CREATE DATABASE test;USE test;CREATE TABLE `ratings` ( `ReviewID` INT NOT NULL, `Rating` INT, PRIMARY KEY (`ReviewID`));INSERT INTO ratings (ReviewID, Rating) VALUES (1, 5);INSERT INTO ratings (ReviewID, Rating) VALUES (2, 4);
    2. Create a database named test and a table named ratings. Insert two data entries to the ratings table.
      mysql -u root -ppassword < mysqldb-init.sql
    3. Query the ratings table in the test database to check whether the operations in Substep b succeed.
      mysql -u root --ppassword test -e "select * from ratings;"
      +----------+--------+| ReviewID | Rating |+----------+--------+| 1 | 5 || 2 | 4 |+----------+--------+

Step 4: Add the ECS instance where MySQL is installed to the ASM instance as an application named MySQLdb.

Run the following command to create a service, service entry, and workload entry for MySQLdb:
Note To run the following command, you must run the aliyun servicemesh command on ASM CLI. For more information, see Install and use ASM CLI.
MESH_ID={The ID of the ASM instance}VM={The IP address of the ECS instance}aliyun servicemesh AddVmAppToMesh \ --ServiceMeshId "$MESH_ID" \ --Namespace vm \ --ServiceName mysqldb \ --Ips "$VM" \ --Ports mysql:3306 \ --Labels app=mysql-workload# mysqldb.vm.svc.cluster.local

Step 5: Update the data plane

Create the v2-mysql-vm version for the Ratings microservice.

ISTIO_HOME=~/shop/istio-1.6.9cd $ISTIO_HOMEkubectl apply -f samples/bookinfo/platform/kube/bookinfo-ratings-v2-mysql-vm.yaml -n bookinfo

Step 6: Update the control plane

  1. Create virtual services for the Ratings and Reviews microservices.
    ISTIO_HOME=~/shop/istio-1.6.9cd $ISTIO_HOMEkubectl --kubeconfig ~/shop_config/asm_bj apply -f samples/bookinfo/networking/virtual-service-ratings-mysql-vm.yaml -n bookinfo
  2. Create a destination rule for all the pods of Bookinfo.
    ISTIO_HOME=~/shop/istio-1.6.9cd $ISTIO_HOMEkubectl --kubeconfig ~/shop_config/asm_bj apply -f samples/bookinfo/networking/destination-rule-all.yaml -n bookinfo

Verify the result

  1. Query the address that is used for external access to Bookinfo.
    export INGRESS_HOST=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.status.loadBalancer.ingress[0].ip}')export INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?( @.name=="http2")].port}')export GATEWAY_URL=$INGRESS_HOST:$INGRESS_PORTecho http://"$GATEWAY_URL/productpage"
  2. Enter the address that is used for external access to Bookinfo in the address bar of a browser. Refresh the page that appears. The page remains the same all the time. The Reviewer1 section displays five stars and the Reviewer2 section displays four stars.
    The following figure shows the new architecture of the microservices of Bookinfo. All requests that are sent from the Productpage microservice to the Reviews microservice are routed to the v3 version of Reviews. All requests to the Ratings microservice are routed to the v2-mysql-vm version.v2
  3. Update the database.
    mysql -u root -ppassword test -e "update ratings set rating=1 where reviewid=1;select * from ratings;"
    [root@iZ2zedxgqw4190znx2wv9wZ ~]# mysql -u root -ppassword test -e "update ratings set rating=3 where reviewid=1;select * from ratings;"+----------+--------+| ReviewID | Rating |+----------+--------+| 1 | 3 || 2 | 4 |+----------+--------+
  4. Enter the address that is used for external access to Bookinfo in the address bar of a browser. Refresh the page that appears. The page remains the same all the time. The Reviewer1 section displays three stars and the Reviewer2 section displays four stars.
    review