OpenShift Service Mesh 3.0 is a Technology Preview feature only
Technology Preview features are not supported with Red Hat production service level agreements (SLAs) and might not be functionally complete. Red Hat does not recommend using them in production. These features provide early access to upcoming product features, enabling customers to test functionality and provide feedback during the development process. This documentation is a work in progress and might not be complete or fully tested.5.3. 安装多主多网络网格
在两个 OpenShift Container Platform 集群上的多主多网络拓扑中安装 Istio。
在此过程中,CLUSTER1
是东集群,CLUSTER2
是 West 集群。
您可以为跨越多个集群的网格调整这些说明。
先决条件
- 您已在组成网格的所有集群中安装 OpenShift Service Mesh 3 Operator。
- 您已完成"为多集群网格创建证书"。
- 您已完成"将证书应用到多集群拓扑"。
- 您已创建了 Istio Container Network Interface (CNI)资源。
-
您已在笔记本电脑上安装了
istioctl
,您可以使用它们运行这些说明。
流程
运行以下命令,创建一个
ISTIO_VERSION
环境变量来定义要安装的 Istio 版本:$ export ISTIO_VERSION=1.24.1
在东集群中安装 Istio:
运行以下命令,在东集群中创建
Istio
资源:$ cat <<EOF | oc --context "${CTX_CLUSTER1}" apply -f - apiVersion: sailoperator.io/v1alpha1 kind: Istio metadata: name: default spec: version: v${ISTIO_VERSION} namespace: istio-system values: global: meshID: mesh1 multiCluster: clusterName: cluster1 network: network1 EOF
运行以下命令,等待 control plane 返回
Ready
状态条件:$ oc --context "${CTX_CLUSTER1}" wait --for condition=Ready istio/default --timeout=3m
运行以下命令,在东集群中创建一个 East-West 网关:
$ oc --context "${CTX_CLUSTER1}" apply -f https://raw.githubusercontent.com/istio-ecosystem/sail-operator/main/docs/multicluster/east-west-gateway-net1.yaml
运行以下命令,通过网关公开服务:
$ oc --context "${CTX_CLUSTER1}" apply -n istio-system -f https://raw.githubusercontent.com/istio-ecosystem/sail-operator/main/docs/multicluster/expose-services.yaml
在 West 集群上安装 Istio:
运行以下命令,在 West 集群中创建
Istio
资源:$ cat <<EOF | oc --context "${CTX_CLUSTER2}" apply -f - apiVersion: sailoperator.io/v1alpha1 kind: Istio metadata: name: default spec: version: v${ISTIO_VERSION} namespace: istio-system values: global: meshID: mesh1 multiCluster: clusterName: cluster2 network: network2 EOF
运行以下命令,等待 control plane 返回
Ready
状态条件:$ oc --context "${CTX_CLUSTER2}" wait --for condition=Ready istio/default --timeout=3m
运行以下命令,在 West 集群上创建一个 East-West 网关:
$ oc --context "${CTX_CLUSTER2}" apply -f https://raw.githubusercontent.com/istio-ecosystem/sail-operator/main/docs/multicluster/east-west-gateway-net2.yaml
运行以下命令,通过网关公开服务:
$ oc --context "${CTX_CLUSTER2}" apply -n istio-system -f https://raw.githubusercontent.com/istio-ecosystem/sail-operator/main/docs/multicluster/expose-services.yaml
运行以下命令,在东集群中安装远程 secret,以便访问 West 集群中的 API 服务器:
$ istioctl create-remote-secret \ --context="${CTX_CLUSTER2}" \ --name=cluster2 | \ oc --context="${CTX_CLUSTER1}" apply -f -
运行以下命令,在 West 集群上安装一个远程 secret,它提供在 East 集群中访问 API 服务器的访问权限:
$ istioctl create-remote-secret \ --context="${CTX_CLUSTER1}" \ --name=cluster1 | \ oc --context="${CTX_CLUSTER2}" apply -f -
5.3.1. 验证多集群拓扑
部署示例应用程序,并在两个 OpenShift Container Platform 集群上的多集群拓扑上验证流量。
在此过程中,CLUSTER1
是东集群,CLUSTER2
是 West 集群。
先决条件
- 您已在组成网格的所有集群中安装 OpenShift Service Mesh Operator。
- 您已完成"为多集群网格创建证书"。
- 您已完成"将证书应用到多集群拓扑"。
- 您已创建了 Istio Container Network Interface (CNI)资源。
-
您已在笔记本电脑上安装了
istioctl
,您将使用它们运行这些说明。 - 已安装多集群拓扑。
流程
在 East 集群上部署示例应用程序:
运行以下命令,在 East 集群中创建示例应用程序命名空间:
$ oc --context "${CTX_CLUSTER1}" get project sample || oc --context="${CTX_CLUSTER1}" new-project sample
运行以下命令标记应用程序命名空间以支持 sidecar 注入:
$ oc --context="${CTX_CLUSTER1}" label namespace sample istio-injection=enabled
部署
helloworld
应用程序:运行以下命令来创建
helloworld
服务:$ oc --context="${CTX_CLUSTER1}" apply \ -f https://raw.githubusercontent.com/istio/istio/${ISTIO_VERSION}/samples/helloworld/helloworld.yaml \ -l service=helloworld -n sample
运行以下命令来创建
helloworld-v1
部署:$ oc --context="${CTX_CLUSTER1}" apply \ -f https://raw.githubusercontent.com/istio/istio/${ISTIO_VERSION}/samples/helloworld/helloworld.yaml \ -l version=v1 -n sample
运行以下命令来部署
sleep
应用程序:$ oc --context="${CTX_CLUSTER1}" apply \ -f https://raw.githubusercontent.com/istio/istio/${ISTIO_VERSION}/samples/sleep/sleep.yaml -n sample
运行以下命令,等待 East 集群上的
helloworld
应用程序返回Ready
状态条件:$ oc --context="${CTX_CLUSTER1}" wait --for condition=available -n sample deployment/helloworld-v1
运行以下命令,等待 East 集群中的
sleep
应用程序返回Ready
状态条件:$ oc --context="${CTX_CLUSTER1}" wait --for condition=available -n sample deployment/sleep
在 West 集群上部署示例应用程序:
运行以下命令,在 West 集群上创建一个应用程序命名空间示例:
$ oc --context "${CTX_CLUSTER2}" get project sample || oc --context="${CTX_CLUSTER2}" new-project sample
运行以下命令标记应用程序命名空间以支持 sidecar 注入:
$ oc --context="${CTX_CLUSTER2}" label namespace sample istio-injection=enabled
部署
helloworld
应用程序:运行以下命令来创建
helloworld
服务:$ oc --context="${CTX_CLUSTER2}" apply \ -f https://raw.githubusercontent.com/istio/istio/${ISTIO_VERSION}/samples/helloworld/helloworld.yaml \ -l service=helloworld -n sample
运行以下命令来创建
helloworld-v2
部署:$ oc --context="${CTX_CLUSTER2}" apply \ -f https://raw.githubusercontent.com/istio/istio/${ISTIO_VERSION}/samples/helloworld/helloworld.yaml \ -l version=v2 -n sample
运行以下命令来部署
sleep
应用程序:$ oc --context="${CTX_CLUSTER2}" apply \ -f https://raw.githubusercontent.com/istio/istio/${ISTIO_VERSION}/samples/sleep/sleep.yaml -n sample
运行以下命令,等待 West 集群中的
helloworld
应用程序返回Ready
状态条件:$ oc --context="${CTX_CLUSTER2}" wait --for condition=available -n sample deployment/helloworld-v2
运行以下命令,等待 West 集群中的
sleep
应用程序返回Ready
状态条件:$ oc --context="${CTX_CLUSTER2}" wait --for condition=available -n sample deployment/sleep
验证集群间的流量流
对于东集群,运行以下命令来向
helloworld
服务发送 10 个请求:$ for i in {0..9}; do \ oc --context="${CTX_CLUSTER1}" exec -n sample deploy/sleep -c sleep -- curl -sS helloworld.sample:5000/hello; \ done
验证您是否看到来自两个集群的响应。这意味着服务的版本 1 和版本 2 可以在响应中看到。
对于 West 集群,向
helloworld
服务发送 10 个请求:$ for i in {0..9}; do \ oc --context="${CTX_CLUSTER2}" exec -n sample deploy/sleep -c sleep -- curl -sS helloworld.sample:5000/hello; \ done
验证您是否看到来自两个集群的响应。这意味着服务的版本 1 和版本 2 可以在响应中看到。
5.3.2. 从开发环境中删除多集群拓扑
在开发环境中使用多集群功能后,从所有集群中删除多集群拓扑。
在此过程中,CLUSTER1
是东集群,CLUSTER2
是 West 集群。
先决条件
- 已安装多集群拓扑。
流程
运行以下命令,从开发环境的 East 集群中删除 Istio 和示例应用程序:
$ oc --context="${CTX_CLUSTER1}" delete istio/default ns/istio-system ns/sample ns/istio-cni
运行以下命令,从开发环境的 West 集群中删除 Istio 和示例应用程序:
$ oc --context="${CTX_CLUSTER2}" delete istio/default ns/istio-system ns/sample ns/istio-cni