做者:justminenode
頭條號:大數據與雲原生linux
微信公衆號:大數據與雲原生git
創做不易,在知足創做共用版權協議的基礎上能夠轉載,但請以超連接形式註明出處。github
爲了方便你們閱讀,能夠關注頭條號或微信公衆號,後續全部的文章將在移動端首發,想學習更多雲原生知識,請關注我。shell
隨着微服務架構的流行,服務網格技術得到了業界的普遍關注,做爲實現雲原生的重要積木,各大廠商也紛紛開始佈局,Amazon在2019年4月份推出了App Mesh;Google、IBM、Lyft聯合開發了Istio。json
Istio做爲下一代服務網格的總體解決方案,獲得了業界的廣泛承認,站在kubernetes巨人的肩膀上,極大地提升了分佈式應用的研發和運維效率。ubuntu
2020是雲原生普及的一年,如何部署、使用、運維Istio又是必需要學習知識,本篇但願帶給你們一個完美的入門體驗。api
從Istio最新發佈列表下載最新發布版本1.4.3壓縮包,及其命令行工具(Istioctl),以下:瀏覽器
# 建立工做目錄 mkdir -p /root/service-mesh/istio && cd /root/service-mesh/istio; # 下載 wget https://github.com/istio/istio/releases/download/1.4.3/istioctl-1.4.3-linux.tar.gz; ## istio也能夠演示的時候在下載 wget https://github.com/istio/istio/releases/download/1.4.3/istio-1.4.3-linux.tar.gz;
話外音:請下載相同版本的Istioctl和Istio,避免沒法預料的問題。安全
tar -vxzf istioctl-1.4.3-linux.tar.gz && cp istioctl /usr/local/bin;
爲了知足不一樣的安裝需求,Istio內置了一系列的安裝配置文件,生產環境建議以default
安裝配置文件爲起點。
話外音:可使用
istioctl profile list
命令查看內置配置文件列表,而後使用istioctl profile dump [配置文件名稱]
打印配置文件內容。
# 安裝 default # istioctl manifest apply --set profile=default - Applying manifest for component Base... ✔ Finished applying manifest for component Base. - Applying manifest for component Galley... - Applying manifest for component IngressGateway... - Applying manifest for component Citadel... - Applying manifest for component Kiali... - Applying manifest for component Prometheus... - Applying manifest for component Policy... - Applying manifest for component Pilot... - Applying manifest for component Injector... - Applying manifest for component Telemetry... ✔ Finished applying manifest for component IngressGateway. ✔ Finished applying manifest for component Citadel. ✔ Finished applying manifest for component Prometheus. ✔ Finished applying manifest for component Policy. ✔ Finished applying manifest for component Galley. ✔ Finished applying manifest for component Injector. ✔ Finished applying manifest for component Pilot. - Finished applying manifest for component Kiali. ✔ Finished applying manifest for component Telemetry. # 驗證 # kubectl get pod -n istio-system NAME READY STATUS RESTARTS AGE istio-citadel-7c959c8d59-hssf4 1/1 Running 0 100m istio-galley-5479df66b5-tr5hf 2/2 Running 0 100m istio-ingressgateway-7c95796d59-s5sc2 1/1 Running 0 100m istio-pilot-656556b575-7zzht 2/2 Running 0 100m istio-policy-5b9b9f5cd9-788rg 2/2 Running 6 100m istio-sidecar-injector-7dbcc9fc89-554vg 1/1 Running 0 100m istio-telemetry-7d5b5947db-tgbmg 2/2 Running 6 100m prometheus-685585888b-5f77l 1/1 Running 0 100m
等待幾分鐘,當全部的組件狀態都爲Running時,表示安裝成功。
經過將基礎設施轉移到Istio,使得應用開發者無需重複建設基礎設施,只需專一於業務邏輯。Istio負責管理整個應用服務集合,這些服務集合組成的網絡拓撲就叫服務網格,Istio提供了kiali來可視化整個服務網格。
# KIALI_USERNAME=$(read -p 'Kiali Username: ' uval && echo -n $uval | base64); Kiali Username: 用戶名 # KIALI_PASSPHRASE=$(read -sp 'Kiali Passphrase: ' pval && echo -n $pval | base64); Kiali Passphrase: 密碼 # cat <<EOF | kubectl apply -f - apiVersion: v1 kind: Secret metadata: name: kiali namespace: istio-system labels: app: kiali type: Opaque data: username: $KIALI_USERNAME passphrase: $KIALI_PASSPHRASE EOF
# istioctl manifest apply --set values.kiali.enabled=true [...] ✔ Finished applying manifest for component Kiali. [...]
使用NodePort方式暴露kiali服務到互聯網,以下:
話外音:應該根據
k8s
環境選擇不一樣聯網方式,生產環境建議暴露爲LoadLalancer
。
# kubectl -n istio-system edit svc kiali [...] spec: ports: - name: http-kiali [...] nodePort: 9527 type: NodePort [...]
瀏覽器鍵入地址http://[ip]:9527/kiali
,鍵入上面建立的憑證,登陸成功,以下:
本節將部署一個多語言異構化的微服務示例(Bookinfo),讓你們對服務網格有一個清晰的認識。
productpage
微服務
調用details
和reviews
微服務,提供圖書單品完整信息。
details
微服務
提供圖書詳細信息。
reviews
微服務
提供圖書評論信息。
一共有三個版本。v1版本不會調用ratings
微服務;v2版本調用ratings
服務,並將每一個等級顯示爲1到5個黑色星號;v3版本調用ratings
服務,並將每一個等級顯示爲1到5個紅色星號。
ratings
微服務
提供圖書星級評分信息。
一圖勝千言,總體架構以下:
將Bookinfo部署到k8s默認命名空間,即default。
kubectl label namespace default istio-injection=enabled
# 進入工做目錄,解壓剛剛下載的Istio root@just: cd /root/service-mesh/istio && tar -vxzf istio-1.4.3-linux.tar.gz # 使用kubectl部署到k8s root@just: kubectl apply -f istio-1.4.3/samples/bookinfo/platform/kube/bookinfo.yaml service/details created serviceaccount/bookinfo-details created deployment.apps/details-v1 created service/ratings created serviceaccount/bookinfo-ratings created deployment.apps/ratings-v1 created service/reviews created serviceaccount/bookinfo-reviews created deployment.apps/reviews-v1 created deployment.apps/reviews-v2 created deployment.apps/reviews-v3 created service/productpage created serviceaccount/bookinfo-productpage created deployment.apps/productpage-v1 created
# 爲Bookinfo部署入口網關 root@just: kubectl apply -f istio-1.4.3/samples/bookinfo/networking/bookinfo-gateway.yaml gateway.networking.istio.io/bookinfo-gateway created virtualservice.networking.istio.io/bookinfo created # 獲取網關地址 root@just: export INGRESS_HOST=$(kubectl get po -l istio=ingressgateway -n istio-system -o jsonpath='{.items[0].status.hostIP}') root@just: export INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].nodePort}') root@just: export GATEWAY_URL=$INGRESS_HOST:$INGRESS_PORT # 獲取圖書單品頁地址 echo http://${GATEWAY_URL}/productpage
不停地刷新圖書單品頁,kiali會實時地繪製服務網格,以下:
基於權重流量的實時控制,以下:
對於服務的可觀察性,kiali還提供了不少其餘的功能,這也是Istio相較於其餘服務網格框架的優點,這裏就不展現了。
本篇使用Istioctl搭建了一套完整的Istio系統,先從戰略上鳥瞰Istio,進一步從戰術上學習Istio將更加容易,做爲一個完整解決方案,後面系列將一步步學習如何運用Istio的鏈接、安全、控制、可觀察性全面地治理分佈式應用。
話外音:到目前爲止,你們應該明白Istio是個什麼東東了吧。
https://github.com/istio/istio/releases
https://istio.io/docs/setup/additional-setup/config-profiles
https://istio.io/docs/setup/getting-started
https://istio.io/docs/setup/install/istioctl/#customizing-the-configuration
https://istio.io/docs/reference/commands/istioctl
https://istio.io/docs/ops/diagnostic-tools/istioctl
https://istio.io/news/releases/1.4.x/announcing-1.4.3
https://istio.io/docs/examples/bookinfo
https://istio.io/docs/tasks/traffic-management/ingress/ingress-control/#determining-the-ingress-ip-and-ports
若是有什麼疑問和看法,歡迎評論區交流。
若是你以爲本篇文章對您有幫助的話,感謝您的【推薦】。
若是你對雲原生感興趣的話能夠【關注我】。