唯品会一家专门做特卖的网站手机版,龙岩做网站公司有哪些,动漫网站开发与建设,vs做网站好不好单控制平面拓扑下#xff0c;多个 Kubernetes 集群共同使用在其中一个集群上运行的单个 Istio 控制平面。控制平面的 Pilot 管理本地和远程集群上的服务#xff0c;并为所有集群配置 Envoy Sidecar 代理。
集群感知的服务路由
Istio 1.1 中引入了集群感知的服务路由能力多个 Kubernetes 集群共同使用在其中一个集群上运行的单个 Istio 控制平面。控制平面的 Pilot 管理本地和远程集群上的服务并为所有集群配置 Envoy Sidecar 代理。
集群感知的服务路由
Istio 1.1 中引入了集群感知的服务路由能力在单一控制平面拓扑配置下使用 Istio 的 Split-horizon EDS水平分割端点发现服务功能可以通过其入口网关将服务请求路由到其他集群。基于请求源的位置Istio 能够将请求路由到不同的端点。
在该配置中从一个集群中的 Sidecar 代理到同一集群中的服务的请求仍然被转发到本地服务 IP。如果目标工作负载在其他集群中运行则使用远程集群的网关 IP 来连接到该服务。 如图所示主集群 cluster1 运行全套的 Istio 控制平面组件同时集群 cluster2 仅运行 Istio Citadel、Sidecar Injector 和 Ingress 网关。不需要 VPN 连接不同集群中的工作负载之间也不需要直接网络访问。
从共享的根 CA 为每个集群的 Citadel 生成中间 CA 证书共享的根 CA 启用跨不同集群的双向 TLS 通信。为了便于说明我们将 samples/certs 目录下 Istio 安装中提供的示例根 CA 证书用于两个集群。在实际部署中你可能会为每个集群使用不同的 CA 证书所有 CA 证书都由公共根 CA 签名。
在每个 Kubernetes 集群中包括示例中的集群 cluster1 与 cluster2使用以下命令为生成的 CA 证书创建 Kubernetes 密钥
kubectl create namespace istio-system
kubectl create secret generic cacerts -n istio-system \--from-filesamples/certs/ca-cert.pem \--from-filesamples/certs/ca-key.pem \--from-filesamples/certs/root-cert.pem \--from-filesamples/certs/cert-chain.pem
Istio 控制平面组件
在部署全套 Istio 控制平面组件的集群 cluster1 中按照以下步骤执行
1.安装 Istio 的 CRD 并等待几秒钟以便将它们提交给 Kubernetes API 服务器如下所示
for
i in install/kubernetes/helm/istio-init/files/crd*yaml; do kubectl apply -f $i;
done
2.然后开始在集群 cluster1 中部署 Istio 控制平面。
如果 helm 依赖项缺失或者不是最新的可以通过 helm dep update 来更新这些依赖项。需要注意的是因为没有使用 istio-cni可以暂时将其从依赖项 requirements.yaml 中去掉再执行更新操作。具体命令如下所示
helm
template --nameistio --namespaceistio-system \
--set
global.mtls.enabledtrue \
--set
security.selfSignedfalse \
--set
global.controlPlaneSecurityEnabledtrue \
--set
global.meshExpansion.enabledtrue \
--set
global.meshNetworks.network2.endpoints[0].fromRegistryn2-k8s-config \
--set
global.meshNetworks.network2.gateways[0].address0.0.0.0 \
--set
global.meshNetworks.network2.gateways[0].port15443 \
install/kubernetes/helm/istio./istio-auth.yaml
请注意网关地址设置为 0.0.0.0。这是一个临时占位符值在集群 cluster2 部署之后将更新为其网关的公共 IP 值。
将 Istio 部署到 cluster1如下所示
kubectl apply -f ./istio-auth.yaml
确保上述步骤在 Kubernetes 集群中执行成功。
创建网关以访问远程服务如下所示
kubectl
create -f - EOF
apiVersion:
networking.istio.io/v1alpha3
kind:
Gateway
metadata:name: cluster-aware-gatewaynamespace: istio-system
spec:selector:istio: ingressgatewayservers:- port:number: 15443name: tlsprotocol: TLStls:mode: AUTO_PASSTHROUGHhosts:- *
EOF
上述网关配置了一个专用端口 15443 用来将传入流量传递到请求的 SNI 标头中指定的目标服务从源服务到目标服务一直使用双向 TLS 连接。
请注意虽然该网关定义应用于集群 cluster1但因为两个集群都与同一个 Pilot 进行通信此网关实例同样也适用于集群 cluster2。
istio-remote 组件
在另一集群 cluster2 中部署 istio-remote 组件按照以下步骤执行
1.首先获取集群 cluster1 的入口网关地址如下所示
export LOCAL_GW_ADDR$(kubectl get svc --selectorappistio-ingressgateway \-n istio-system -o
jsonpath{.items[0].status.loadBalancer.ingress[0].ip})
通过执行以下命令使用 Helm 创建 Istio remote 部署 YAML 文件
helm
template --name istio-remote --namespaceistio-system \
--values
install/kubernetes/helm/istio/values-istio-remote.yaml \
--set
global.mtls.enabledtrue \
--set
gateways.enabledtrue \
--set
security.selfSignedfalse \
--set
global.controlPlaneSecurityEnabledtrue \
--set
global.createRemoteSvcEndpointstrue \
--set
global.remotePilotCreateSvcEndpointtrue \
--set
global.remotePilotAddress${LOCAL_GW_ADDR} \
--set
global.remotePolicyAddress${LOCAL_GW_ADDR} \
--set
global.remoteTelemetryAddress${LOCAL_GW_ADDR} \
--set
gateways.istio-ingressgateway.env.ISTIO_META_NETWORKnetwork2 \
--set
global.networknetwork2 \
install/kubernetes/helm/istioistio-remote-auth.yaml
2.将 Istio remote 组件部署到 cluster2如下所示
kubectl apply -f ./istio-remote-auth.yaml
确保上述步骤在 Kubernetes 集群中执行成功。
3.更新集群 cluster1 的配置项 istio获取集群 cluster2 的入口网关地址如下所示
export
REMOTE_GW_ADDR$(kubectl get --context$CTX_REMOTE svc --selectorapp
istio-ingressgateway
-n istio-system -o jsonpath{.items[0].status.loadBalancer.ingress
[0].ip})
在集群 cluster1 中编辑命名空间 istio-system 下的配置项 istio替换 network2 的网关地址从 0.0.0.0 变成集群 cluster2 的入口网关地址 ${REMOTE_GW_ADDR}。保存后Pilot 将自动读取更新的网络配置。
4.创建集群 cluster2 的 Kubeconfig。通过以下命令在集群 cluster2 上创建服务账号 istio-multi 的 Kubeconfig并保存为文件 n2-k8s-config
CLUSTER_NAMEcluster2
SERVER$(kubectl
config view --minifytrue -o jsonpath{.clusters[].cluster.server})
SECRET_NAME$(kubectl
get sa istio-multi -n istio-system -o jsonpath{.secrets[].name})
CA_DATA$(kubectl
get secret ${SECRET_NAME} -n istio-system -o
jsonpath{.data[ca\.crt]})
TOKEN$(kubectl
get secret ${SECRET_NAME} -n istio-system -o
jsonpath{.data[token]} | base64 --decode)
cat
EOF n2-k8s-config
apiVersion:
v1
kind:
Config
clusters:- cluster:certificate-authority-data: ${CA_DATA}server: ${SERVER}name: ${CLUSTER_NAME}
contexts:- context:cluster: ${CLUSTER_NAME}user: ${CLUSTER_NAME}name: ${CLUSTER_NAME}
current-context:
${CLUSTER_NAME}
users:- name: ${CLUSTER_NAME}user:token: ${TOKEN}
EOF
5.将集群 cluster2 加入到 Istio 控制平面。
在集群 clusterl 执行以下命令将上述生成的集群 cluster2 的 kubeconfig 添加到集群 cluster1 的 secret 中执行这些命令后集群 cluster1 中的 Istio Pilot 将开始监听集群 cluster2 的服务和实例就像监听集群 cluster1 中的服务与实例一样
kubectl create secret generic n2-k8s-secret --from-file n2-k8s-config -n istio-system
kubectl label secret n2-k8s-secret istio/multiClustertrue -n istio-system
部署示例应用
为了演示跨集群访问在第一个 Kubernetes 集群 cluster1 中部署 sleep 应用服务和版本 v1 的 helloworld 服务在第二个集群 cluster2 中部署版本 v2 的 helloworld 服务然后验证 sleep 应用是否可以调用本地或者远程集群的 helloworld 服务。
1.部署 sleep 和版本 v1 的 helloworld 服务到第一个集群 cluster1 中执行如下命令
kubectl
create namespace app1
kubectl
label namespace app1 istio-injectionenabled
kubectl
apply -n app1 -f samples/sleep/sleep.yaml
kubectl
apply -n app1 -f samples/helloworld/service.yaml
kubectl
apply -n app1 -f samples/helloworld/helloworld.yaml -l versionv1
export
SLEEP_POD$(kubectl get -n app1 pod -l appsleep -o
jsonpath{.items..metadata.name})
2.部署版本 v2 的 helloworld 服务到第二个集群 cluster2 中执行如下命令
kubectl
create namespace app1
kubectl
label namespace app1 istio-injectionenabled
kubectl
apply -n app1 -f samples/helloworld/service.yaml
kubectl
apply -n app1 -f samples/helloworld/helloworld.yaml -l versionv2
3.登录到命名空间 istio-system 下的 istio-pilot 容器中运行 curl localhost:8080/v1/registration | grep helloworld -A 11 -B 2 命令如果得到如下类似的结果就说明版本 v1 与 v2 的 helloworld 服务都已经注册到 Istio 控制平面中了
4.验证在集群 cluster1 中的 sleep 服务是否可以正常调用本地或者远程集群的 helloworld 服务在集群 cluster1 下执行如下命令
kubectl exec -it -n app1 $SLEEP_POD sh 登录到容器中运行 curl helloworld.app1:5000/hello。
如果设置正确则在返回的调用结果中可以看到两个版本的 helloworld 服务同时可以通过查看 sleep 容器组中的 istio-proxy 容器日志来验证访问的端点 IP 地址返回结果如下所示
原文链接 本文为云栖社区原创内容未经允许不得转载。