|
| 1 | +--- |
| 2 | +title: 验证 Ambient 安装 |
| 3 | +description: 验证 Istio Ambient 网格是否已在多个集群上正确安装。 |
| 4 | +weight: 50 |
| 5 | +keywords: [kubernetes,multicluster,ambient] |
| 6 | +test: yes |
| 7 | +owner: istio/wg-environments-maintainers |
| 8 | +prev: /docs/ambient/install/multicluster/multi-primary_multi-network |
| 9 | +--- |
| 10 | +按照本指南验证您的 Ambient 多集群 Istio 安装是否正常工作。 |
| 11 | + |
| 12 | +在继续之前,请务必完成[开始之前](/zh/docs/ambient/install/multicluster/before-you-begin)下的步骤, |
| 13 | +且选择并遵循其中一个[多集群安装指南](/zh/docs/ambient/install/multicluster)。 |
| 14 | + |
| 15 | +在本指南中,我们将验证多集群功能是否正常,并将 `HelloWorld` 应用程序 `v1` |
| 16 | +部署到 `cluster1`,将 `v2` 部署到 `cluster2`。当 `HelloWorld` 收到请求时, |
| 17 | +当我们调用 `/hello` 路径时,它会在响应中包含其版本信息。 |
| 18 | + |
| 19 | +我们还将把 `curl` 容器部署到两个集群。我们将使用这些 Pod 作为 `HelloWorld` 服务的请求源, |
| 20 | +模拟网格内流量。最后,在生成流量后,我们将观察哪个集群接收了请求。 |
| 21 | + |
| 22 | +## 验证多集群 {#verify-multicluster} |
| 23 | + |
| 24 | +确认 Istiod 现在能够与远程集群的 Kubernetes 控制平面通信。 |
| 25 | + |
| 26 | +{{< text bash >}} |
| 27 | +$ istioctl remote-clusters --context="${CTX_CLUSTER1}" |
| 28 | +NAME SECRET STATUS ISTIOD |
| 29 | +cluster1 synced istiod-7b74b769db-kb4kj |
| 30 | +cluster2 istio-system/istio-remote-secret-cluster2 synced istiod-7b74b769db-kb4kj |
| 31 | +{{< /text >}} |
| 32 | + |
| 33 | +所有集群的状态都应显示为 `synced`。如果集群的 `STATUS` 显示为 `timeout`, |
| 34 | +则表示主集群中的 Istiod 无法与远程集群通信。有关详细的错误消息,请参阅 Istiod 日志。 |
| 35 | + |
| 36 | +注意:如果您确实看到 `timeout` 问题,并且在主集群中的 Istiod 和远程集群中的 Kubernetes |
| 37 | +控制平面之间存在中间主机(例如 [Rancher 身份验证代理](https://ranchermanager.docs.rancher.com/zh/how-to-guides/new-user-guides/manage-clusters/access-clusters/authorized-cluster-endpoint#two-authentication-methods-for-rke-clusters)), |
| 38 | +则可能需要更新 `istioctl create-remote-secret` 生成的 kubeconfig |
| 39 | +的 `certificate-authority-data` 字段,以匹配中间主机正在使用的证书。 |
| 40 | + |
| 41 | +## 部署 `HelloWorld` 服务 {#deploy-the-helloworld-service} |
| 42 | + |
| 43 | +为了使 `HelloWorld` 服务能够从任何集群调用, |
| 44 | +DNS 查询必须在每个集群中成功(详情请参阅[部署模型](/zh/docs/ops/deployment/deployment-models#dns-with-multiple-clusters))。 |
| 45 | +我们将通过将 `HelloWorld` 服务部署到网格中的每个集群来解决此问题。 |
| 46 | + |
| 47 | +{{< tip >}} |
| 48 | +在继续之前,请确保两个集群中的 istio-system 命名空间都将 `istio.io/topology-network` |
| 49 | +设置为适当的值(例如,`cluster1` 设置为 `network1`,`cluster2` 设置为 `network2`)。 |
| 50 | +{{< /tip >}} |
| 51 | + |
| 52 | +首先,在每个集群中创建 `sample` 命名空间: |
| 53 | + |
| 54 | +{{< text bash >}} |
| 55 | +$ kubectl create --context="${CTX_CLUSTER1}" namespace sample |
| 56 | +$ kubectl create --context="${CTX_CLUSTER2}" namespace sample |
| 57 | +{{< /text >}} |
| 58 | + |
| 59 | +在网格中注册 `sample` 命名空间: |
| 60 | + |
| 61 | +{{< text bash >}} |
| 62 | +$ kubectl label --context="${CTX_CLUSTER1}" namespace sample \ |
| 63 | + istio.io/dataplane-mode=ambient |
| 64 | +$ kubectl label --context="${CTX_CLUSTER2}" namespace sample \ |
| 65 | + istio.io/dataplane-mode=ambient |
| 66 | +{{< /text >}} |
| 67 | + |
| 68 | +在两个集群中创建 `HelloWorld` 服务: |
| 69 | + |
| 70 | +{{< text bash >}} |
| 71 | +$ kubectl apply --context="${CTX_CLUSTER1}" \ |
| 72 | + -f @samples/helloworld/helloworld.yaml@ \ |
| 73 | + -l service=helloworld -n sample |
| 74 | +$ kubectl apply --context="${CTX_CLUSTER2}" \ |
| 75 | + -f @samples/helloworld/helloworld.yaml@ \ |
| 76 | + -l service=helloworld -n sample |
| 77 | +{{< /text >}} |
| 78 | + |
| 79 | +## 部署 `HelloWorld` `V1` {#deploy-helloworld-v1} |
| 80 | + |
| 81 | +将 `helloworld-v1` 应用程序部署到 `cluster1`: |
| 82 | + |
| 83 | +{{< text bash >}} |
| 84 | +$ kubectl apply --context="${CTX_CLUSTER1}" \ |
| 85 | + -f @samples/helloworld/helloworld.yaml@ \ |
| 86 | + -l version=v1 -n sample |
| 87 | +{{< /text >}} |
| 88 | + |
| 89 | +确认 `helloworld-v1` Pod 状态: |
| 90 | + |
| 91 | +{{< text bash >}} |
| 92 | +$ kubectl get pod --context="${CTX_CLUSTER1}" -n sample -l app=helloworld |
| 93 | +NAME READY STATUS RESTARTS AGE |
| 94 | +helloworld-v1-86f77cd7bd-cpxhv 1/1 Running 0 40s |
| 95 | +{{< /text >}} |
| 96 | + |
| 97 | +等待 `helloworld-v1` 的状态变为 `Running`。 |
| 98 | + |
| 99 | +现在,将 `cluster1` 中的 helloworld 服务标记为全局,以便可以从网格中的其他集群访问它: |
| 100 | + |
| 101 | +{{< text bash >}} |
| 102 | +$ kubectl label --context="${CTX_CLUSTER1}" svc helloworld -n sample \ |
| 103 | + istio.io/global="true" |
| 104 | +{{< /text >}} |
| 105 | + |
| 106 | +## 部署 `HelloWorld` `V2` {#deploy-helloworld-v2} |
| 107 | + |
| 108 | +将 `helloworld-v2` 应用程序部署到 `cluster2`: |
| 109 | + |
| 110 | +{{< text bash >}} |
| 111 | +$ kubectl apply --context="${CTX_CLUSTER2}" \ |
| 112 | + -f @samples/helloworld/helloworld.yaml@ \ |
| 113 | + -l version=v2 -n sample |
| 114 | +{{< /text >}} |
| 115 | + |
| 116 | +确认 `helloworld-v2` Pod 状态: |
| 117 | + |
| 118 | +{{< text bash >}} |
| 119 | +$ kubectl get pod --context="${CTX_CLUSTER2}" -n sample -l app=helloworld |
| 120 | +NAME READY STATUS RESTARTS AGE |
| 121 | +helloworld-v2-758dd55874-6x4t8 1/1 Running 0 40s |
| 122 | +{{< /text >}} |
| 123 | + |
| 124 | +等待 `helloworld-v2` 的状态变为 `Running`。 |
| 125 | + |
| 126 | +现在,将 `cluster2` 中的 helloworld 服务标记为全局,以便可以从网格中的其他集群访问它: |
| 127 | + |
| 128 | +{{< text bash >}} |
| 129 | +$ kubectl label --context="${CTX_CLUSTER2}" svc helloworld -n sample \ |
| 130 | + istio.io/global="true" |
| 131 | +{{< /text >}} |
| 132 | + |
| 133 | +## 部署 `curl` {#deploy-curl} |
| 134 | + |
| 135 | +将 `curl` 应用程序部署到两个集群: |
| 136 | + |
| 137 | +{{< text bash >}} |
| 138 | +$ kubectl apply --context="${CTX_CLUSTER1}" \ |
| 139 | + -f @samples/curl/curl.yaml@ -n sample |
| 140 | +$ kubectl apply --context="${CTX_CLUSTER2}" \ |
| 141 | + -f @samples/curl/curl.yaml@ -n sample |
| 142 | +{{< /text >}} |
| 143 | + |
| 144 | +确认 `cluster1` 上的 `curl` Pod 状态: |
| 145 | + |
| 146 | +{{< text bash >}} |
| 147 | +$ kubectl get pod --context="${CTX_CLUSTER1}" -n sample -l app=curl |
| 148 | +NAME READY STATUS RESTARTS AGE |
| 149 | +curl-754684654f-n6bzf 1/1 Running 0 5s |
| 150 | +{{< /text >}} |
| 151 | + |
| 152 | +等待 `curl` Pod 的状态变为 `Running`。 |
| 153 | + |
| 154 | +确认 `cluster2` 上的 `curl` Pod 状态: |
| 155 | + |
| 156 | +{{< text bash >}} |
| 157 | +$ kubectl get pod --context="${CTX_CLUSTER2}" -n sample -l app=curl |
| 158 | +NAME READY STATUS RESTARTS AGE |
| 159 | +curl-754684654f-dzl9j 1/1 Running 0 5s |
| 160 | +{{< /text >}} |
| 161 | + |
| 162 | +等待 `curl` Pod 的状态变为 `Running`。 |
| 163 | + |
| 164 | +## 验证跨集群流量 {#verifying-cross-cluster-traffic} |
| 165 | + |
| 166 | +要验证跨集群负载均衡是否按预期工作,请使用 `curl` Pod |
| 167 | +多次调用 `HelloWorld` 服务。为确保负载均衡正常工作, |
| 168 | +请从部署中的所有集群调用 `HelloWorld` 服务。 |
| 169 | + |
| 170 | +从 `cluster1` 上的 `curl` Pod 向 `HelloWorld` 服务发送一个请求: |
| 171 | + |
| 172 | +{{< text bash >}} |
| 173 | +$ kubectl exec --context="${CTX_CLUSTER1}" -n sample -c curl \ |
| 174 | + "$(kubectl get pod --context="${CTX_CLUSTER1}" -n sample -l \ |
| 175 | + app=curl -o jsonpath='{.items[0].metadata.name}')" \ |
| 176 | + -- curl -sS helloworld.sample:5000/hello |
| 177 | +{{< /text >}} |
| 178 | + |
| 179 | +重复此请求几次,并验证 `HelloWorld` 版本是否应在 `v1` 和 `v2` 之间变化, |
| 180 | +这表示两个集群中的端点都在被使用: |
| 181 | + |
| 182 | +{{< text plain >}} |
| 183 | +Hello version: v2, instance: helloworld-v2-758dd55874-6x4t8 |
| 184 | +Hello version: v1, instance: helloworld-v1-86f77cd7bd-cpxhv |
| 185 | +... |
| 186 | +{{< /text >}} |
| 187 | + |
| 188 | +现在从 `cluster2` 上的 `curl` Pod 重复此过程: |
| 189 | + |
| 190 | +{{< text bash >}} |
| 191 | +$ kubectl exec --context="${CTX_CLUSTER2}" -n sample -c curl \ |
| 192 | + "$(kubectl get pod --context="${CTX_CLUSTER2}" -n sample -l \ |
| 193 | + app=curl -o jsonpath='{.items[0].metadata.name}')" \ |
| 194 | + -- curl -sS helloworld.sample:5000/hello |
| 195 | +{{< /text >}} |
| 196 | + |
| 197 | +重复此请求几次并验证 `HelloWorld` 版本是否应在 `v1` 和 `v2` 之间切换: |
| 198 | + |
| 199 | +{{< text plain >}} |
| 200 | +Hello version: v2, instance: helloworld-v2-758dd55874-6x4t8 |
| 201 | +Hello version: v1, instance: helloworld-v1-86f77cd7bd-cpxhv |
| 202 | +... |
| 203 | +{{< /text >}} |
| 204 | + |
| 205 | +**恭喜!**您已成功在多个集群上安装并验证了 Istio! |
| 206 | + |
| 207 | +<!-- TODO: Link to guide for locality load balancing once we add waypoint instructions --> |
0 commit comments