快速上手
1. docker desktop 上安裝istio
這裡采用docker desktop安裝。如果沒有安裝docker desktop 看這裡 docker desktop 安裝
我們安裝21年1.9 release 版本。
這裡告訴你其他的安裝方式,你可以根據場景選擇。=>其他安裝istio 方式
這裡使用這種方式 Install with Istioctl Install with Istioctl
安裝事先準備
- 根據你的環境下載下傳對應的istioctl istio
-
設定好平台 docker desktop
至少需要配置設定4個CPU,8個G記憶體
[外鍊圖檔轉存失敗,源站可能有防盜鍊機制,建議将圖檔儲存下來直接上傳(img-iWCx4JrK-1613806927847)(http://andtwo.vip/wp-content/uploads/2021/02/docker_desktop.png)]
- 檢查已運作的pods 與 service
- 服務關系:一個Pod必須至少屬于一個Kubernetes服務,即使Pod不暴露任何端口也是如此。如果Pod屬于多個Kubernetes服務,則這些服務不能将相同的端口号用于不同的協定,例如HTTP和TCP
- 應用UID:確定Pod不以使用者ID(UID)為1337的使用者身份運作應用程式
- 有NET_ADMIN NET_RAW 的能力
- 帶有應用和版本标簽的部署
- 命名服務端口:服務端口必須命名。端口名稱鍵/值對必須具有以下文法
name: <protocol>[-<suffix>]
安裝istio
>istioctl install
Detected that your cluster does not support third party JWT authentication. Falling back to less secure first party JWT. See https://istio.io/v1.9/docs/ops/best-practices/security/#configure-third-party-service-account-tokens for details.
This will install the Istio 1.9.0 profile with ["Istio core" "Istiod" "Ingress gateways"] components into the cluster. Proceed? (y/N) y
✔ Istio core installed
✔ Istiod installed
✔ Ingress gateways installed
- Pruning removed resources Removed PodDisruptionBudget:istio-system:istio-egressgateway.
Removed Deployment:istio-system:istio-egressgateway.
Removed Service:istio-system:istio-egressgateway.
Removed ServiceAccount:istio-system:istio-egressgateway-service-account.
Removed RoleBinding:istio-system:istio-egressgateway-sds.
Removed Role:istio-system:istio-egressgateway-sds.
✔ Installation complete
2. istio 中部署一個應用
- git clone 書上的列子:
git clone https://github.com/osswangxining/istio-book
- 建立命名空間 voting,
kubectl create ns voting
- 為命名空間增加一個标簽 istio-injection=enabled ,四體哦自動将代理sidecar 注入到此命名空間下的所有pod中
kubectl label ns voting istio-injection=enabled
-
應用pod,部署1.0版本
在 istio-book/intelligent-routing-with-istio 目錄下
輸出以下,表示成功建立:kubectl apply -f kubernetes/step-1-create-voting-app.yaml --namespace voting
>kubectl apply -f kubernetes/step-1-create-voting-app.yaml --namespace voting
deployment.apps/voting-storage-1-0 created
service/voting-storage created
deployment.apps/voting-analytics-1-0 created
service/voting-analytics created
deployment.apps/voting-app-1-0 created
service/voting-app created
過一會檢查下pods是否正常在跑
>kubectl get pods -n voting
NAME READY STATUS RESTARTS AGE
voting-analytics-1-0-7d679cdb57-hmswv 2/2 Running 0 6m58s
voting-app-1-0-848ddcfd4c-shxks 2/2 Running 0 6m57s
voting-storage-1-0-7c76cb7d47-mfvqw 2/2 Running 0 6m58s
- 建立網關
>kubectl apply -f istio/step-1-create-voting-app-gateway.yaml --namespace voting
virtualservice.networking.istio.io/voting-app created
gateway.networking.istio.io/voting-app-gateway created
- 檢查service 狀态
>kubectl get svc -n voting
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
voting-analytics ClusterIP 10.99.104.100 <none> 8080/TCP 12m
voting-app ClusterIP 10.96.173.223 <none> 8080/TCP 12m
voting-storage ClusterIP 10.97.231.62 <none> 6379/TCP 12m
下面指令檢視istio Gateway =》voting-app-gateway
kubectl get gateway
下面指令檢視虛拟服務
kubectl get vs -n voting
NAME GATEWAYS HOSTS AGE
voting-app [voting-app-gateway] [*] 30m
-
頁面驗證
頁面通路一下http://localhost 出現以下頁面,表示運作成功 (點選istio 會累加,其他時也會累加)
[外鍊圖檔轉存失敗,源站可能有防盜鍊機制,建議将圖檔儲存下來直接上傳(img-A5ZEc4qW-1613806927852)(http://andtwo.vip/wp-content/uploads/2021/02/截屏2021-02-20-下午2.52.56.png)]
-
部署2.0 版本
2.0 版本增加了cookie featureflag=on 比對規則,命中了會走v2版本
kubectl apply -f istio/step-2a-update-voting-app-virtualservice.yaml --namespace voting
更新虛拟服務/目标規則
>kubectl apply -f istio/step-2b-add-routing-for-all-components.yaml -n voting
destinationrule.networking.istio.io/voting-app created
destinationrule.networking.istio.io/voting-analytics created
virtualservice.networking.istio.io/voting-analytics created
destinationrule.networking.istio.io/voting-storage created
virtualservice.networking.istio.io/voting-storage created
更新voting-app服務,增加v2版本
kubectl apply -f kubernetes/step-2-update-voting-app-to-2.0.yaml -n voting
檢查下:
>kubectl get pods -n voting
NAME READY STATUS RESTARTS AGE
voting-analytics-1-0-7d679cdb57-hmswv 2/2 Running 0 61m
voting-app-1-0-848ddcfd4c-shxks 2/2 Running 0 61m
voting-app-2-0-5686d959cb-wj7dg 2/2 Running 0 56s
voting-storage-1-0-7c76cb7d47-mfvqw 2/2 Running 0 61m
>kubectl get vs -n voting
NAME GATEWAYS HOSTS AGE
voting-analytics [voting-analytics.voting.svc.cluster.local] 6m15s
voting-app [voting-app-gateway] [*] 63m
voting-storage [voting-storage.voting.svc.cluster.local] 6m15s
-
檢查V2版本
再次打開http://localhost,圖中set 點選一次,會在cookie中增加v2版本的标示,頁面會重新整理成v2的樣子。v2版本沒有下方的灰色内容
[外鍊圖檔轉存失敗,源站可能有防盜鍊機制,建議将圖檔儲存下來直接上傳(img-5EX3YHdz-1613806927854)(http://andtwo.vip/wp-content/uploads/2021/02/v1.png)]
[外鍊圖檔轉存失敗,源站可能有防盜鍊機制,建議将圖檔儲存下來直接上傳(img-fwMPQaid-1613806927856)(http://andtwo.vip/wp-content/uploads/2021/02/v2.png)]
到此,初次的istio 使用實踐完成。
這裡具體gateway ,virtualservice,destinationRule,policy 等後續文章會具體介紹。
圖檔沒有的,請移步個人網站 andtwo.vip