istio從1.5版本開(kāi)始回歸單體架構(gòu)垢袱,下面記錄1.6.1版本安裝測(cè)試攻柠。kubernetes版本為1.18
1.安裝
安裝請(qǐng)參考官網(wǎng),安裝包下載可以github上獲取惠遏,如果能聯(lián)網(wǎng)舀武,也可以使用下面命令獲取
$ curl -L https://istio.io/downloadIstio | sh -
切換到 Istio 包所在目錄下拄养。例如:Istio 包名為 istio-1.6.1
,則:
$ cd istio-1.6.1
然后將 istioctl
放到系統(tǒng)路徑下
$ mv ./bin/istioctl /usr/local/bin
接著就可以安裝了
istioctl manifest apply --set profile=demo
驗(yàn)證是否安裝成功
$ kubectl get svc -n istio-system
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
grafana ClusterIP 172.21.211.123 <none> 3000/TCP 2m
istio-citadel ClusterIP 172.21.177.222 <none> 8060/TCP,15014/TCP 2m
istio-egressgateway ClusterIP 172.21.113.24 <none> 80/TCP,443/TCP,15443/TCP 2m
istio-galley ClusterIP 172.21.132.247 <none> 443/TCP,15014/TCP,9901/TCP 2m
istio-ingressgateway LoadBalancer 172.21.144.254 52.116.22.242 15020:31831/TCP,80:31380/TCP,443:31390/TCP,31400:31400/TCP,15029:30318/TCP,15030:32645/TCP,15031:31933/TCP,15032:31188/TCP,15443:30838/TCP 2m
istio-pilot ClusterIP 172.21.105.205 <none> 15010/TCP,15011/TCP,8080/TCP,15014/TCP 2m
istio-policy ClusterIP 172.21.14.236 <none> 9091/TCP,15004/TCP,15014/TCP 2m
istio-sidecar-injector ClusterIP 172.21.155.47 <none> 443/TCP,15014/TCP 2m
istio-telemetry ClusterIP 172.21.196.79 <none> 9091/TCP,15004/TCP,15014/TCP,42422/TCP 2m
jaeger-agent ClusterIP None <none> 5775/UDP,6831/UDP,6832/UDP 2m
jaeger-collector ClusterIP 172.21.135.51 <none> 14267/TCP,14268/TCP 2m
jaeger-query ClusterIP 172.21.26.187 <none> 16686/TCP 2m
kiali ClusterIP 172.21.155.201 <none> 20001/TCP 2m
prometheus ClusterIP 172.21.63.159 <none> 9090/TCP 2m
tracing ClusterIP 172.21.2.245 <none> 80/TCP 2m
zipkin ClusterIP 172.21.182.245 <none> 9411/TCP
如果集群運(yùn)行在一個(gè)不支持外部負(fù)載均衡器的環(huán)境中(例如:minikube)银舱,istio-ingressgateway
的 EXTERNAL-IP
將顯示為 <pending>
狀態(tài)瘪匿。請(qǐng)使用服務(wù)的 NodePort
或 端口轉(zhuǎn)發(fā)來(lái)訪問(wèn)網(wǎng)關(guān)跛梗。
$ kubectl edit svc istio-ingressgateway -n istio-system
...
spec
...
type: NodePort
請(qǐng)確保關(guān)聯(lián)的 Kubernetes pod 已經(jīng)部署,并且 STATUS
為 Running
:
$ kubectl get pods -n istio-system
NAME READY STATUS RESTARTS AGE
grafana-f8467cc6-rbjlg 1/1 Running 0 1m
istio-citadel-78df5b548f-g5cpw 1/1 Running 0 1m
istio-egressgateway-78569df5c4-zwtb5 1/1 Running 0 1m
istio-galley-74d5f764fc-q7nrk 1/1 Running 0 1m
istio-ingressgateway-7ddcfd665c-dmtqz 1/1 Running 0 1m
istio-pilot-f479bbf5c-qwr28 1/1 Running 0 1m
istio-policy-6fccc5c868-xhblv 1/1 Running 2 1m
istio-sidecar-injector-78499d85b8-x44m6 1/1 Running 0 1m
istio-telemetry-78b96c6cb6-ldm9q 1/1 Running 2 1m
istio-tracing-69b5f778b7-s2zvw 1/1 Running 0 1m
kiali-99f7467dc-6rvwp 1/1 Running 0 1m
prometheus-67cdb66cbb-9w2hm 1/1 Running 0 1m
2.Profile配置
不同Profile柿顶,安裝的組件不同茄袖,上面是為了測(cè)試,指定了demo
配置嘁锯,具體不同版本請(qǐng)查看官網(wǎng)宪祥,下面貼一下:
下表中標(biāo)記為 X 的組件就是包含在配置文件里的內(nèi)容:
為了進(jìn)一步自定義 Istio 和安裝插件,您可以在安裝 Istio 時(shí)所使用的 istioctl manifest
命令中添加一個(gè)或多個(gè) --set <key>=<value>
選項(xiàng)家乘。 安裝選項(xiàng)中列出了完整的當(dāng)前所支持的安裝鍵值對(duì)集合蝗羊。
2.bookinfo示例
官網(wǎng)鏈接為https://istio.io/latest/zh/docs/examples/bookinfo/
1.進(jìn)入 Istio 安裝目錄。
2.Istio 默認(rèn)自動(dòng)注入 Sidecar. 請(qǐng)為 default
命名空間打上標(biāo)簽 istio-injection=enabled
:
$ kubectl label namespace default istio-injection=enabled
3.使用 kubectl
部署應(yīng)用:
$ kubectl apply -f samples/bookinfo/platform/kube/bookinfo.yaml
4.確認(rèn)所有的服務(wù)和 Pod 都已經(jīng)正確的定義和啟動(dòng):
$ kubectl get services
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
details 10.0.0.31 <none> 9080/TCP 6m
kubernetes 10.0.0.1 <none> 443/TCP 7d
productpage 10.0.0.120 <none> 9080/TCP 6m
ratings 10.0.0.15 <none> 9080/TCP 6m
reviews 10.0.0.170 <none> 9080/TCP 6m
和
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
details-v1-1520924117-48z17 2/2 Running 0 6m
productpage-v1-560495357-jk1lz 2/2 Running 0 6m
ratings-v1-734492171-rnr5l 2/2 Running 0 6m
reviews-v1-874083890-f0qf0 2/2 Running 0 6m
reviews-v2-1343845940-b34q5 2/2 Running 0 6m
reviews-v3-1813607990-8ch52 2/2 Running 0 6m
5.要確認(rèn) Bookinfo 應(yīng)用是否正在運(yùn)行仁锯,請(qǐng)?jiān)谀硞€(gè) Pod 中用 curl
命令對(duì)應(yīng)用發(fā)送請(qǐng)求耀找,例如 ratings
:
$ kubectl exec -it $(kubectl get pod -l app=ratings -o jsonpath='{.items[0].metadata.name}') -c ratings -- curl productpage:9080/productpage | grep -o "<title>.*</title>"
<title>Simple Bookstore App</title>
6.為應(yīng)用程序定義 Ingress 網(wǎng)關(guān):
$ kubectl apply -f samples/bookinfo/networking/bookinfo-gateway.yaml
7.確認(rèn)網(wǎng)關(guān)創(chuàng)建完成:
$ kubectl get gateway
NAME AGE
bookinfo-gateway 32s
8.通過(guò)istio網(wǎng)關(guān)訪問(wèn)應(yīng)用
瀏覽器訪問(wèn)http://$GATEWAY_URL/productpage,可以多刷新幾次业崖,會(huì)有不同的效果野芒。
$GATEWAY_URL=節(jié)點(diǎn)ip+nodeport端口
nodeport為istio-ingressgateway的svc的http2指定的端口,通過(guò)
$ kubectl get svc istio-ingressgateway -n istio-system -oyaml
...
- name: http2
nodePort: 31624
port: 80
protocol: TCP
...
8.驗(yàn)證規(guī)則
$ kubectl apply -f samples/bookinfo/networking/destination-rule-all.yaml
9.查看規(guī)則
kubectl get destinationrules -o yaml
3.清理bookinfo
$ samples/bookinfo/platform/kube/cleanup.sh
4.卸載istio
$ istioctl manifest generate --set profile=demo | kubectl delete -f -