虚拟机集成

这个例子把 Bookinfo 服务部署到 Kubernetes 集群和一组虚拟机上,然后演示从单一服务网格的角度,如何使用 Istio 来对其进行控制。

这个例子还在开发之中,只在 Google Cloud Platform 上进行了测试。Pod 叠加网络和虚拟机网络之间进行隔离的平台,例如 IBM Cloud,即使有 Istio 的帮助,虚拟机还是无法建立到 Kubernetes Pod 的直接连接的。

概述

网格扩展环境下的 Bookinfo 应用

网格扩展环境下的 Bookinfo 应用

开始之前

  • 依照安装指南部署 Istio。

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

  • 创建一个虚拟机,命名为 vm1,和 Istio 集群处于同一项目之中,并且将其加入集群

在虚拟机上运行 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.2/samples/bookinfo/src/mysql/mysqldb-init.sql | mysql -u root -ppassword

为了更清晰的观察 Bookinfo 应用在输出方面的差异,可以用下面的命令来修改评级记录,从而生成不同的评级显示:

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

修改评级数据:

  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 服务会使用刚才部署的数据库服务。要验证他的工作情况,可以创建 ratings:v2 服务来访问虚拟机上的 MySQL 服务。然后制定路由规则,强制 review 服务使用 ratings:v2

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. $ istioctl create -n bookinfo -f @samples/bookinfo/networking/virtual-service-ratings-mysql-vm.yaml@

可以检查一下 Bookinfo 应用的输出,会看到 Reviewer1 给出了 1 星,而 Reviewer2 给出了 4 星,或者还可以修改虚拟机上的数据来查看变更的结果。

另外可以在 RawVM MySQL 文档中找到除错等方面的详细信息。

相关内容

网格扩展

部署在 Kubernetes 之中的 Istio 服务网格,将虚拟机和物理机集成进入到服务网格的方法。