开始之前

在开始本地负载均衡任务之前,您必须首先在多个集群上安装 Istio。这些集群必须跨越三个区域,包含四个可用区。根据您的云提供商提供的功能,所需的集群数量可能会有所不同。

我们将部署 HelloWorld 应用程序的多个实例,如下所示

Setup for locality load balancing tasks
本地性负载均衡任务设置

环境变量

本指南假设所有集群都将通过默认Kubernetes 配置文件中的上下文进行访问。以下环境变量将用于各种上下文

变量描述
CTX_PRIMARY用于将配置应用于主集群的上下文。
CTX_R1_Z1用于与 region1.zone1 中的 Pod 交互的上下文。
CTX_R1_Z2用于与 region1.zone2 中的 Pod 交互的上下文。
CTX_R2_Z3用于与 region2.zone3 中的 Pod 交互的上下文。
CTX_R3_Z4用于与 region3.zone4 中的 Pod 交互的上下文。

创建 sample 命名空间

首先,为启用自动 Sidecar 注射的 sample 命名空间生成 yaml 文件。

$ cat <<EOF > sample.yaml
apiVersion: v1
kind: Namespace
metadata:
  name: sample
  labels:
    istio-injection: enabled
EOF

sample 命名空间添加到每个集群。

$ for CTX in "$CTX_PRIMARY" "$CTX_R1_Z1" "$CTX_R1_Z2" "$CTX_R2_Z3" "$CTX_R3_Z4"; \
  do \
    kubectl --context="$CTX" apply -f sample.yaml; \
  done

部署 HelloWorld

使用本地性作为版本字符串,为每个本地性生成 HelloWorld YAML。

压缩
$ for LOC in "region1.zone1" "region1.zone2" "region2.zone3" "region3.zone4"; \
  do \
    ./@samples/helloworld/gen-helloworld.sh@ \
      --version "$LOC" > "helloworld-${LOC}.yaml"; \
  done

HelloWorld YAML 应用于每个本地性的相应集群。

$ kubectl apply --context="${CTX_R1_Z1}" -n sample \
  -f helloworld-region1.zone1.yaml
$ kubectl apply --context="${CTX_R1_Z2}" -n sample \
  -f helloworld-region1.zone2.yaml
$ kubectl apply --context="${CTX_R2_Z3}" -n sample \
  -f helloworld-region2.zone3.yaml
$ kubectl apply --context="${CTX_R3_Z4}" -n sample \
  -f helloworld-region3.zone4.yaml

部署 curl

curl 应用程序部署到 region1 zone1

压缩
$ kubectl apply --context="${CTX_R1_Z1}" \
  -f @samples/curl/curl.yaml@ -n sample

等待 HelloWorld Pod

等待每个区域中的 HelloWorld Pod 处于 Running 状态。

$ kubectl get pod --context="${CTX_R1_Z1}" -n sample -l app="helloworld" \
  -l version="region1.zone1"
NAME                                       READY   STATUS    RESTARTS   AGE
helloworld-region1.zone1-86f77cd7b-cpxhv   2/2     Running   0          30s
$ kubectl get pod --context="${CTX_R1_Z2}" -n sample -l app="helloworld" \
  -l version="region1.zone2"
NAME                                       READY   STATUS    RESTARTS   AGE
helloworld-region1.zone2-86f77cd7b-cpxhv   2/2     Running   0          30s
$ kubectl get pod --context="${CTX_R2_Z3}" -n sample -l app="helloworld" \
  -l version="region2.zone3"
NAME                                       READY   STATUS    RESTARTS   AGE
helloworld-region2.zone3-86f77cd7b-cpxhv   2/2     Running   0          30s
$ kubectl get pod --context="${CTX_R3_Z4}" -n sample -l app="helloworld" \
  -l version="region3.zone4"
NAME                                       READY   STATUS    RESTARTS   AGE
helloworld-region3.zone4-86f77cd7b-cpxhv   2/2     Running   0          30s

恭喜! 您已成功配置系统,现在可以开始执行本地性负载均衡任务了!

后续步骤

您现在可以配置以下负载均衡选项之一

此信息是否有用?
您是否有任何改进建议?

感谢您的反馈!