這篇文章主要講解了“怎么使用Istio進(jìn)行多集群部署管理”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來(lái)研究和學(xué)習(xí)“怎么使用Istio進(jìn)行多集群部署管理”吧!
10年積累的成都網(wǎng)站建設(shè)、成都網(wǎng)站制作經(jīng)驗(yàn),可以快速應(yīng)對(duì)客戶對(duì)網(wǎng)站的新想法和需求。提供各種問(wèn)題對(duì)應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認(rèn)識(shí)你,你也不認(rèn)識(shí)我。但先網(wǎng)站設(shè)計(jì)后付款的網(wǎng)站建設(shè)流程,更有彭水苗族土家族免費(fèi)網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。
在多控制平面拓?fù)涞呐渲弥校總€(gè) Kubernetes 集群都會(huì)安裝相同的 Istio 控制平面,并且每個(gè)控制平面只會(huì)管理自己集群內(nèi)的服務(wù)端點(diǎn)。通過(guò)使用 Istio 網(wǎng)關(guān)、公共根證書頒發(fā)機(jī)構(gòu)(CA)以及服務(wù)條目 ServiceEntry,可以將多個(gè)集群配置組成一個(gè)邏輯上的單一服務(wù)網(wǎng)格。這種方法沒(méi)有特殊的網(wǎng)絡(luò)要求,因此通常被認(rèn)為是在 Kubernetes 集群之間沒(méi)有通用網(wǎng)絡(luò)連接時(shí)的一種最簡(jiǎn)單方法。
在這種拓?fù)渑渲孟?,Kubernetes 跨集群通信需要服務(wù)之間的雙向 TLS 連接,要在集群之間啟用雙向 TLS 通信,每個(gè)集群的 Citadel 將配置由共享的根 CA 生成的中間 CA 證書,如圖所示。
(多控制平面)
從共享的根 CA 為每個(gè)集群的 Citadel 生成中間 CA 證書,共享的根 CA 啟用跨不同集群的雙向 TLS 通信。為了便于說(shuō)明,我們將 samples/certs 目錄下 Istio 安裝中提供的示例根 CA 證書用于兩個(gè)集群。在實(shí)際部署中,你可能會(huì)為每個(gè)集群使用不同的 CA 證書,所有 CA 證書都由公共根 CA 簽名。
在每個(gè) Kubernetes 集群中實(shí)施以下步驟,以在所有集群中部署相同的 Istio 控制平面配置。
使用以下的命令為生成的 CA 證書創(chuàng)建 Kubernetes 密鑰,如下所示:
kubectl create namespace istio-system kubectl create secret generic cacerts -n istio-system \ --from-file=samples/certs/ca-cert.pem \ --from-file=samples/certs/ca-key.pem \ --from-file=samples/certs/root-cert.pem \ --from-file=samples/certs/cert-chain.pem
安裝 Istio 的 CRD 并等待幾秒鐘,以便將它們提交給 Kubernetes API 服務(wù)器,如下所示:
for i in install/kubernetes/helm/istio-init/files/crd*yaml; do kubectl apply -f $i; done
部署 Istio 控制平面:如果 helm 依賴項(xiàng)缺失或者不是最新的,可以通過(guò) helm dep update 來(lái)更新這些依賴項(xiàng)。注意因?yàn)闆](méi)有使用 istio-cni,可以暫時(shí)將其從依賴項(xiàng) requirements.yaml 中去掉再執(zhí)行更新操作。具體執(zhí)行命令如下:
helm template install/kubernetes/helm/istio --name istio --namespace istio-system \ -f install/kubernetes/helm/istio/values-istio-multicluster-gateways.yaml > ./istio.yaml kubectl apply -f ./istio.yaml
確保上述步驟在每個(gè) Kubernetes 集群中都執(zhí)行成功。當(dāng)然,通過(guò) helm 生成 istio.yaml 的命令執(zhí)行一次即可。
為遠(yuǎn)程集群中的服務(wù)提供 DNS 解析,則現(xiàn)有應(yīng)用程序不需要做修改就可以運(yùn)行,因?yàn)閼?yīng)用程序通常期望通過(guò)其 DNS 名稱來(lái)解析服務(wù)并訪問(wèn)所得到的 IP 地址。Istio 本身不使用 DNS 在服務(wù)之間路由請(qǐng)求,同一個(gè) Kubernetes 集群下的服務(wù)會(huì)共享一個(gè)相同的 DNS 后綴(例如 svc.cluster.local)。Kubernetes DNS 為這些服務(wù)提供 DNS 解析能力。為了給遠(yuǎn)程集群中的服務(wù)提供相似的設(shè)置,將遠(yuǎn)程集群中的服務(wù)以 ..global 的格式命名。
Istio 安裝包中附帶了一個(gè) CoreDNS 服務(wù)器,該服務(wù)器將為這些服務(wù)提供DNS解析能力。為了利用這個(gè) DNS 解析能力,需要配置 Kubernetes 的 DNS 服務(wù)指向該 CoreDNS 服務(wù)。該 CoreDNS 服務(wù)將作為 .global DNS 域的 DNS 服務(wù)器。
對(duì)于使用 kube-dns 的集群,請(qǐng)創(chuàng)建以下配置項(xiàng)或更新現(xiàn)有的配置項(xiàng):
kubectl apply -f - <<EOF apiVersion: v1 kind: ConfigMap metadata: name: kube-dns namespace: kube-system data: stubDomains: | {"global": ["$(kubectl get svc -n istio-system istiocoredns -o jsonpath={.spec.clusterIP})"]} EOF
對(duì)于使用 CoreDNS 的集群,請(qǐng)創(chuàng)建以下配置項(xiàng)或更新現(xiàn)有的配置項(xiàng):
kubectl apply -f - <<EOF apiVersion: v1 kind: ConfigMap metadata: name: coredns namespace: kube-system data: Corefile: | .:53 { errors health kubernetes cluster.local in-addr.arpa ip6.arpa { pods insecure upstream fallthrough in-addr.arpa ip6.arpa } prometheus :9153 proxy . /etc/resolv.conf cache 30 reload loadbalance } global:53 { errors cache 30 proxy . $(kubectl get svc -n istio-system istiocoredns -o jsonpath={. spec.clusterIP}) } EOF
為了演示跨集群訪問(wèn),在一個(gè) Kubernetes 集群中部署 sleep 應(yīng)用服務(wù),在第二個(gè)集群中部署 httpbin 應(yīng)用服務(wù),然后驗(yàn)證 sleep 應(yīng)用是否可以調(diào)用遠(yuǎn)程集群的 httpbin 服務(wù)。
部署 sleep 服務(wù)到第一個(gè)集群 cluster1 中,執(zhí)行如下命令:
kubectl create namespace app1 kubectl label namespace app1 istio-injection=enabled kubectl apply -n app1 -f samples/sleep/sleep.yaml export SLEEP_POD=$(kubectl get -n app1 pod -l app=sleep -o jsonpath={.items..metadata.name})
部署 httpbin 服務(wù)到第二個(gè)集群 cluster2 中,執(zhí)行如下命令:
kubectl create namespace app2 kubectl label namespace app2 istio-injection=enabled kubectl apply -n app2 -f samples/httpbin/httpbin.yaml
獲取集群 cluster2 的入口網(wǎng)關(guān)地址,如下所示:
export CLUSTER2_GW_ADDR=$(kubectl get svc --selector=app=istio-ingressgateway \ -n istio-system -o jsonpath="{.items[0].status.loadBalancer.ingress[0].ip}")
為了讓在集群 cluster1 中的服務(wù) sleep 能夠訪問(wèn)集群 cluster2 中的服務(wù) httpbin,我們需要在集群 cluster1 中為服務(wù) httpbin 創(chuàng)建一個(gè)服務(wù)條目 ServiceEntry 資源。服務(wù)條目 ServiceEntry 的主機(jī)名應(yīng)該是..globalname,其中 name 和 namespace 分別對(duì)應(yīng)于集群 cluster2 中的遠(yuǎn)程服務(wù)的名稱和命名空間。
對(duì)于 *.global 域下服務(wù)的 DNS 解析,需要為這些服務(wù)分配一個(gè) IP 地址,并且保證 .globalDNS 域中的每個(gè)服務(wù)在集群中必須具有唯一的 IP 地址。這些 IP 地址在 pod 之外是不可路由的。在這個(gè)例子中,我們將使用網(wǎng)段 127.255.0.0/16 來(lái)避免與其他的IP沖突。這些 IP 的應(yīng)用流量將由 Sidecar 代理捕獲并路由到適當(dāng)?shù)钠渌h(yuǎn)程服務(wù)。
在集群 cluster1 中創(chuàng)建該 httpbin 服務(wù)對(duì)應(yīng)的 ServiceEntry,執(zhí)行如下命令:
kubectl apply -n app1 -f - <<EOF apiVersion: networking.istio.io/v1alpha3 kind: ServiceEntry metadata: name: httpbin-app2 spec: hosts: # must be of form name.namespace.global - httpbin.app2.global # Treat remote cluster services as part of the service mesh # as all clusters in the service mesh share the same root of trust. location: MESH_INTERNAL ports: - name: http1 number: 8000 protocol: http resolution: DNS addresses: # the IP address to which httpbin.bar.global will resolve to # must be unique for each remote service, within a given cluster. # This address need not be routable. Traffic for this IP will be captured # by the sidecar and routed appropriately. - 127.255.0.2 endpoints: # This is the routable address of the ingress gateway in cluster2 that # sits in front of sleep.bar service. Traffic from the sidecar will be # routed to this address. - address: ${CLUSTER2_GW_ADDR} ports: http1: 15443 # Do not change this port value EOF
上面的配置將會(huì)使集群 cluster1 中訪問(wèn) httpbin.app2.global 的所有流量,包括訪問(wèn)它的任何端口的流量,都會(huì)被路由到啟用了雙向 TLS 連接的端點(diǎn) :15443 上。
端口 15443 的網(wǎng)關(guān)是一個(gè)特殊的 SNI 感知的 Envoy 代理,它是在前面開始部分中作為多集群 Istio 安裝步驟的一部分預(yù)先配置和安裝的。進(jìn)入端口 15443 的流量將在目標(biāo)集群的適當(dāng)內(nèi)部服務(wù)的 pod 中進(jìn)行負(fù)載均衡。
在集群 cluster1 下執(zhí)行如下命令查看容器 istiocoredns,可以看到上述 ServiceEntry 的域名映射關(guān)系已經(jīng)被加載:
export ISTIO_COREDNS=$(kubectl get -n istio-system po -l app=istiocoredns -o jsonpath={.items..metadata.name}) kubectl logs --tail 2 -n istio-system ${ISTIO_COREDNS} -c istio-coredns-plugin
執(zhí)行結(jié)果如下所示:
驗(yàn)證在集群 cluster1 中的 sleep 服務(wù)是否可以正常調(diào)用位于集群 cluster2 中的 httpbin 服務(wù),在集群 cluster1 執(zhí)行如下命令:
kubectl exec $SLEEP_POD -n app1 -c sleep -- curl httpbin.app2.global:8000/headers
執(zhí)行結(jié)果如下所示:
至此,集群 cluster1 與 cluster2 在多控制平面配置下完成了連通。
通過(guò)前面的文章,我們已經(jīng)了解了 Istio 的很多功能,例如基本版本的路由等,可以在單個(gè) Kubernetes 集群上很容易地實(shí)現(xiàn)。而很多真實(shí)的業(yè)務(wù)場(chǎng)景中,基于微服務(wù)的應(yīng)用程序并非那么簡(jiǎn)單,而是需要在多個(gè)位置跨集群去分配和運(yùn)行服務(wù)。那么問(wèn)題就來(lái)了,是否 Istio 的這些功能同樣可以很簡(jiǎn)單地運(yùn)行在這些真實(shí)的復(fù)雜環(huán)境中呢?
下面我們將會(huì)通過(guò)一個(gè)示例來(lái)了解 Istio 的流量管理功能如何在具有多個(gè)控制平面拓?fù)涞亩嗉壕W(wǎng)格中正常運(yùn)行。
首先,部署版本 v1 的 helloworld 服務(wù)到第一個(gè)集群 cluster1 中,執(zhí)行如下命令:
kubectl create namespace hello kubectl label namespace hello istio-injection=enabled kubectl apply -n hello -f samples/sleep/sleep.yaml kubectl apply -n hello -f samples/helloworld/service.yaml kubectl apply -n hello -f samples/helloworld/helloworld.yaml -l version=v1
部署版本 v2 與 v3 的 helloworld 服務(wù)到第二個(gè)集群 cluster2 中,執(zhí)行如下命令:
kubectl create namespace hello kubectl label namespace hello istio-injection=enabled kubectl apply -n hello -f samples/helloworld/service.yaml kubectl apply -n hello -f samples/helloworld/helloworld.yaml -l version=v2 kubectl apply -n hello -f samples/helloworld/helloworld.yaml -l version=v3
如前面章節(jié)中所述,多控制平面下,需要使用以 .global 為后綴的 DNS 名稱訪問(wèn)遠(yuǎn)程服務(wù)。
在我們的例子中,它是 helloworld.hello.global,所以我們需要在集群 cluster1 中創(chuàng)建服務(wù)條目 ServiceEntry 和目標(biāo)規(guī)則 DestinationRule。服務(wù)條目 ServiceEntry 將使用集群 cluster2 的入口網(wǎng)關(guān)作為端點(diǎn)地址來(lái)訪問(wèn)服務(wù)。
通過(guò)使用以下命令在集群 cluster1 中創(chuàng)建 helloworld 服務(wù)對(duì)應(yīng)的服務(wù)條目 ServiceEntry 和目標(biāo)規(guī)則DestinationRule:
kubectl apply -n hello -f - <<EOF apiVersion: networking.istio.io/v1alpha3 kind: ServiceEntry metadata: name: helloworld spec: hosts: - helloworld.hello.global location: MESH_INTERNAL ports: - name: http1 number: 5000 protocol: http resolution: DNS addresses: - 127.255.0.8 endpoints: - address: ${CLUSTER2_GW_ADDR} labels: cluster: cluster2 ports: http1: 15443 # Do not change this port value --- apiVersion: networking.istio.io/v1alpha3 kind: DestinationRule metadata: name: helloworld-global spec: host: helloworld.hello.global trafficPolicy: tls: mode: ISTIO_MUTUAL subsets: - name: v2 labels: cluster: cluster2 - name: v3 labels: cluster: cluster2 EOF
在兩個(gè)集群上創(chuàng)建目標(biāo)規(guī)則。在集群 cluster1 中創(chuàng)建子集 v1 對(duì)應(yīng)的目標(biāo)規(guī)則,執(zhí)行如下命令:
kubectl apply -n hello -f - <<EOF apiVersion: networking.istio.io/v1alpha3 kind: DestinationRule metadata: name: helloworld spec: host: helloworld.hello.svc.cluster.local trafficPolicy: tls: mode: ISTIO_MUTUAL subsets: - name: v1 labels: version: v1 EOF
而在集群 cluster2 中創(chuàng)建子集 v2 和 v3 對(duì)應(yīng)的目標(biāo)規(guī)則,執(zhí)行如下命令:
kubectl apply -n hello -f - <<EOF apiVersion: networking.istio.io/v1alpha3 kind: DestinationRule metadata: name: helloworld spec: host: helloworld.hello.svc.cluster.local trafficPolicy: tls: mode: ISTIO_MUTUAL subsets: - name: v2 labels: version: v2 - name: v3 labels: version: v3 EOF
創(chuàng)建虛擬服務(wù)以路由流量。
應(yīng)用下面的虛擬服務(wù)將會(huì)使得來(lái)自用戶 jason 對(duì) helloworld 的流量請(qǐng)求指向位于集群 cluster2 中的版本 v2 和 v3,其中 v2 比例為 70%,v3 比例為 30%;來(lái)自任何其他用戶對(duì) helloworld 的流量請(qǐng)求都將轉(zhuǎn)到位于集群 cluster1 中的版本 v1:
kubectl apply -n hello -f - <<EOF apiVersion: networking.istio.io/v1alpha3 kind: VirtualService metadata: name: helloworld spec: hosts: - helloworld.hello.svc.cluster.local - helloworld.hello.global http: - match: - headers: end-user: exact: jason route: - destination: host: helloworld.hello.global subset: v2 weight: 70 - destination: host: helloworld.hello.global subset: v3 weight: 30 - route: - destination: host: helloworld.hello.svc.cluster.local subset: v1 EOF
執(zhí)行多次調(diào)用,可以從下面的執(zhí)行結(jié)果中看出,上述流量路由的規(guī)則生效,這也說(shuō)明了在多控制平面拓?fù)湎拢糜诼酚傻囊?guī)則定義與在本地集群的使用方式是一樣的:
設(shè)置多集群網(wǎng)格的最簡(jiǎn)單方法是使用多控制平面拓?fù)?,因?yàn)樗鼪](méi)有特殊的網(wǎng)絡(luò)要求。通過(guò)上述示例可以看出,在單個(gè) Kubernetes 集群上運(yùn)行的路由功能同樣很容易地在多個(gè)集群中使用運(yùn)行。
感謝各位的閱讀,以上就是“怎么使用Istio進(jìn)行多集群部署管理”的內(nèi)容了,經(jīng)過(guò)本文的學(xué)習(xí)后,相信大家對(duì)怎么使用Istio進(jìn)行多集群部署管理這一問(wèn)題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是創(chuàng)新互聯(lián),小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!
當(dāng)前名稱:怎么使用Istio進(jìn)行多集群部署管理
URL鏈接:http://jinyejixie.com/article26/ijgecg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)頁(yè)設(shè)計(jì)公司、靜態(tài)網(wǎng)站、手機(jī)網(wǎng)站建設(shè)、Google、ChatGPT、虛擬主機(jī)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)