跨网络多主架构的安装

按照本指南,在 cluster1cluster2 两个集群上,安装 Istio 控制平面, 且将两者均设置为主集群(primary cluster)。 集群 cluster1network1 网络上,而集群 cluster2network2 网络上。 这意味着这些跨集群边界的 Pod 之间,网络不能直接连通。

继续安装之前,请确保完成了准备工作中的步骤。

如果您使用 kind 测试多集群,您可以使用 MetalLBLoadBalancer 服务使用 EXTERNAL-IP

在此配置中,cluster1cluster2 均监测两个集群 API Server 的服务端点。

跨集群边界的服务负载,通过专用的东西向网关,以间接的方式通讯。每个集群中的网关在其他集群必须可以访问。

Multiple primary clusters on separate networks

Multiple primary clusters on separate networks

cluster1 设置缺省网络

创建命名空间 istio-system 之后,我们需要设置集群的网络:

  1. $ kubectl --context="${CTX_CLUSTER1}" get namespace istio-system && \
  2. kubectl --context="${CTX_CLUSTER1}" label namespace istio-system topology.istio.io/network=network1

cluster1 设为主集群

cluster1 创建 Istio 配置文件:

  1. $ cat <<EOF > cluster1.yaml
  2. apiVersion: install.istio.io/v1alpha1
  3. kind: IstioOperator
  4. spec:
  5. values:
  6. global:
  7. meshID: mesh1
  8. multiCluster:
  9. clusterName: cluster1
  10. network: network1
  11. EOF

将配置文件应用到 cluster1

  1. $ istioctl install --context="${CTX_CLUSTER1}" -f cluster1.yaml

cluster1 安装东西向网关

cluster1 安装专用的 东西向网关。 默认情况下,此网关将被公开到互联网上。 生产系统可能需要添加额外的访问限制(即:通过防火墙规则)来防止外部攻击。 咨询你的云服务商,了解可用的选择。

Zip

  1. $ @samples/multicluster/gen-eastwest-gateway.sh@ \
  2. --mesh mesh1 --cluster cluster1 --network network1 | \
  3. istioctl --context="${CTX_CLUSTER1}" install -y -f -

如果随着版本修正已经安装控制面板,在 gen-eastwest-gateway.sh 命令中添加 --revision rev 标志。

等待东西向网关被分配外部 IP 地址:

  1. $ kubectl --context="${CTX_CLUSTER1}" get svc istio-eastwestgateway -n istio-system
  2. NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
  3. istio-eastwestgateway LoadBalancer 10.80.6.124 34.75.71.237 ... 51s

开放 cluster1 中的服务

因为集群位于不同的网络中,所以我们需要在两个集群东西向网关上开放所有服务(*.local)。 虽然此网关在互联网上是公开的,但它背后的服务只能被拥有可信 mTLS 证书、工作负载 ID 的服务访问,就像它们处于同一网络一样。

Zip

  1. $ kubectl --context="${CTX_CLUSTER1}" apply -n istio-system -f \
  2. @samples/multicluster/expose-services.yaml@

cluster2 设置缺省网络

命名空间 istio-system 创建完成后,我们需要设置集群的网络:

  1. $ kubectl --context="${CTX_CLUSTER2}" get namespace istio-system && \
  2. kubectl --context="${CTX_CLUSTER2}" label namespace istio-system topology.istio.io/network=network2

将 cluster2 设为主集群

cluster2 创建 Istio 配置文件:

  1. $ cat <<EOF > cluster2.yaml
  2. apiVersion: install.istio.io/v1alpha1
  3. kind: IstioOperator
  4. spec:
  5. values:
  6. global:
  7. meshID: mesh1
  8. multiCluster:
  9. clusterName: cluster2
  10. network: network2
  11. EOF

将配置文件应用到 cluster2

  1. $ istioctl install --context="${CTX_CLUSTER2}" -f cluster2.yaml

cluster2 安装东西向网关

仿照上面 cluster1 的操作,在 cluster2 安装专用于东西向流量的网关。

Zip

  1. $ @samples/multicluster/gen-eastwest-gateway.sh@ \
  2. --mesh mesh1 --cluster cluster2 --network network2 | \
  3. istioctl --context="${CTX_CLUSTER2}" install -y -f -

等待东西向网关被分配外部 IP 地址:

  1. $ kubectl --context="${CTX_CLUSTER2}" get svc istio-eastwestgateway -n istio-system
  2. NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
  3. istio-eastwestgateway LoadBalancer 10.0.12.121 34.122.91.98 ... 51s

开放 cluster2 中的服务

仿照上面 cluster1 的操作,通过东西向网关开放服务。

Zip

  1. $ kubectl --context="${CTX_CLUSTER2}" apply -n istio-system -f \
  2. @samples/multicluster/expose-services.yaml@

启用端点发现

cluster2 中安装一个提供 cluster1 API Server 访问权限的远程 Secret。

  1. $ istioctl x create-remote-secret \
  2. --context="${CTX_CLUSTER1}" \
  3. --name=cluster1 | \
  4. kubectl apply -f - --context="${CTX_CLUSTER2}"

cluster1 中安装一个提供 cluster2 API Server 访问权限的远程 Secret。

  1. $ istioctl x create-remote-secret \
  2. --context="${CTX_CLUSTER2}" \
  3. --name=cluster2 | \
  4. kubectl apply -f - --context="${CTX_CLUSTER1}"

恭喜! 你在跨网络多主架构的集群上,成功的安装了 Istio 网格。

后续步骤

现在,你可以验证此次安装.