istio.io/content/en/docs/examples/virtual-machines/index.md

5.1 KiB

title description weight keywords aliases owner test
Bookinfo with a Virtual Machine Run the Bookinfo application with a MySQL service running on a virtual machine within your mesh. 60
virtual-machine
vms
/docs/examples/integrating-vms/
/docs/examples/mesh-expansion/bookinfo-expanded
/docs/examples/virtual-machines/bookinfo/
/docs/examples/vm-bookinfo
istio/wg-environments-maintainers yes

This example deploys the Bookinfo application across Kubernetes with one service running on a virtual machine (VM), and illustrates how to control this infrastructure as a single mesh.

Overview

{{< image width="80%" link="./vm-bookinfo.svg" caption="Bookinfo running on VMs" >}}

Before you begin

Running MySQL on the VM

We will first install MySQL on the VM, and configure it as a backend for the ratings service. All commands below should be run on the VM.

Install mariadb:

{{< text bash >}} $ sudo apt-get update && sudo apt-get install -y mariadb-server $ sudo sed -i '/bind-address/c\bind-address = 0.0.0.0' /etc/mysql/mariadb.conf.d/50-server.cnf {{< /text >}}

Set up authentication:

{{< text bash >}} $ cat <<EOF | sudo mysql

Grant access to root

GRANT ALL PRIVILEGES ON . TO 'root'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;

Grant root access to other IPs

CREATE USER 'root'@'%' IDENTIFIED BY 'password'; GRANT ALL PRIVILEGES ON . TO 'root'@'%' WITH GRANT OPTION; FLUSH PRIVILEGES; quit; EOF $ sudo systemctl restart mysql {{< /text >}}

You can find details of configuring MySQL at Mysql.

On the VM add ratings database to mysql.

{{< text bash >}} $ curl -LO {{< github_file >}}/samples/bookinfo/src/mysql/mysqldb-init.sql $ mysql -u root -ppassword < mysqldb-init.sql {{< /text >}}

To make it easy to visually inspect the difference in the output of the Bookinfo application, you can change the ratings that are generated by using the following commands to inspect the ratings:

{{< text bash >}} $ mysql -u root -ppassword test -e "select * from ratings;" +----------+--------+ | ReviewID | Rating | +----------+--------+ | 1 | 5 | | 2 | 4 | +----------+--------+ {{< /text >}}

and to change the ratings

{{< text bash >}} $ mysql -u root -ppassword test -e "update ratings set rating=1 where reviewid=1;select * from ratings;" +----------+--------+ | ReviewID | Rating | +----------+--------+ | 1 | 1 | | 2 | 4 | +----------+--------+ {{< /text >}}

Expose the mysql service to the mesh

When the virtual machine is started, it will automatically be registered into the mesh. However, just like when creating a Pod, we still need to create a Service before we can easily access it.

{{< text bash >}} $ cat <<EOF | kubectl apply -f - -n vm apiVersion: v1 kind: Service metadata: name: mysqldb labels: app: mysqldb spec: ports:

  • port: 3306 name: tcp selector: app: mysqldb EOF {{< /text >}}

Using the mysql service

The ratings service in Bookinfo will use the DB on the machine. To verify that it works, create version 2 of the ratings service that uses the mysql db on the VM. Then specify route rules that force the review service to use the ratings version 2.

{{< text bash >}} $ kubectl apply -n bookinfo -f @samples/bookinfo/platform/kube/bookinfo-ratings-v2-mysql-vm.yaml@ {{< /text >}}

Create route rules that will force Bookinfo to use the ratings back end:

{{< text bash >}} $ kubectl apply -n bookinfo -f @samples/bookinfo/networking/virtual-service-ratings-mysql-vm.yaml@ {{< /text >}}

You can verify the output of the Bookinfo application is showing 1 star from Reviewer1 and 4 stars from Reviewer2 or change the ratings on your VM and see the results.

Reaching Kubernetes services from the virtual machine

In the above example, we treated our virtual machine as only a server. We can also seamlessly call Kubernetes services from our virtual machine:

{{< text bash >}} $ curl productpage.bookinfo:9080/productpage ...

... {{< /text >}}

Istio's DNS proxying automatically configures DNS for the virtual machine, allowing us to make calls to Kubernetes hostnames.

Cleanup

  • Delete the Bookinfo sample application and its configuration following the steps in Bookinfo cleanup.

  • Delete the mysqldb Service:

    {{< text syntax=bash snip_id=none >}} $ kubectl delete service mysqldb {{< /text >}}

  • Cleanup the VM following the steps in virtual-machine uninstall.