安装 primary-remote 多网络网格

在两个集群上以 primary-remote 多网络拓扑安装 Istio。

NOTE

在此操作步骤中,CLUSTER1East 集群,CLUSTER2West 集群。East 集群是 primary 集群,West 集群是 remote 集群。

您可以调整这些说明,以构建跨越两个以上集群的网格。

拓扑

跨集群边界的服务工作负载通过专用于东西向流量的网关间接通信。 每个集群中的网关都必须可从另一个集群访问。

cluster2 中的服务将通过同一个东西向网关访问 cluster1 中的控制平面。

Primary-Remote 多网络拓扑

先决条件

  • 您已在组成网格的所有集群中安装 Alauda Container Platform Networking for Multus plugin,并且 kube-ovn 必须为 v4.1.5 或更高版本。
  • 您可以访问两个支持外部负载均衡器的集群。
    WARNING

    在 primary-remote 模式下,如果外部负载均衡器地址是 IP 且为 IPv6,则在 Alauda Service Mesh v2.1.2 之前的版本中不支持 primary-remote 部署

  • 您已在组成网格的所有集群中安装 Alauda Service Mesh v2 Operator。
  • 您已完成为多集群网格创建证书
  • 您已完成将证书应用于多集群拓扑
  • 您已在本地安装 istioctl,以便用于执行这些操作步骤。

操作步骤

创建定义要安装的 Istio 版本的 ISTIO_VERSION 环境变量

export ISTIO_VERSION=1.30.4

East 集群上安装 IstioCNI

运行以下命令,在 East 集群上安装 IstioCNI 资源:

kubectl --context "${CTX_CLUSTER1}" create namespace istio-cni
cat <<EOF | kubectl --context "${CTX_CLUSTER1}" apply -f -
apiVersion: sailoperator.io/v1
kind: IstioCNI
metadata:
  name: default
spec:
  version: v${ISTIO_VERSION}
  namespace: istio-cni
  values:
    cni:
      cniConfDir: /etc/cni/multus/net.d
      excludeNamespaces:
        - istio-cni
        - kube-system
EOF

East 集群上安装 Istio

  1. 运行以下命令,在 East 集群上创建 Istio 资源:

    将以下 Istio 资源保存到 istio-external.yaml

    istio-external.yaml
    apiVersion: sailoperator.io/v1
    kind: Istio
    metadata:
      name: default
    spec:
      version: v${ISTIO_VERSION}
      namespace: istio-system
      values:
        global:
          meshID: mesh1
          multiCluster:
            clusterName: cluster1
          network: network1
          externalIstiod: true
          proxy:
            seccompProfile:
              type: RuntimeDefault
    1. 这会使安装在 East 集群上的控制平面能够充当其他 remote 集群的外部控制平面。
    2. spec.values.global.proxy.seccompProfile.type 设置为 RuntimeDefault,可使注入的 sidecar 满足 Restricted Pod Security Admission 配置文件的要求。由于此控制平面还会注入 remote West 集群的工作负载,因此该设置涵盖两个集群。有关更多信息,请参阅 Pod Security Admission

    使用 kubectl 应用 Istio 资源:

    envsubst < istio-external.yaml | kubectl --context "${CTX_CLUSTER1}" apply -f -
  2. 运行以下命令,等待控制平面返回“Ready”状态条件:

    kubectl --context "${CTX_CLUSTER1}" wait --for condition=Ready istio/default --timeout=3m
  3. 运行以下命令,在 East 集群上创建东西向网关:

    WARNING

    对于运行早于 4.11 的 Linux kernel 版本的节点(例如 CentOS 7),在安装网关前需要进行额外配置

    kubectl --context "${CTX_CLUSTER1}" apply -f https://raw.githubusercontent.com/alauda-mesh/sail-operator/release-2.2/docs/deployment-models/resources/east-west-gateway-net1.yaml
    可选:将东西向网关部署到 Infra Nodes(点击展开)

    运行以下命令为网关 deployment 打补丁:

    kubectl --context "${CTX_CLUSTER1}" patch deployment istio-eastwestgateway -n istio-system \
      --type='merge' \
      --patch '{
        "spec": {
          "template": {
            "spec": {
              "nodeSelector": {
                "node-role.kubernetes.io/infra": ""
              },
              "tolerations": [
                {
                  "effect": "NoSchedule",
                  "key": "node-role.kubernetes.io/infra",
                  "value": "reserved",
                  "operator": "Equal"
                }
              ]
            }
          }
        }
      }'
  4. 运行以下命令,通过网关暴露控制平面,以便 West 集群中的服务访问该控制平面:

    kubectl --context "${CTX_CLUSTER1}" apply -n istio-system -f https://raw.githubusercontent.com/alauda-mesh/sail-operator/release-2.2/docs/deployment-models/resources/expose-istiod.yaml
  5. 运行以下命令,通过网关暴露应用服务:

    kubectl --context "${CTX_CLUSTER1}" apply -n istio-system -f https://raw.githubusercontent.com/alauda-mesh/sail-operator/release-2.2/docs/deployment-models/resources/expose-services.yaml

West 集群上安装 IstioCNI

运行以下命令,在 West 集群上安装 IstioCNI 资源:

kubectl --context "${CTX_CLUSTER2}" create namespace istio-cni
cat <<EOF | kubectl --context "${CTX_CLUSTER2}" apply -f -
apiVersion: sailoperator.io/v1
kind: IstioCNI
metadata:
  name: default
spec:
  version: v${ISTIO_VERSION}
  namespace: istio-cni
  values:
    cni:
      cniConfDir: /etc/cni/multus/net.d
      excludeNamespaces:
        - istio-cni
        - kube-system
EOF

West 集群上安装 Istio

  1. 运行以下命令,保存运行于 East 集群中的东西向网关的 IP 地址:

    export DISCOVERY_ADDRESS=$(kubectl --context="${CTX_CLUSTER1}" \
       -n istio-system get svc istio-eastwestgateway \
       -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
    echo "DISCOVERY_ADDRESS=${DISCOVERY_ADDRESS}"
  2. 运行以下命令,在 West 集群上创建 Istio 资源:

    cat <<EOF | kubectl --context "${CTX_CLUSTER2}" apply -f -
    apiVersion: sailoperator.io/v1
    kind: Istio
    metadata:
      name: default
    spec:
      version: v${ISTIO_VERSION}
      namespace: istio-system
      profile: remote
      values:
        istiodRemote:
          injectionPath: /inject/cluster/cluster2/net/network2
        global:
          remotePilotAddress: ${DISCOVERY_ADDRESS}
    EOF
  3. 运行以下命令,为 West 集群中的 istio-system namespace 添加注释,使其由 East 集群中的控制平面管理:

    kubectl --context="${CTX_CLUSTER2}" annotate namespace istio-system topology.istio.io/controlPlaneClusters=cluster1
  4. 运行以下命令,在 East 集群上安装 remote secret,为访问 West 集群中的 API server 提供权限:

    istioctl create-remote-secret \
      --context="${CTX_CLUSTER2}" \
      --name=cluster2 | \
      kubectl --context="${CTX_CLUSTER1}" apply -f -
  5. 运行以下命令,等待 Istio 资源返回“Ready”状态条件:

    kubectl --context "${CTX_CLUSTER2}" wait --for condition=Ready istio/default --timeout=3m
  6. 运行以下命令,在 West 集群上创建东西向网关:

    WARNING

    对于运行早于 4.11 的 Linux kernel 版本的节点(例如 CentOS 7),在安装网关前需要进行额外配置

    kubectl --context "${CTX_CLUSTER2}" apply -f https://raw.githubusercontent.com/alauda-mesh/sail-operator/release-2.2/docs/deployment-models/resources/east-west-gateway-net2.yaml
    可选:将东西向网关部署到 Infra Nodes(点击展开)

    运行以下命令为网关 deployment 打补丁:

    kubectl --context "${CTX_CLUSTER2}" patch deployment istio-eastwestgateway -n istio-system \
      --type='merge' \
      --patch '{
        "spec": {
          "template": {
            "spec": {
              "nodeSelector": {
                "node-role.kubernetes.io/infra": ""
              },
              "tolerations": [
                {
                  "effect": "NoSchedule",
                  "key": "node-role.kubernetes.io/infra",
                  "value": "reserved",
                  "operator": "Equal"
                }
              ]
            }
          }
        }
      }'
    NOTE

    由于 West 集群使用 remote profile 安装,在 East 集群上暴露应用服务会使其同时暴露在两个集群的东西向网关上。

验证 primary-remote 拓扑

要确认 primary-remote 拓扑运行正常,您将在两个独立的 Alauda Container Platform 集群上部署示例应用。目标是建立一个基准环境,以便生成和观察跨集群流量。

操作步骤

首先将所需的示例应用部署到 East 集群。

此集群将承载 helloworld 服务的 v1 版本。

  1. East 集群上为应用创建专用 namespace。

    kubectl --context="${CTX_CLUSTER1}" create namespace sample
    kubectl --context="${CTX_CLUSTER1}" label namespace sample pod-security.kubernetes.io/enforce=restricted --overwrite
  2. 应用所需的 label,为 sample namespace 启用自动 Istio sidecar 注入。

    kubectl --context="${CTX_CLUSTER1}" label namespace sample istio-injection=enabled
  3. 部署 helloworld 应用组件。

    a. 首先,建立 helloworld 服务端点。

    kubectl --context="${CTX_CLUSTER1}" apply \
      -l service=helloworld -n sample \
      -f https://raw.githubusercontent.com/alauda-mesh/istio/refs/heads/istio-1.30/samples/helloworld/helloworld.yaml

    b. 然后,部署 helloworld 应用的 v1 实例。

    kubectl --context="${CTX_CLUSTER1}" apply \
      -l version=v1 -n sample \
      -f https://raw.githubusercontent.com/alauda-mesh/istio/refs/heads/istio-1.30/samples/helloworld/helloworld.yaml
  4. 部署 sleep 应用,该应用将充当发送测试请求的客户端。

    kubectl --context="${CTX_CLUSTER1}" apply \
      -n sample \
      -f https://raw.githubusercontent.com/alauda-mesh/istio/refs/heads/istio-1.30/samples/sleep/sleep.yaml
  5. 暂停操作,直到 helloworld-v1 deployment 完全可用并就绪。

    kubectl --context="${CTX_CLUSTER1}" wait --for condition=available -n sample deployment/helloworld-v1
  6. 同样,等待 sleep deployment 报告 Ready 状态。

    kubectl --context="${CTX_CLUSTER1}" wait --for condition=available -n sample deployment/sleep

West 集群上复制此设置。

此集群将承载 helloworld 服务的 v2 版本。

  1. West 集群上创建 sample namespace。

    kubectl --context="${CTX_CLUSTER2}" create namespace sample
    kubectl --context="${CTX_CLUSTER2}" label namespace sample pod-security.kubernetes.io/enforce=restricted --overwrite
  2. 同样为此 namespace 启用 Istio sidecar 注入。

    kubectl --context="${CTX_CLUSTER2}" label namespace sample istio-injection=enabled
  3. 部署 helloworld 应用组件。

    a. 在 West 集群上创建通用的 helloworld 服务端点。

    kubectl --context="${CTX_CLUSTER2}" apply \
      -l service=helloworld -n sample \
      -f https://raw.githubusercontent.com/alauda-mesh/istio/refs/heads/istio-1.30/samples/helloworld/helloworld.yaml

    b. 部署 helloworld 应用的 v2 实例。

    kubectl --context="${CTX_CLUSTER2}" apply \
      -l version=v2 -n sample \
      -f https://raw.githubusercontent.com/alauda-mesh/istio/refs/heads/istio-1.30/samples/helloworld/helloworld.yaml
  4. West 集群上部署客户端 sleep 应用。

    kubectl --context="${CTX_CLUSTER2}" apply \
      -n sample \
      -f https://raw.githubusercontent.com/alauda-mesh/istio/refs/heads/istio-1.30/samples/sleep/sleep.yaml
  5. 等待 helloworld-v2 deployment 完全可用。

    kubectl --context="${CTX_CLUSTER2}" wait --for condition=available -n sample deployment/helloworld-v2 --timeout=3m
  6. 最后,确保 West 集群上的 sleep deployment 已就绪。

    kubectl --context="${CTX_CLUSTER2}" wait --for condition=available -n sample deployment/sleep --timeout=3m

验证集群间的流量流动

两个集群上的应用都已部署并运行后,下一步是发送请求,并确认流量在整个服务网格中正确进行负载均衡。

  1. East 集群中的某个 pod 内,向 helloworld 服务发送一系列共 10 个请求。

    for i in {0..9}; do \
      kubectl --context="${CTX_CLUSTER1}" exec -n sample deploy/sleep -c sleep -- curl -sS helloworld.sample:5000/hello; \
    done

    预期结果是同时收到来自 helloworld-v1East)和 helloworld-v2West)的响应,这证明服务网格会跨集群边界路由请求。

    示例输出
    Hello version: v1, instance: helloworld-v1-644474db4b-7cwhz
    Hello version: v2, instance: helloworld-v2-645cb7fc46-lnbb7
    Hello version: v1, instance: helloworld-v1-644474db4b-7cwhz
    Hello version: v1, instance: helloworld-v1-644474db4b-7cwhz
    Hello version: v1, instance: helloworld-v1-644474db4b-7cwhz
    Hello version: v2, instance: helloworld-v2-645cb7fc46-lnbb7
    Hello version: v2, instance: helloworld-v2-645cb7fc46-lnbb7
    Hello version: v1, instance: helloworld-v1-644474db4b-7cwhz
    Hello version: v2, instance: helloworld-v2-645cb7fc46-lnbb7
    Hello version: v1, instance: helloworld-v1-644474db4b-7cwhz
  2. West 集群中执行相同的测试。

    for i in {0..9}; do \
      kubectl --context="${CTX_CLUSTER2}" exec -n sample deploy/sleep -c sleep -- curl -sS helloworld.sample:5000/hello; \
    done

    同样,您应观察到来自该服务 v1v2 的响应,从而确认无论请求从何处发起,primary-remote 负载均衡都能正常工作。

从开发环境中移除 primary-remote 拓扑

完成验证和试验后,应拆除 primary-remote 配置,以清理开发环境并释放资源。

操作步骤

  1. 执行一条命令,从 East 集群中移除所有 Istio 组件和示例应用。

    kubectl --context="${CTX_CLUSTER1}" delete istio/default istiocni/default ns/sample ns/istio-system ns/istio-cni
  2. 运行相应命令,在 West 集群上执行相同的清理操作。

    kubectl --context="${CTX_CLUSTER2}" delete istio/default istiocni/default ns/sample ns/istio-system ns/istio-cni