验证 Ambient 安装

按照本指南验证您的 Ambient 多集群 Istio 安装是否正常工作。

在继续之前,请务必完成开始之前下的步骤, 且选择并遵循其中一个多集群安装指南。

在本指南中,我们将验证多集群功能是否正常,并将 HelloWorld 应用程序 v1 部署到 cluster1,将 v2 部署到 cluster2。当 HelloWorld 收到请求时, 当我们调用 /hello 路径时,它会在响应中包含其版本信息。

我们还将把 curl 容器部署到两个集群。我们将使用这些 Pod 作为 HelloWorld 服务的请求源, 模拟网格内流量。最后,在生成流量后,我们将观察哪个集群接收了请求。

验证多集群

确认 Istiod 现在能够与远程集群的 Kubernetes 控制平面通信。

$ istioctl remote-clusters --context="${CTX_CLUSTER1}"
NAME         SECRET                                        STATUS      ISTIOD
cluster1                                                   synced      istiod-7b74b769db-kb4kj
cluster2     istio-system/istio-remote-secret-cluster2     synced      istiod-7b74b769db-kb4kj

所有集群的状态都应显示为 synced。如果集群的 STATUS 显示为 timeout, 则表示主集群中的 Istiod 无法与远程集群通信。有关详细的错误消息,请参阅 Istiod 日志。

注意:如果您确实看到 timeout 问题,并且在主集群中的 Istiod 和远程集群中的 Kubernetes 控制平面之间存在中间主机(例如 Rancher 身份验证代理), 则可能需要更新 istioctl create-remote-secret 生成的 kubeconfig 的 certificate-authority-data 字段,以匹配中间主机正在使用的证书。

部署 HelloWorld 服务

每个集群的 DNS 服务器都会利用该集群内定义的 Kubernetes Service 来解析服务名称。 一个用于执行 curl 操作的 Pod 必须先获取 HelloWorld 服务的本地虚拟 IP(VIP), 才能发送请求;随后,Istio 便能将该请求路由至任一集群中的工作负载。 正因如此,即便某个集群中没有本地的 HelloWorld Pod, HelloWorld Service 也必须在两个集群中同时部署。

可以使用 ServiceEntry 代替 Kubernetes Service, 但它不会配置 Kubernetes DNS。因此, 必须手动或通过具有地址自动分配功能的 Istio DNS 代理配置 DNS。 本指南使用 Kubernetes 服务。有关更多详细信息, 请参阅具有多个集群的 DNS。

首先,在每个集群中创建 sample 命名空间:

$ kubectl create --context="${CTX_CLUSTER1}" namespace sample
$ kubectl create --context="${CTX_CLUSTER2}" namespace sample

在网格中注册 sample 命名空间:

$ kubectl label --context="${CTX_CLUSTER1}" namespace sample \
    istio.io/dataplane-mode=ambient
$ kubectl label --context="${CTX_CLUSTER2}" namespace sample \
    istio.io/dataplane-mode=ambient

在两个集群中创建 HelloWorld 服务:

ZipZip
$ kubectl apply --context="${CTX_CLUSTER1}" \
    -f @samples/helloworld/helloworld.yaml@ \
    -l service=helloworld -n sample
$ kubectl apply --context="${CTX_CLUSTER2}" \
    -f @samples/helloworld/helloworld.yaml@ \
    -l service=helloworld -n sample

部署 HelloWorld V1

将 helloworld-v1 应用程序部署到 cluster1:

Zip
$ kubectl apply --context="${CTX_CLUSTER1}" \
    -f @samples/helloworld/helloworld.yaml@ \
    -l version=v1 -n sample

确认 helloworld-v1 Pod 状态:

$ kubectl get pod --context="${CTX_CLUSTER1}" -n sample -l app=helloworld
NAME                            READY     STATUS    RESTARTS   AGE
helloworld-v1-86f77cd7bd-cpxhv  1/1       Running   0          40s

等待 helloworld-v1 的状态变为 Running。

现在,将 cluster1 中的 helloworld 服务标记为全局,以便可以从网格中的其他集群访问它:

$ kubectl label --context="${CTX_CLUSTER1}" svc helloworld -n sample \
    istio.io/global="true"

部署 HelloWorld V2

将 helloworld-v2 应用程序部署到 cluster2:

Zip
$ kubectl apply --context="${CTX_CLUSTER2}" \
    -f @samples/helloworld/helloworld.yaml@ \
    -l version=v2 -n sample

确认 helloworld-v2 Pod 状态:

$ kubectl get pod --context="${CTX_CLUSTER2}" -n sample -l app=helloworld
NAME                            READY     STATUS    RESTARTS   AGE
helloworld-v2-758dd55874-6x4t8  1/1       Running   0          40s

等待 helloworld-v2 的状态变为 Running。

现在,将 cluster2 中的 helloworld 服务标记为全局,以便可以从网格中的其他集群访问它:

$ kubectl label --context="${CTX_CLUSTER2}" svc helloworld -n sample \
    istio.io/global="true"

部署 curl

将 curl 应用程序部署到两个集群:

ZipZip
$ kubectl apply --context="${CTX_CLUSTER1}" \
    -f @samples/curl/curl.yaml@ -n sample
$ kubectl apply --context="${CTX_CLUSTER2}" \
    -f @samples/curl/curl.yaml@ -n sample

确认 cluster1 上的 curl Pod 状态:

$ kubectl get pod --context="${CTX_CLUSTER1}" -n sample -l app=curl
NAME                             READY   STATUS    RESTARTS   AGE
curl-754684654f-n6bzf            1/1     Running   0          5s

等待 curl Pod 的状态变为 Running。

确认 cluster2 上的 curl Pod 状态:

$ kubectl get pod --context="${CTX_CLUSTER2}" -n sample -l app=curl
NAME                             READY   STATUS    RESTARTS   AGE
curl-754684654f-dzl9j            1/1     Running   0          5s

等待 curl Pod 的状态变为 Running。

验证跨集群流量

要验证跨集群负载均衡是否按预期工作,请使用 curl Pod 多次调用 HelloWorld 服务。为确保负载均衡正常工作, 请从部署中的所有集群调用 HelloWorld 服务。

从 cluster1 上的 curl Pod 向 HelloWorld 服务发送一个请求:

$ kubectl exec --context="${CTX_CLUSTER1}" -n sample -c curl \
    "$(kubectl get pod --context="${CTX_CLUSTER1}" -n sample -l \
    app=curl -o jsonpath='{.items[0].metadata.name}')" \
    -- curl -sS helloworld.sample:5000/hello

重复此请求几次,并验证 HelloWorld 版本是否应在 v1 和 v2 之间变化, 这表示两个集群中的端点都在被使用:

Hello version: v2, instance: helloworld-v2-758dd55874-6x4t8
Hello version: v1, instance: helloworld-v1-86f77cd7bd-cpxhv
...

现在从 cluster2 上的 curl Pod 重复此过程:

$ kubectl exec --context="${CTX_CLUSTER2}" -n sample -c curl \
    "$(kubectl get pod --context="${CTX_CLUSTER2}" -n sample -l \
    app=curl -o jsonpath='{.items[0].metadata.name}')" \
    -- curl -sS helloworld.sample:5000/hello

重复此请求几次并验证 HelloWorld 版本是否应在 v1 和 v2 之间切换:

Hello version: v2, instance: helloworld-v2-758dd55874-6x4t8
Hello version: v1, instance: helloworld-v1-86f77cd7bd-cpxhv
...

**恭喜!**您已成功在多个集群上安装并验证了 Istio!

后续步骤

为您的多集群部署配置本地故障转移。

为您的多集群部署部署 Kiali。

这些信息有用吗?
您是否有更多建议和改进意见?

感谢您的反馈!