diff --git a/content/zh/docs/examples/virtual-machines/_index.md b/content/zh/docs/examples/virtual-machines/_index.md deleted file mode 100644 index 690365badc..0000000000 --- a/content/zh/docs/examples/virtual-machines/_index.md +++ /dev/null @@ -1,13 +0,0 @@ ---- -title: 虚拟机 -description: 将虚拟机中运行的工作负载添加到 Istio 网格的示例。 -weight: 30 -aliases: -- /zh/docs/examples/mesh-expansion/ -- /zh/docs/examples/mesh-expansion -- /zh/docs/tasks/virtual-machines -keywords: -- kubernetes -- vms -- virtual-machine ---- diff --git a/content/zh/docs/examples/virtual-machines/bookinfo/index.md b/content/zh/docs/examples/virtual-machines/bookinfo/index.md deleted file mode 100644 index 4c07e0c155..0000000000 --- a/content/zh/docs/examples/virtual-machines/bookinfo/index.md +++ /dev/null @@ -1,128 +0,0 @@ ---- -title: 在虚拟机上部署 Bookinfo 应用程序 -description: 使用在网格内的虚拟机上运行的 MySQL 服务运行 Bookinfo 应用程序。 -weight: 60 -keywords: -- virtual-machine -- vms -aliases: -- /zh/docs/examples/integrating-vms/ -- /zh/docs/examples/mesh-expansion/bookinfo-expanded -- /zh/docs/examples/vm-bookinfo ---- - -本示例通过在虚拟机(VM)上运行一项服务来跨 Kubernetes 部署 Bookinfo 应用程序,并说明了如何以单个网格的形式控制此基础架构。 - -{{< warning >}} -此示例仍在开发中,仅在 Google Cloud Platform 上进行了测试。 -在 Pod 的覆盖网络与 VM 网络隔离的 IBM Cloud 或其他平台上, -即使使用 Istio,虚拟机也无法与 Kubernetes Pod 进行任何直接通信活动。 -{{< /warning >}} - -## 概述{#overview} - -{{< image width="80%" link="./vm-bookinfo.svg" caption="Bookinfo running on VMs" >}} - - - -## 开始之前{#before-you-begin} - -- 按照[安装指南](/zh/docs/setup/getting-started/)中的说明安装 Istio。 - -- 部署 [Bookinfo](/zh/docs/examples/bookinfo/) 示例应用程序(在 `bookinfo` 命名空间中)。 - -- 在与 Istio 集群相同的项目中创建一个名为 'vm-1' 的虚拟机,然后[加入网格](/zh/docs/examples/virtual-machines/single-network/)。 - -## 在 VM 上运行 MySQL{#running-MySQL-on-the-VM} - -我们将首先在虚拟机上安装 MySQL,并将其配置为 ratings 服务的后端。 - -在虚拟机上: - -{{< text bash >}} -$ sudo apt-get update && sudo apt-get install -y mariadb-server -$ sudo mysql -# 授予 root 的访问权限 -GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION; -quit; -{{< /text >}} - -{{< text bash >}} -$ sudo systemctl restart mysql -{{< /text >}} - -您可以在 [Mysql](https://mariadb.com/kb/en/library/download/) 中找到配置 MySQL 的详细信息。 - -在虚拟机上,将 ratings 数据库添加到 mysql 中。 - -{{< text bash >}} -$ curl -q {{< github_file >}}/samples/bookinfo/src/mysql/mysqldb-init.sql | mysql -u root -ppassword -{{< /text >}} - -为了便于直观地检查 Bookinfo 应用程序输出中的差异,您可以使用以下命令来更改所生成的 ratings 数据库并且检查它: - -{{< text bash >}} -$ mysql -u root -password test -e "select * from ratings;" -+----------+--------+ -| ReviewID | Rating | -+----------+--------+ -| 1 | 5 | -| 2 | 4 | -+----------+--------+ -{{< /text >}} - -更改 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 >}} - -## 找出将用于添加到网格中的虚拟机的 IP 地址{#find-out-the-IP-address-of-the-VM-that-will-be-used-to-add-it-to-the-mesh} - -在虚拟机上: - -{{< text bash >}} -$ hostname -I -{{< /text >}} - -## 向网格中注册 mysql 服务{#registering-the-mysql-service-with-the-mesh} - -在可以访问 [`istioctl`](/zh/docs/reference/commands/istioctl) 命令的主机上,注册虚拟机和 mysql 数据库服务。 - -{{< text bash >}} -$ istioctl register -n vm mysqldb 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}] [] [{mysql 3306 }]} -I1108 20:17:54.959744 40419 register.go:191] Successfully updated mysqldb, now with 1 endpoints -{{< /text >}} - -请注意,'mysqldb' 虚拟机不需要也不应具有特殊的 Kubernetes 特权。 - -## 使用 mysql 服务{#using-the-mysql-service} - -Bookinfo 中的 ratings 服务将使用该虚拟机上的数据库。为了验证它是否正常工作,请在虚拟机上创建使用 mysql 数据库的 ratings 服务第二个版本。然后指定路由规则,用于强制 review 服务使用 ratings 服务的第二个版本。 - -{{< text bash >}} -$ istioctl kube-inject -n bookinfo -f @samples/bookinfo/platform/kube/bookinfo-ratings-v2-mysql-vm.yaml@ | kubectl apply -n bookinfo -f - -{{< /text >}} - -创建将强制 Bookinfo 使用 ratings 后端的路由规则: - -{{< text bash >}} -$ kubectl apply -n bookinfo -f @samples/bookinfo/networking/virtual-service-ratings-mysql-vm.yaml@ -{{< /text >}} - -您可以验证 Bookinfo 应用程序的输出显示的是 Reviewer1 的 1 个星,还是 Reviewer2 的 4 个星,或者更改虚拟机的 ratings 服务并查看结果。 - -同时,您还可以在 [RawVM MySQL]({{< github_blob >}}/samples/rawvm/README.md) 文档中找到一些疑难解答和其他信息。 diff --git a/content/zh/docs/examples/virtual-machines/index.md b/content/zh/docs/examples/virtual-machines/index.md new file mode 100644 index 0000000000..c8227914a6 --- /dev/null +++ b/content/zh/docs/examples/virtual-machines/index.md @@ -0,0 +1,144 @@ +--- +title: 在虚拟机上部署 Bookinfo 应用程序 +description: 使用在网格内的虚拟机上运行的 MySQL 服务运行 Bookinfo 应用程序。 +weight: 60 +keywords: +- virtual-machine +- vms +aliases: +- /zh/docs/examples/integrating-vms/ +- /zh/docs/examples/mesh-expansion/bookinfo-expanded +- /zh/docs/examples/virtual-machines/bookinfo/ +- /zh/docs/examples/vm-bookinfo +owner: istio/wg-environments-maintainers +test: yes +--- + +本示例通过在虚拟机(VM)上运行一项服务来跨 Kubernetes 部署 Bookinfo 应用程序,并说明了如何以单个网格的形式控制此基础架构。 + +## 概述{#overview} + +{{< image width="80%" link="./vm-bookinfo.svg" caption="在虚机上运行 Bookinfo" >}} + + + +## 开始之前{#before-you-begin} + +- 按照[虚拟机安装引导](/zh/docs/setup/install/virtual-machine/)的介绍来配置 Istio。 + +- 部署 [Bookinfo](/zh/docs/examples/bookinfo/) 示例应用(在 `bookinfo` 命名空间下)。 + +- 按照[虚拟机配置](/zh/docs/setup/install/virtual-machine/#configure-the-virtual-machine)创建一个虚拟机并添加到 `vm` 命名空间下。 + +## 在虚拟机上运行 MySQL{#running-MySQL-on-the-VM} + +您将在虚拟机上安装 MySQL,并将其配置为 ratings 服务的后端。 + +下列的所有命令都在虚机上执行。 + +安装 `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 >}} + +设置认证信息: + +{{< text bash >}} +$ cat <}} + +您可以在 [Mysql](https://mariadb.com/kb/en/library/download/) 中找到配置 MySQL 的详细信息。 + +在虚拟机上,将 ratings 数据库添加到 mysql 中。 + +{{< text bash >}} +$ curl -LO {{< github_file >}}/samples/bookinfo/src/mysql/mysqldb-init.sql +$ mysql -u root -ppassword < mysqldb-init.sql +{{< /text >}} + +为了便于直观地检查 Bookinfo 应用程序输出中的差异,您可以使用以下命令来更改所生成的 ratings 数据库并且检查它: + +{{< text bash >}} +$ mysql -u root -ppassword test -e "select * from ratings;" ++----------+--------+ +| ReviewID | Rating | ++----------+--------+ +| 1 | 5 | +| 2 | 4 | ++----------+--------+ +{{< /text >}} + +更改 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 >}} + +## 向网格中注册 mysql 服务{#registering-the-mysql-service-with-the-mesh} + +当虚机启动时,将会自动被注册到网格中。然而,就像我们创建一个 Pod 一样,在更加便捷的访问之前需要创建一个 Service 。 + +{{< text bash >}} +$ cat <}} + +## 使用 mysql 服务{#using-the-mysql-service} + +Bookinfo 中的 ratings 服务将使用该虚拟机上的数据库。为了验证它是否正常工作,请在虚拟机上创建使用 mysql 数据库的 ratings 服务第二个版本。然后指定路由规则,用于强制 review 服务使用 ratings 服务的第二个版本。 + +{{< text bash >}} +$ kubectl apply -n bookinfo -f @samples/bookinfo/platform/kube/bookinfo-ratings-v2-mysql-vm.yaml@ +{{< /text >}} + +创建强制 Bookinfo 使用 ratings 后端的路由规则: + +{{< text bash >}} +$ kubectl apply -n bookinfo -f @samples/bookinfo/networking/virtual-service-ratings-mysql-vm.yaml@ +{{< /text >}} + +您可以验证 Bookinfo 应用程序的输出显示的是 Reviewer1 的 1 个星,还是 Reviewer2 的 4 个星,或者更改虚拟机的 ratings 服务并查看结果。 + +## 从虚机访问 Kubernetes 服务{#reaching-Kubernetes-services-from-the-virtual-machine} + +在上面的示例中,我们将虚拟机视为一个服务。 您还可以在您的虚拟机中无缝调用 Kubernetes 的服务: + +{{< text bash >}} +$ curl productpage.bookinfo:9080 +... +Simple Bookstore App +... +{{< /text >}} + +Istio 的 [DNS 代理](/zh/docs/ops/configuration/traffic-management/dns-proxy/)自动为您的虚机配置 DNS , 允许我们 Kubernetes 的主机名进行访问。 diff --git a/content/zh/docs/examples/virtual-machines/multi-network/index.md b/content/zh/docs/examples/virtual-machines/multi-network/index.md deleted file mode 100644 index 646a0bddfe..0000000000 --- a/content/zh/docs/examples/virtual-machines/multi-network/index.md +++ /dev/null @@ -1,325 +0,0 @@ ---- -title: 多网络网格中的虚拟机 -description: 学习怎样添加运行在虚拟机上的服务到您的多网络 Istio 网格中。 -weight: 30 -keywords: -- kubernetes -- virtual-machine -- gateways -- vms -aliases: -- /zh/docs/examples/mesh-expansion/multi-network -- /zh/docs/tasks/virtual-machines/multi-network ---- - -本示例演示如何利用网关整合一个 VM 或一个裸机到部署在 Kubernetes 上的多网络 Istio 网格中。这种方式不要求 VM,裸机和集群之间可以通过 VPN 连通或者直接的网络访问。 - -## 前提条件{#prerequisites} - -- 一个或者多个 Kubernetes 集群,支持版本为:{{< supported_kubernetes_versions >}}。 -- 虚拟机(VMs)必须可以通过 IP 连接网格中的 Ingress 网关。 - -## 安装步骤{#installation-steps} - -设置内容包括准备网格用于扩展,安装和配置各个 VM 。 - -### 集群上定制化安装 Istio {#customized-installation-of-Istio-on-the-cluster} - -当添加非 Kubernetes 的服务到 Istio 网格时,第一步是 Istio 本身的安装配置,并生成让 VMs 连接到网格的配置文件。为 VM 准备集群需要使用集群管理员权限在一台机器上执行如下命令: - -1. 为您的生成的 CA 证书创建 Kubernetes secret,使用如下命令。查看 [Certificate Authority (CA) certificates](/zh/docs/tasks/security/plugin-ca-cert/#plugging-in-the-existing-certificate-and-key) 获取更多细节。 - - {{< warning >}} - 样本目录中的 root 证书和中间证书已经大范围分发并被识别。**不能** 在生产环境中使用这些证书,否则您的集群容易受到安全漏洞和破坏的威胁。 - {{< /warning >}} - - {{< text bash >}} - $ kubectl create namespace istio-system - $ kubectl create secret generic cacerts -n istio-system \ - --from-file=@samples/certs/ca-cert.pem@ \ - --from-file=@samples/certs/ca-key.pem@ \ - --from-file=@samples/certs/root-cert.pem@ \ - --from-file=@samples/certs/cert-chain.pem@ - {{< /text >}} - -1. 集群中部署 Istio 控制平面 - - {{< text bash >}} - $ istioctl manifest apply \ - -f install/kubernetes/operator/examples/vm/values-istio-meshexpansion-gateways.yaml \ - --set coreDNS.enabled=true - {{< /text >}} - - 更多细节和定制选项,参考 [installation instructions](/zh/docs/setup/install/istioctl/)。 - -1. 为 VM 的服务创建 `vm` 命名空间 - - {{< text bash >}} - $ kubectl create ns vm - {{< /text >}} - -1. 定义命名空间,供 VM 加入。本示例使用 `SERVICE_NAMESPACE` 环境变量保存命名空间。这个环境变量的值必须与您后面在配置文件中使用的命名空间匹配。 - - {{< text bash >}} - $ export SERVICE_NAMESPACE="vm" - {{< /text >}} - -1. 取得初始密钥,服务账户需要在 VMs 上使用。 - - {{< text bash >}} - $ kubectl -n $SERVICE_NAMESPACE get secret istio.default \ - -o jsonpath='{.data.root-cert\.pem}' | base64 --decode > root-cert.pem - $ kubectl -n $SERVICE_NAMESPACE get secret istio.default \ - -o jsonpath='{.data.key\.pem}' | base64 --decode > key.pem - $ kubectl -n $SERVICE_NAMESPACE get secret istio.default \ - -o jsonpath='{.data.cert-chain\.pem}' | base64 --decode > cert-chain.pem - {{< /text >}} - -1. 确定并保存 Istio Ingress gateway 的 IP 地址,VMs 会通过这个 IP 地址访问 [Citadel](/zh/docs/concepts/security/) , - [Pilot](/zh/docs/ops/deployment/architecture/#pilot) 和集群中的工作负载。 - - {{< text bash >}} - $ export GWIP=$(kubectl get -n istio-system service istio-ingressgateway -o jsonpath='{.status.loadBalancer.ingress[0].ip}') - $ echo $GWIP - 35.232.112.158 - {{< /text >}} - -1. 生成一个 `cluster.env` 配置并部署到 VMs 中。这个文件包含会被 Envoy 拦截和转发 Kubernetes 集群 IP 地址段。 - - {{< text bash >}} - $ echo -e "ISTIO_CP_AUTH=MUTUAL_TLS\nISTIO_SERVICE_CIDR=$ISTIO_SERVICE_CIDR\n" > cluster.env - {{< /text >}} - -1. 检查生成的 `cluster.env` 文件内容。它应该和下面示例类似: - - {{< text bash >}} - $ cat cluster.env - ISTIO_CP_AUTH=MUTUAL_TLS - ISTIO_SERVICE_CIDR=172.21.0.0/16 - {{< /text >}} - -1. 如果 VM 只是调用网格中的服务,您可以跳过这一步。否则,通过如下命令添加 VM 暴露的端口到 `cluster.env` 文件中。如果有必要,您后面还能修改这些端口。 - - {{< text bash >}} - $ echo "ISTIO_INBOUND_PORTS=8888" >> cluster.env - {{< /text >}} - -### 设置 DNS {#setup-DNS} - -参考 [Setup DNS](/zh/docs/setup/install/multicluster/gateways/#setup-DNS) 设置集群 DNS 。 - -### 设置 VM {#setting-up-the-VM} - -下一步,在每台您想要添加到网格中的机器上执行如下命令: - -1. 拷贝之前创建的 `cluster.env` 和 `*.pem` 到 VM 中。 - -1. 安装 Envoy sidecar 的 Debian 包。 - - {{< text bash >}} - $ curl -L https://storage.googleapis.com/istio-release/releases/{{< istio_full_version >}}/deb/istio-sidecar.deb > istio-sidecar.deb - $ sudo dpkg -i istio-sidecar.deb - {{< /text >}} - -1. 添加 Istio gateway 的 IP 地址到 `/etc/hosts` 中。重新查看[集群上定制化安装 Istio](#customized-installation-of-Istio-on-the-cluster) 部分学习怎样获取 IP 地址。 -下面的示例演示更新 `/etc/hosts` 文件中的 Istio gateway 地址: - - {{< text bash >}} - $ echo "35.232.112.158 istio-citadel istio-pilot istio-pilot.istio-system" | sudo tee -a /etc/hosts - {{< /text >}} - -1. 安装 `root-cert.pem`, `key.pem` 和 `cert-chain.pem` 到 `/etc/certs/` 下。 - - {{< text bash >}} - $ sudo mkdir -p /etc/certs - $ sudo cp {root-cert.pem,cert-chain.pem,key.pem} /etc/certs - {{< /text >}} - -1. 安装 `cluster.env` 到 `/var/lib/istio/envoy/` 下。 - - {{< text bash >}} - $ sudo cp cluster.env /var/lib/istio/envoy - {{< /text >}} - -1. 移交 `/etc/certs/` 和 `/var/lib/istio/envoy/` 下的文件所有权给 Istio proxy 。 - - {{< text bash >}} - $ sudo chown -R istio-proxy /etc/certs /var/lib/istio/envoy - {{< /text >}} - -1. 使用 `systemctl` 启动 Istio 。 - - {{< text bash >}} - $ sudo systemctl start istio-auth-node-agent - $ sudo systemctl start istio - {{< /text >}} - -## 添加 Istio 资源{#added-Istio-resources} - -下面的 Istio 资源结合 gateways 一起对添加 VMs 到网格中做支持。这些资源让 VM 和 集群摆脱了扁平网络的要求。 - -| 资源类型| 资源名字 | 功能 | -| ---------------------------- |--------------------------- | ----------------- | -| `configmap` | `coredns` | Send *.global request to `istiocordns` service | -| `service` | `istiocoredns` | Resolve *.global to Istio Ingress gateway | -| `gateway.networking.istio.io` | `meshexpansion-gateway` | Open port for Pilot, Citadel and Mixer | -| `gateway.networking.istio.io` | `istio-multicluster-ingressgateway`| Open port 15443 for inbound *.global traffic | -| `envoyfilter.networking.istio.io` | `istio-multicluster-ingressgateway`| Transform `*.global` to `*. svc.cluster.local` | -| `destinationrule.networking.istio.io`| `istio-multicluster-destinationrule`| Set traffic policy for 15443 traffic | -| `destinationrule.networking.istio.io`| `meshexpansion-dr-pilot` | Set traffic policy for `istio-pilot` | -| `destinationrule.networking.istio.io`| `istio-policy` | Set traffic policy for `istio-policy` | -| `destinationrule.networking.istio.io`| `istio-telemetry` | Set traffic policy for `istio-telemetry` | -| `virtualservice.networking.istio.io` | `meshexpansion-vs-pilot` | Set route info for `istio-pilot` | -| `virtualservice.networking.istio.io` | `meshexpansion-vs-citadel` | Set route info for `istio-citadel` | - -## 暴露在集群上运行的服务到 VMs {#expose-service-running-on-cluster-to-VMs} - -集群中每个需要被 VM 访问到的服务必须在集群中添加一个 service entry 配置。Service entry 中的 host 要求格式为 `..global`,其中 name 和 namespace 分别对应服务中的名字和命名空间。 - -在集群中配置 [httpbin service]({{< github_tree >}}/samples/httpbin) ,演示 VM 怎样访问集群中的服务。 - -1. 在集群中部署 `httpbin` 。 - - {{< text bash >}} - $ kubectl create namespace bar - $ kubectl label namespace bar istio-injection=enabled - $ kubectl apply -n bar -f @samples/httpbin/httpbin.yaml@ - {{< /text >}} - -1. 在集群中为 `httpbin` 服务创建 service entry 。 - - 为了 VM 中的服务能够访问到集群中的 `httpbin` ,我们需要为它创建一个 service entry。Service entry 中的 host 值要求格式为 `..global`,其中 name 和 namespace 分别对应远程服务中的名字和命名空间。 - - 因为 DNS 解析 `*.global` 域上的服务,您需要为这些服务分配一个 IP 地址。 - - {{< tip >}} - 各个服务(`*.global` DNS 域中)必须在集群中有一个唯一的 IP。 - {{< /tip >}} - - 如果全局服务已经有真正的 VIPs,您可以使用它们,否则我们建议使用来自回环段 `127.0.0.0/8` 的还未分配的 IPs 。这些 IPs 在 pod 外不能路由。 - - 本示例中我们使用 `127.255.0.0/16` 中的 IPs 避免和常用的 IPs 例如 `127.0.0.1` (`localhost`) 产生冲突。 - - 使用这些 IPs 的应用流量将被 sidecar 捕获并路由到合适的远程服务上。 - - {{< text bash >}} - $ kubectl apply -n bar -f - <}} - - 上述配置会让来自 VMs 的 地址为 `httpbin.bar.global` 的 *any port* 的所有流量通过双向 TLS 连接被路由到指定 endpoint `:15443` 。 - - 端口为 15443 的 gateway 是一个特殊的 SNI-aware Envoy,作为结合 gateway 的网格扩张的部分在 Istio 安装部署步骤部分做了配置和安装。进入端口 15443 的流量会在目标集群中合适的内部服务的 pods 上做负载均衡(本例子,是集群中的 `httpbin.bar`)。 - - {{< warning >}} - 禁止为端口 15443 创建 `Gateway` 配置。 - {{< /warning >}} - -## 从 VM 发送请求到 Kubernetes 中的服务{#send-requests-from-VM-to-Kubernetes-services} - -机器在安装以后,就能访问运行在 Kubernetes 集群中的服务。 - -下面的示例演示一个使用 `/etc/hosts/` 的 VM 访问运行在 Kubernetes 集群中的服务。这个服务来自 [httpbin service]({{}}/samples/httpbin)。 - -1. 在添加的 VM 上,添加服务名字和地址到它的 `/etc/hosts` 文件中。您就可以从该 VM 连接集群上的服务了,例子如下: - - {{< text bash >}} -$ echo "127.255.0.3 httpbin.bar.global" | sudo tee -a /etc/hosts -$ curl -v httpbin.bar.global:8000 -< HTTP/1.1 200 OK -< server: envoy -< content-type: text/html; charset=utf-8 -< content-length: 9593 - -... html content ... - {{< /text >}} - -`server: envoy` header 表示 sidecar 拦截了这个流量。 - -## 在添加的 VM 上运行服务{#running-services-on-the-added-VM} - -1. 在 VM 实例上安装一个 HTTP 服务器处理来自端口 8888 的 HTTP 流量: - - {{< text bash >}} - $ python -m SimpleHTTPServer 8888 - {{< /text >}} - -1. 指定 VM 实例的 IP 地址。 - -1. 添加 VM 服务到网格中 - - {{< text bash >}} - $ istioctl experimental add-to-mesh external-service vmhttp ${VM_IP} http:8888 -n ${SERVICE_NAMESPACE} - {{< /text >}} - - {{< tip >}} - 确认您已经将 `istioctl` 客户端添加到您的路径下,这在 [download page](/zh/docs/setup/getting-started/#download) 有讲到。 - {{< /tip >}} - -1. 在 Kubernetes 集群中部署一个运行 `sleep` 服务的 pod,并等待它的状态变为 ready: - - {{< text bash >}} - $ kubectl apply -f @samples/sleep/sleep.yaml@ - $ kubectl get pod - NAME READY STATUS RESTARTS AGE - sleep-88ddbcfdd-rm42k 2/2 Running 0 1s - ... - {{< /text >}} - -1. 从运行在 pod 上的 `sleep` 服务发送请求给 VM 的 HTTP 服务: - - {{< text bash >}} - $ kubectl exec -it sleep-88ddbcfdd-rm42k -c sleep -- curl vmhttp.${SERVICE_NAMESPACE}.svc.cluster.local:8888 - {{< /text >}} - - 如果配置正确,您将会看到如下类似输出: - - {{< text html >}} - - Directory listing for / - -

Directory listing for /

-
-
    -
  • .bashrc
  • -
  • .ssh/
  • - ... - - {{< /text >}} - -**恭喜!** 您成功配置一个运行在集群 pod 上的服务,发送流量给运行在一个集群外的 VM 上的服务并测试配置是否生效。 - -## 清除{#cleanup} - -执行如下命令从网格的抽象模型中移除扩展的 VM。 - -{{< text bash >}} -$ istioctl experimental remove-from-mesh -n ${SERVICE_NAMESPACE} vmhttp -Kubernetes Service "vmhttp.vm" has been deleted for external service "vmhttp" -Service Entry "mesh-expansion-vmhttp" has been deleted for external service "vmhttp" -{{< /text >}} diff --git a/content/zh/docs/examples/virtual-machines/single-network/index.md b/content/zh/docs/examples/virtual-machines/single-network/index.md deleted file mode 100644 index 56dc395808..0000000000 --- a/content/zh/docs/examples/virtual-machines/single-network/index.md +++ /dev/null @@ -1,321 +0,0 @@ ---- -title: 单个网络网格中的虚拟机 -description: 学习如何新增一个服务,使其运行在单网络 Istio 网格的虚拟机上。 -weight: 20 -keywords: -- kubernetes -- vms -- virtual-machines -aliases: -- /zh/docs/setup/kubernetes/additional-setup/mesh-expansion/ -- /zh/docs/examples/mesh-expansion/single-network -- /zh/docs/tasks/virtual-machines/single-network ---- - -此示例显示如何将 VM 或者本地裸机集成到 Kubernetes 上部署的单网络 Istio 网格中。 - -## 准备环境{#prerequisites} - -- 您已经在 Kubernetes 上部署了 Istio。如果尚未这样做, - 则可以在[安装指南](/zh/docs/setup/getting-started/)中找到方法。 - -- 虚拟机(VM)必须具有网格中 endpoint 的 IP 连接。 - 这通常需要 VPC 或者 VPN,以及需要提供直接(没有 NAT 或者防火墙拒绝访问) - 路由到 endpoint 的容器网络。虚拟机不需要访问 Kubernetes 分配的集群 IP 地址。 - -- VM 必须有权访问 DNS 服务,将名称解析为集群 IP 地址。 - 选项包括通过内部负载均衡器,使用 [Core DNS](https://coredns.io/) 服务公开的 Kubernetes DNS 服务器,或者在可从 VM 中访问的任何其他 DNS 服务器中配置 IP。 - -具有以下说明: - -- 假设扩展 VM 运行在 GCE 上。 -- 使用 Google 平台的特定命令执行某些步骤。 - -## 安装步骤{#installation-steps} - -安装并配置每个虚拟机,设置准备用于扩展的网格。 - -### 为虚拟机准备 Kubernetes 集群{#preparing-the-Kubernetes-cluster-for-VMs} - -当将非 Kubernetes 服务添加到 Istio 网格中时,首先配置 Istio 它自己的设施,并生成配置文件使 VM 连接网格。在具有集群管理员特权的计算机上,使用以下命令为 VM 准备集群: - -1. 使用类似于以下的命令,为生成的 CA 证书创建 Kubernetes secret。请参阅[证书办法机构 (CA) 证书](/zh/docs/tasks/security/plugin-ca-cert/#plugging-in-the-existing-certificate-and-key)获取更多的详细信息。 - - {{< warning >}} - 样本目录中的 root 证书和中间证书已经大范围分发并被识别。 - **不能** 在生产环境中使用这些证书,否则您的集群容易受到安全漏洞和破坏的威胁。 - {{< /warning >}} - - {{< text bash >}} - $ kubectl create namespace istio-system - $ kubectl create secret generic cacerts -n istio-system \ - --from-file=@samples/certs/ca-cert.pem@ \ - --from-file=@samples/certs/ca-key.pem@ \ - --from-file=@samples/certs/root-cert.pem@ \ - --from-file=@samples/certs/cert-chain.pem@ - {{< /text >}} - -1. 在集群中部署 Istio 控制平面: - - {{< text bash >}} - $ istioctl manifest apply \ - -f install/kubernetes/operator/examples/vm/values-istio-meshexpansion.yaml - {{< /text >}} - - 有关更多的详细信息和自定义选项,请参阅 - [安装说明](/zh/docs/setup/install/istioctl/)。 - -1. 定义 VM 加入的命名空间。本示例使用 `SERVICE_NAMESPACE` - 环境变量存储命名空间。此变量的值必须与稍后在配置文件中使用的命名空间相匹配。 - - {{< text bash >}} - $ export SERVICE_NAMESPACE="default" - {{< /text >}} - -1. 确定并存储 Istio 入口网关的 IP 地址,因为 VMs 通过此 IP 地址访问 [Citadel](/zh/docs/concepts/security/) 和 - [Pilot](/zh/docs/ops/deployment/architecture/#pilot)。 - - {{< text bash >}} - $ export GWIP=$(kubectl get -n istio-system service istio-ingressgateway -o jsonpath='{.status.loadBalancer.ingress[0].ip}') - $ echo $GWIP - 35.232.112.158 - {{< /text >}} - -1. 在 VM 中生成 `cluster.env` 配置并部署。该文件包含 Kubernetes 集群 IP 地址范围,可 - 通过 Envoy 进行拦截和重定向。当您安装 Kubernetes 时,可以指定 CIDR 的范围为 `servicesIpv4Cidr`。 - 在安装后,按照以下示例的命令,使用适当的值替换 `$MY_ZONE` 和 `$MY_PROJECT`, - 以获取 CIDR: - - {{< text bash >}} - $ ISTIO_SERVICE_CIDR=$(gcloud container clusters describe $K8S_CLUSTER --zone $MY_ZONE --project $MY_PROJECT --format "value(servicesIpv4Cidr)") - $ echo -e "ISTIO_CP_AUTH=MUTUAL_TLS\nISTIO_SERVICE_CIDR=$ISTIO_SERVICE_CIDR\n" > cluster.env - {{< /text >}} - -1. 检查生成文件 `cluster.env` 的内容。其内容应该与以下示例类似: - - {{< text bash >}} - $ cat cluster.env - ISTIO_CP_AUTH=MUTUAL_TLS - ISTIO_SERVICE_CIDR=10.55.240.0/20 - {{< /text >}} - -1. 如果 VM 仅在网格中调用服务,您可以跳过这 2 一步骤。否则,使用以下命令为 VM 新增公开端口到 `cluster.env` 文件下。 - 如有必要,您可以稍后更改端口。 - - {{< text bash >}} - $ echo "ISTIO_INBOUND_PORTS=3306,8080" >> cluster.env - {{< /text >}} - -1. 提取服务帐户需要在 VM 上使用的初始密钥。 - - {{< text bash >}} - $ kubectl -n $SERVICE_NAMESPACE get secret istio.default \ - -o jsonpath='{.data.root-cert\.pem}' |base64 --decode > root-cert.pem - $ kubectl -n $SERVICE_NAMESPACE get secret istio.default \ - -o jsonpath='{.data.key\.pem}' |base64 --decode > key.pem - $ kubectl -n $SERVICE_NAMESPACE get secret istio.default \ - -o jsonpath='{.data.cert-chain\.pem}' |base64 --decode > cert-chain.pem - {{< /text >}} - -### 设置 VM{#setting-up-the-VM} - -下一步,将要加入网格的每台机器上运行以下命令: - -1. 将之前创建的 `cluster.env` 和 `*.pem` 文件复制到 VM 中。例如: - - {{< text bash >}} - $ export GCE_NAME="your-gce-instance" - $ gcloud compute scp --project=${MY_PROJECT} --zone=${MY_ZONE} {key.pem,cert-chain.pem,cluster.env,root-cert.pem} ${GCE_NAME}:~ - {{< /text >}} - -1. 使用 Envoy sidecar 安装 Debian 软件包。 - - {{< text bash >}} - $ gcloud compute ssh --project=${MY_PROJECT} --zone=${MY_ZONE} "${GCE_NAME}" - $ curl -L https://storage.googleapis.com/istio-release/releases/{{< istio_full_version >}}/deb/istio-sidecar.deb > istio-sidecar.deb - $ sudo dpkg -i istio-sidecar.deb - {{< /text >}} - -1. 将 Istio 的网关 IP 地址添加到 `/etc/hosts`。重新访问[集群准备](#preparing-the-Kubernetes-cluster-for-VMs)部分以了解如何获取 IP 地址。 -以下示例使用 Istio 网关地址修改 `/etc/hosts` 文件: - - {{< text bash >}} - $ echo "35.232.112.158 istio-citadel istio-pilot istio-pilot.istio-system" | sudo tee -a /etc/hosts - {{< /text >}} - -1. 在 `/etc/certs/` 下安装 `root-cert.pem`,`key.pem` 和 `cert-chain.pem`。 - - {{< text bash >}} - $ sudo mkdir -p /etc/certs - $ sudo cp {root-cert.pem,cert-chain.pem,key.pem} /etc/certs - {{< /text >}} - -1. 在 `/var/lib/istio/envoy/` 下安装 `cluster.env`。 - - {{< text bash >}} - $ sudo cp cluster.env /var/lib/istio/envoy - {{< /text >}} - -1. 将 `/etc/certs/` 和 `/var/lib/istio/envoy/` 中文件的所有权转交给 Istio proxy。 - - {{< text bash >}} - $ sudo chown -R istio-proxy /etc/certs /var/lib/istio/envoy - {{< /text >}} - -1. 验证节点上的 agent 是否正常工作: - - {{< text bash >}} - $ sudo node_agent - .... - CSR is approved successfully. Will renew cert in 1079h59m59.84568493s - {{< /text >}} - -1. 使用 `systemctl` 启动 Istio: - - {{< text bash >}} - $ sudo systemctl start istio-auth-node-agent - $ sudo systemctl start istio - {{< /text >}} - -## 将来自 VM 工作负载的请求发送到 Kubernetes 服务{#send-requests-from-VM-workloads-to-Kubernetes-services} - -设置完后,机器可以访问运行在 Kubernetes 集群上的服务,或者其他的 VM。 - -以下示例展示了使用 `/etc/hosts/` 如何从 VM 中访问 Kubernetes 集群上运行的服务, -这里使用 [Bookinfo 示例](/zh/docs/examples/bookinfo/)中的服务。 - -1. 首先,在集群管理机器上获取服务的虚拟 IP 地址(`clusterIP`): - - {{< text bash >}} - $ kubectl get svc productpage -o jsonpath='{.spec.clusterIP}' - 10.55.246.247 - {{< /text >}} - -1. 然后在新增的 VM 上,将服务名称和地址添加到其 `etc/hosts` 文件下。 - 然后您可以从 VM 连接到集群服务,如以下示例: - - {{< text bash >}} -$ echo "10.55.246.247 productpage.default.svc.cluster.local" | sudo tee -a /etc/hosts -$ curl -v productpage.default.svc.cluster.local:9080 -< HTTP/1.1 200 OK -< content-type: text/html; charset=utf-8 -< content-length: 1836 -< server: envoy -... html content ... - {{< /text >}} - -`server: envoy` 标头指示 sidecar 拦截了流量。 - -## 在添加的 VM 中运行服务{#running-services-on-the-added-VM} - -1. 在 VM 实例上设置 HTTP 服务,以在端口 8080 上提供 HTTP 通信: - - {{< text bash >}} - $ gcloud compute ssh ${GCE_NAME} - $ python -m SimpleHTTPServer 8080 - {{< /text >}} - -1. 定义 VM 实例的 IP 地址。例如,使用以下命令 - 查找 GCE 实例的 IP 地址: - - {{< text bash >}} - $ export GCE_IP=$(gcloud --format="value(networkInterfaces[0].networkIP)" compute instances describe ${GCE_NAME}) - $ echo ${GCE_IP} - {{< /text >}} - -1. 将 VM 服务添加到网格 - - {{< text bash >}} - $ istioctl experimental add-to-mesh external-service vmhttp ${VM_IP} http:8080 -n ${SERVICE_NAMESPACE} - {{< /text >}} - - {{< tip >}} - 按照[下载页面](/zh/docs/setup/getting-started/#download)中的说明,确保已经将 `istioctl` 客户端添加到您的路径中。 - {{< /tip >}} - -1. 在 Kubernetes 集群中部署一个 pod 运行 `sleep` 服务,然后等待其准备就绪: - - {{< text bash >}} - $ kubectl apply -f @samples/sleep/sleep.yaml@ - $ kubectl get pod - NAME READY STATUS RESTARTS AGE - sleep-88ddbcfdd-rm42k 2/2 Running 0 1s - ... - {{< /text >}} - -1. 将 pod 中 `sleep` 服务的请求发送到 VM 的 HTTP 服务: - - {{< text bash >}} - $ kubectl exec -it sleep-88ddbcfdd-rm42k -c sleep -- curl vmhttp.${SERVICE_NAMESPACE}.svc.cluster.local:8080 - {{< /text >}} - - 您应该看到类似于以下输出的内容: - - {{< text html >}} - - Directory listing for / - -

    Directory listing for /

    -
    -
      -
    • .bashrc
    • -
    • .ssh/
    • - ... - - {{< /text >}} - -**恭喜你!** 您已经成功的配置了一个服务,使其运行在集群中的 pod 上,将其流量发送给集群之外在 VM 上运行的服务,并测试了配置是否有效。 - -## 清理{#cleanup} - -运行以下命令,从网格的抽象模型中删除扩展 VM: - -{{< text bash >}} -$ istioctl experimental remove-from-mesh -n ${SERVICE_NAMESPACE} vmhttp -Kubernetes Service "vmhttp.vm" has been deleted for external service "vmhttp" -Service Entry "mesh-expansion-vmhttp" has been deleted for external service "vmhttp" -{{< /text >}} - -## 故障排除{#troubleshooting} - -以下是一些常见的 VM 相关问题的基本故障排除步骤。 - -- 从 VM 向群集发出请求时,请确保不要以 `root` 或 - 者 `istio-proxy` 用户的身份运行请求。默认情况下,Istio 将这两个用户都排除在拦截范围之外。 - -- 验证计算机是否可以达到集群中运行的所有工作负载的 IP。例如: - - {{< text bash >}} - $ kubectl get endpoints productpage -o jsonpath='{.subsets[0].addresses[0].ip}' - 10.52.39.13 - {{< /text >}} - - {{< text bash >}} - $ curl 10.52.39.13:9080 - html output - {{< /text >}} - -- 检查节点 agent 和 sidecar 的状态: - - {{< text bash >}} - $ sudo systemctl status istio-auth-node-agent - $ sudo systemctl status istio - {{< /text >}} - -- 检查进程是否正在运行。在 VM 上,您应该看到以下示例的进程,如果您运行了 - `ps` 过滤 `istio`: - - {{< text bash >}} - $ ps aux | grep istio - root 6941 0.0 0.2 75392 16820 ? Ssl 21:32 0:00 /usr/local/istio/bin/node_agent --logtostderr - root 6955 0.0 0.0 49344 3048 ? Ss 21:32 0:00 su -s /bin/bash -c INSTANCE_IP=10.150.0.5 POD_NAME=demo-vm-1 POD_NAMESPACE=default exec /usr/local/bin/pilot-agent proxy > /var/log/istio/istio.log istio-proxy - istio-p+ 7016 0.0 0.1 215172 12096 ? Ssl 21:32 0:00 /usr/local/bin/pilot-agent proxy - istio-p+ 7094 4.0 0.3 69540 24800 ? Sl 21:32 0:37 /usr/local/bin/envoy -c /etc/istio/proxy/envoy-rev1.json --restart-epoch 1 --drain-time-s 2 --parent-shutdown-time-s 3 --service-cluster istio-proxy --service-node sidecar~10.150.0.5~demo-vm-1.default~default.svc.cluster.local - {{< /text >}} - -- 检查 Envoy 访问和错误日志: - - {{< text bash >}} - $ tail /var/log/istio/istio.log - $ tail /var/log/istio/istio.err.log - {{< /text >}} diff --git a/content/zh/docs/examples/virtual-machines/snips.sh b/content/zh/docs/examples/virtual-machines/snips.sh new file mode 100644 index 0000000000..e444425bf6 --- /dev/null +++ b/content/zh/docs/examples/virtual-machines/snips.sh @@ -0,0 +1,105 @@ +#!/bin/bash +# shellcheck disable=SC2034,SC2153,SC2155,SC2164 + +# Copyright Istio Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#################################################################################################### +# WARNING: THIS IS AN AUTO-GENERATED FILE, DO NOT EDIT. PLEASE MODIFY THE ORIGINAL MARKDOWN FILE: +# docs/examples/virtual-machines/index.md +#################################################################################################### + +snip_running_mysql_on_the_vm_1() { +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 +} + +snip_running_mysql_on_the_vm_2() { +cat <Simple Bookstore App +... +ENDSNIP diff --git a/content/zh/docs/examples/virtual-machines/test.sh b/content/zh/docs/examples/virtual-machines/test.sh new file mode 100644 index 0000000000..85cc10bded --- /dev/null +++ b/content/zh/docs/examples/virtual-machines/test.sh @@ -0,0 +1,109 @@ +#!/usr/bin/env bash +# shellcheck disable=SC2034,SC2155,SC2154 + +# Copyright Istio Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -e +set -u +set -o pipefail +set -x + +export VM_APP="mysqldb" +export VM_NAMESPACE="vm" +export WORK_DIR="$(mktemp -d)" +export SERVICE_ACCOUNT="default" +export CLUSTER_NETWORK="" +export VM_NETWORK="" +export CLUSTER="Kubernetes" + +source "tests/util/samples.sh" +source "content/en/docs/setup/install/virtual-machine/snips.sh" +source "content/en/docs/setup/install/virtual-machine/common.sh" + +function run_in_vm() { + script="${1:?script}" + docker exec --privileged vm bash -c "set -x; source /examples/snips.sh; + ${script} +" +} + +function run_in_vm_interactive() { + script="${1:?script}" + docker exec -t --privileged vm bash -c "set -x ;source /examples/snips.sh; + ${script} +" +} + +# @setup profile=none + +setup_cluster_for_vms +EXTRA_VM_ARGS="-v ${PWD}/content/en/docs/examples/virtual-machines:/examples" setup_vm +start_vm +echo "VM STARTED" +run_in_vm "while ! curl localhost:15021/healthz/ready -s; do sleep 1; done" +run_in_vm "while ! curl archive.ubuntu.com -s; do sleep 1; done" + +run_in_vm " + snip_running_mysql_on_the_vm_1 + mkdir -p /var/lib/mysql /var/run/mysqld + chown -R mysql:mysql /var/lib/mysql /var/run/mysqld; + chmod 777 /var/run/mysqld +" + +# We do not have systemd, need to start mysql manually +docker exec --privileged -d vm mysqld --skip-grant-tables +# Wait for mysql to be ready +run_in_vm "while ! sudo mysql 2> /dev/null; do echo retrying mysql...; sleep 5; done" + +run_in_vm snip_running_mysql_on_the_vm_3 + +check_table4() { run_in_vm_interactive snip_running_mysql_on_the_vm_4; } +_verify_contains check_table4 "${snip_running_mysql_on_the_vm_4_out}" + +check_table5() { run_in_vm_interactive snip_running_mysql_on_the_vm_5; } +_verify_contains check_table5 "${snip_running_mysql_on_the_vm_5_out}" + +snip_expose_the_mysql_service_to_the_mesh_1 + +# Setup test applications. Doc assumes these are present +kubectl create namespace bookinfo || true +kubectl label namespace bookinfo istio-injection=enabled --overwrite +kubectl apply -n bookinfo -f samples/bookinfo/platform/kube/bookinfo.yaml +kubectl apply -n bookinfo -f samples/bookinfo/networking/bookinfo-gateway.yaml +kubectl apply -n bookinfo -f samples/bookinfo/networking/destination-rule-all.yaml +startup_sleep_sample +for deploy in "productpage-v1" "details-v1" "ratings-v1" "reviews-v1" "reviews-v2" "reviews-v3"; do + _wait_for_deployment bookinfo "$deploy" +done + +# Switch bookinfo to point to mysql +snip_using_the_mysql_service_1 +snip_using_the_mysql_service_2 + +# Send traffic, ensure we get ratings +get_bookinfo_productpage() { + sample_http_request "/productpage" +} +_verify_contains get_bookinfo_productpage "glyphicon glyphicon-star" + +run_curl() { run_in_vm_interactive snip_reaching_kubernetes_services_from_the_virtual_machine_1; } +_verify_elided run_curl "${snip_reaching_kubernetes_services_from_the_virtual_machine_1_out}" + +# @cleanup +docker stop vm +kubectl delete -f samples/multicluster/expose-istiod.yaml --ignore-not-found=true +istioctl manifest generate | kubectl delete -f - --ignore-not-found=true +cleanup_sleep_sample +kubectl delete namespace istio-system vm bookinfo --ignore-not-found=true diff --git a/content/zh/docs/examples/virtual-machines/bookinfo/vm-bookinfo.svg b/content/zh/docs/examples/virtual-machines/vm-bookinfo.svg similarity index 100% rename from content/zh/docs/examples/virtual-machines/bookinfo/vm-bookinfo.svg rename to content/zh/docs/examples/virtual-machines/vm-bookinfo.svg