Integrating Virtual Machines

这个例子跨k8s和一些虚拟机来部署Bookinfo,讲述如何使用Istio服务网格将这个架构当作单一网格进行操作。

注意:这个指南还在开发阶段,并且仅在Google Cloud平台进行了测试。在IBM Cloud或其他平台上隔离VM网络并覆盖Pod网络的情况下,即使使用Istio,VM也不能和K8s Pods进行任何直接通信。

Overview

这里写图片描述

Before you begin

  • 按照 Installation guide 的指示安装Istio。
  • 部署 Bookinfo 示例应用(在命名空间bookinfo 中)
  • 在与Istio集群相同的项目中创建一个名为 ‘vm-1’的VM,并 Join the Mesh

Running mysql on the VM

我们首先在VM中安装mysql,并把它配置成ratings服务的后端服务。
在VM上:

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;
sudo systemctl restart mysql

你可以在Mysql 中找到更多关于mysql配置的细节。
在VM上将ratings的数据添加到mysql中:

# Add ratings db to the mysql db
curl -q https://raw.githubusercontent.com/istio/istio/master/samples/bookinfo/src/mysql/mysqldb-init.sql | mysql -u root -ppassword

为了便于直观的检查bookinfo应用的输出差异,可以使用下列命令生成ratings:

# To inspect the ratings
mysql -u root -ppassword test -e "select * from ratings;"
+----------+--------+
| ReviewID | Rating |
+----------+--------+
|        1 |      5 |
|        2 |      4 |
+----------+--------+
# To change the ratings
mysql -u root -ppassword test -e  "update ratings set rating=1 where reviewid=1;select * from ratings;"
+----------+--------+
| ReviewID | Rating |
+----------+--------+
|        1 |      1 |
|        2 |      4 |
+----------+--------+

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

在VM上:

hostname -I

Registering the mysql service with the mesh

在可以使用istioctl 命令的主机上,注册VM和mysql db服务

istioctl register -n vm mysqldb <ip-address-of-vm> 3306

输出如下:

$ istioctl register -n vm mysqldb 10.150.0.5 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

注意 ‘mysqldb’虚拟机不需要也不应该有特殊的k8s权限。

Using the mysql service

bookinfo的ratings服务将使用机器上的数据库。为了验证它是否工作,创建使用VM mysql db的v2版本ratings服务。然后指定路由规则,强制review服务使用v2版本的ratings服务。

# Create the version of ratings service that will use mysql back end
istioctl kube-inject -n bookinfo -f samples/bookinfo/kube/bookinfo-ratings-v2-mysql-vm.yaml | kubectl apply -n bookinfo -f -
# Create route rules that will force bookinfo to use the ratings back end
istioctl create -n bookinfo -f samples/bookinfo/kube/route-rule-ratings-mysql-vm.yaml

你可以确认book nfo应用的输出,Reviewer1 展示1星,Reviewer2 展示4星,或者改变你的VM上的ratings并查看结果。

同时,你可以在 RawVM MySQL 文档中发现一些故障和其他信息。

猜你喜欢

转载自blog.csdn.net/ybt_c_index/article/details/80339344