---
title: Bookinfo with a Virtual Machine
description: Run the Bookinfo application with a MySQL service running on a virtual
  machine within your mesh.
weight: 60
keywords:
- virtual-machine
- vms
aliases:
- /docs/examples/integrating-vms/
- /docs/examples/mesh-expansion/bookinfo-expanded
- /docs/examples/vm-bookinfo
---

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.

{{< warning >}}
This example is still under development and only tested on Google Cloud Platform.
On IBM Cloud or other platforms where overlay network of Pods is isolated from VM network,
VMs cannot initiate any direct communication to Kubernetes Pods even when using Istio.
{{< /warning >}}

## Overview

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

<!-- source of the drawing
https://docs.google.com/drawings/d/1G1592HlOVgtbsIqxJnmMzvy6ejIdhajCosxF1LbvspI/edit
 -->

## Before you begin

- Setup Istio by following the instructions in the
  [Installation guide](/docs/setup/getting-started/).

- Deploy the [Bookinfo](/docs/examples/bookinfo/) sample application (in the `bookinfo` namespace).

- Create a VM named 'vm-1' in the same project as the Istio cluster, and [join the mesh](/docs/examples/virtual-machines/single-network/).

## Running MySQL on the VM

We will first install MySQL on the VM, and configure it as a backend for the ratings service.

On the VM:

{{< text bash >}}
$ sudo apt-get update && sudo apt-get install -y mariadb-server
$ sudo mysql
# Grant access to root
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;
quit;
{{< /text >}}

{{< text bash >}}
$ sudo systemctl restart mysql
{{< /text >}}

You can find details of configuring MySQL at [Mysql](https://mariadb.com/kb/en/library/download/).

On the VM add ratings database to mysql.

{{< text bash >}}
$ curl -q {{< github_file >}}/samples/bookinfo/src/mysql/mysqldb-init.sql | mysql -u root -ppassword
{{< /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 -password 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 >}}

## Find out the IP address of the VM that will be used to add it to the mesh

On the VM:

{{< text bash >}}
$ hostname -I
{{< /text >}}

## Registering the mysql service with the mesh

On a host with access to [`istioctl`](/docs/reference/commands/istioctl) commands, register the VM and mysql db service

{{< text bash >}}
$ istioctl register -n vm mysqldb <ip-address-of-vm> 3306
I1108 20:17:54.256699   40419 register.go:43] Registering for service 'mysqldb' ip '10.150.0.5', ports list [{3306 mysql}]
I1108 20:17:54.256815   40419 register.go:48] 0 labels ([]) and 1 annotations ([alpha.istio.io/kubernetes-serviceaccounts=default])
W1108 20:17:54.573068   40419 register.go:123] Got 'services "mysqldb" not found' looking up svc 'mysqldb' in namespace 'vm', attempting to create it
W1108 20:17:54.816122   40419 register.go:138] Got 'endpoints "mysqldb" not found' looking up endpoints for 'mysqldb' in namespace 'vm', attempting to create them
I1108 20:17:54.886657   40419 register.go:180] No pre existing exact matching ports list found, created new subset {[{10.150.0.5  <nil> nil}] [] [{mysql 3306 }]}
I1108 20:17:54.959744   40419 register.go:191] Successfully updated mysqldb, now with 1 endpoints
{{< /text >}}

Note that the 'mysqldb' virtual machine does not need and should not have special Kubernetes privileges.

## 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 >}}
$ istioctl kube-inject -n bookinfo -f @samples/bookinfo/platform/kube/bookinfo-ratings-v2-mysql-vm.yaml@ | kubectl apply -n bookinfo -f -
{{< /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.

You can also find some troubleshooting and other information in the [RawVM MySQL]({{< github_blob >}}/samples/rawvm/README.md) document in the meantime.
