# 主远程 - 单网络平面

## 在不同网络上安装Primary-Remote

请按照本指南将Istio控制平面安装在cluster1(主集群)并配置(cluster2远程集群)在中使用控制平面。集群cluster1在network1网络上,而cluster2在netowrk2网络上。这意味着跨集群边界的Pod之间没有直接连接.

在开始之前,一定要完成下的步骤 ,然后再开始。

在此配置中,集群cluster1将在两个集群中观察端点的API服务器。这样,控制平面将能够为两个集群中的工作负载提供服务发现。

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

服务cluster2将cluster1通过同一东西方网关到达控制平面。

![单独网络上的主集群和远程集群](https://istio.io/latest/docs/setup/install/multicluster/primary-remote_multi-network/arch.svg)

> 现在,远程配置文件将在远程集群中安装一台istiod服务器,该服务器将用于该集群中的工作负载的CA和Webhook注入。但是,服务发现将定向到主集群中的控制平面。 将来的版本将完全不需要在远程集群中添加一个摘要。敬请关注！

## 为cluster1设置默认网络

如果已经创建了istio-system命名空间,则需要在此处设置集群的网络:

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

## 配置cluster1为主集群

为创建Istio配置cluster1:

```
cat <<EOF > cluster1.yaml
apiVersion: install.istio.io/v1alpha1
kind: IstioOperator
spec:
  values:
    global:
      meshID: mesh1
      multiCluster:
        clusterName: cluster1
      network: network1
```

将配置应用于cluster1:

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

## 在cluster1中安装东西向网关

安装cluster1专用于东西方流量的网关。默认情况下,此网关将在Internet上公开。生产系统可能需要其他访问限制(例如,通过防火墙规则),以防止外部攻击。与您的云供应商联系以查看可用的选项。

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

等待向东西方网关分配一个外部IP地址:

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

## 暴露cluster1中的控制平面

在上进行安装之前cluster2,我们需要首先将控制平面暴露在其中, cluster1以便其中的服务cluster2将能够访问服务发现:

```
kubectl apply --context="${CTX_CLUSTER1}" -f \
    samples/multicluster/expose-istiod.yaml
```

## 公开cluster1的服务

由于集群位于单独的网络上,因此我们还需要在两个集群中的东西方网关上公开所有用户服务(\* .local)。尽管此网关在Internet上是公共的,但只有具有受信任的mTLS证书和工作负载ID的服务才能访问其网关后面的服务,就像它们在同一网络上一样。

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

## 为cluster2设置默认网络

如果已经创建了istio-system命名空间,则需要在此处设置集群的网络:

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

## 启用cluster2 API Server的访问权限

在配置远程集群之前,我们首先必须在中提供控制平面cluster1访问cluster2 API Server的权限。这将执行以下操作:

使控制平面能够验证来自中运行的工作负载的连接请求cluster2。没有API Server访问权限,控制平面将拒绝请求。

启用发现在中运行的服务端点的功能cluster2。

为了提供对API服务器的访问权限cluster2,我们生成了一个远程机密并将其应用于cluster1:

```
istioctl x create-remote-secret \
    --context="${CTX_CLUSTER2}" \
    --name=cluster2 | \
    kubectl apply -f - --context="${CTX_CLUSTER1}"
```

## 配置cluster2为远程集群

保存cluster1的东西方网关的地址。

```
export DISCOVERY_ADDRESS=$(kubectl \
    --context="${CTX_CLUSTER1}" \
    -n istio-system get svc istio-eastwestgateway \
    -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
```

现在在上创建一个远程配置cluster2。

```
cat <<EOF > cluster2.yaml
apiVersion: install.istio.io/v1alpha1
kind: IstioOperator
spec:
  profile: remote
  values:
    global:
      meshID: mesh1
      multiCluster:
        clusterName: cluster2
      network: network2
      remotePilotAddress: ${DISCOVERY_ADDRESS}
EOF
```

将配置应用于cluster2:

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

## 在cluster2中安装东西方网关

与cluster1上面的操作一样,在cluster2其中安装专用于东西向流量的网关并公开用户服务。

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

等待向东西方网关分配一个外部IP地址:

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

## 暴露cluster2中的服务

与cluster1上面的操作一样,通过东西网关公开服务。

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

恭喜你！您已成功跨不同网络上的主集群和远程集群安装了一个Istio网格！


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://rocdu.gitbook.io/deep-understanding-of-istio/4/1/2-4.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
