验证 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
服务
为了使 HelloWorld
服务能够从任何集群调用,
DNS 查询必须在每个集群中成功(详情请参阅部署模型)。
我们将通过将 HelloWorld
服务部署到网格中的每个集群来解决此问题。
首先,在每个集群中创建 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
服务:
$ 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
:
$ 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
:
$ 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
应用程序部署到两个集群:
$ 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!