在虚拟机上部署 Bookinfo 应用程序

本示例通过在虚拟机(VM)上运行一项服务来跨 Kubernetes 部署 Bookinfo 应用程序,并说明了如何以单个网格的形式控制此基础架构。

此示例仍在开发中,仅在 Google Cloud Platform 上进行了测试。 在 Pod 的覆盖网络与 VM 网络隔离的 IBM Cloud 或其他平台上, 即使使用 Istio,虚拟机也无法与 Kubernetes Pod 进行任何直接通信活动。

概述

Bookinfo running on VMs

Bookinfo running on VMs

开始之前

  • 按照安装指南中的说明安装 Istio。

  • 部署 Bookinfo 示例应用程序(在 bookinfo 命名空间中)。

  • 在与 Istio 集群相同的项目中创建一个名为 ‘vm-1’ 的虚拟机,然后加入网格

在 VM 上运行 MySQL

我们将首先在虚拟机上安装 MySQL,并将其配置为 ratings 服务的后端。

在虚拟机上:

  1. $ sudo apt-get update && sudo apt-get install -y mariadb-server
  2. $ sudo mysql
  3. # 授予 root 的访问权限
  4. GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;
  5. quit;
  1. $ sudo systemctl restart mysql

您可以在 Mysql 中找到配置 MySQL 的详细信息。

在虚拟机上,将 ratings 数据库添加到 mysql 中。

  1. $ curl -q https://raw.githubusercontent.com/istio/istio/release-1.9/samples/bookinfo/src/mysql/mysqldb-init.sql | mysql -u root -ppassword

为了便于直观地检查 Bookinfo 应用程序输出中的差异,您可以使用以下命令来更改所生成的 ratings 数据库并且检查它:

  1. $ mysql -u root -password test -e "select * from ratings;"
  2. +----------+--------+
  3. | ReviewID | Rating |
  4. +----------+--------+
  5. | 1 | 5 |
  6. | 2 | 4 |
  7. +----------+--------+

更改 ratings 数据库:

  1. $ mysql -u root -ppassword test -e "update ratings set rating=1 where reviewid=1;select * from ratings;"
  2. +----------+--------+
  3. | ReviewID | Rating |
  4. +----------+--------+
  5. | 1 | 1 |
  6. | 2 | 4 |
  7. +----------+--------+

找出将用于添加到网格中的虚拟机的 IP 地址

在虚拟机上:

  1. $ hostname -I

向网格中注册 mysql 服务

在可以访问 istioctl 命令的主机上,注册虚拟机和 mysql 数据库服务。

  1. $ istioctl register -n vm mysqldb <ip-address-of-vm> 3306
  2. I1108 20:17:54.256699 40419 register.go:43] Registering for service 'mysqldb' ip '10.150.0.5', ports list [{3306 mysql}]
  3. I1108 20:17:54.256815 40419 register.go:48] 0 labels ([]) and 1 annotations ([alpha.istio.io/kubernetes-serviceaccounts=default])
  4. 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
  5. 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
  6. 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 }]}
  7. I1108 20:17:54.959744 40419 register.go:191] Successfully updated mysqldb, now with 1 endpoints

请注意,’mysqldb’ 虚拟机不需要也不应具有特殊的 Kubernetes 特权。

使用 mysql 服务

Bookinfo 中的 ratings 服务将使用该虚拟机上的数据库。为了验证它是否正常工作,请在虚拟机上创建使用 mysql 数据库的 ratings 服务第二个版本。然后指定路由规则,用于强制 review 服务使用 ratings 服务的第二个版本。

Zip

  1. $ istioctl kube-inject -n bookinfo -f @samples/bookinfo/platform/kube/bookinfo-ratings-v2-mysql-vm.yaml@ | kubectl apply -n bookinfo -f -

创建将强制 Bookinfo 使用 ratings 后端的路由规则:

Zip

  1. $ kubectl apply -n bookinfo -f @samples/bookinfo/networking/virtual-service-ratings-mysql-vm.yaml@

您可以验证 Bookinfo 应用程序的输出显示的是 Reviewer1 的 1 个星,还是 Reviewer2 的 4 个星,或者更改虚拟机的 ratings 服务并查看结果。

同时,您还可以在 RawVM MySQL 文档中找到一些疑难解答和其他信息。

相关内容

多网络网格中的虚拟机

学习怎样添加运行在虚拟机上的服务到您的多网络 Istio 网格中。

虚拟机安装

部署 Istio,接入虚拟机中运行的工作负载。

单个网络网格中的虚拟机

学习如何新增一个服务,使其运行在单网络 Istio 网格的虚拟机上。