Bookinfo可以在sample這個folder裡面找到,官方是使用這個專案demo istio的功能特性,那我也來手把手跟著做做看
detailsreviews
ratings
ratigs
服務ratigs
服務,並使用 1 到 5 個黑色星形圖示來顯示評分ratigs
服務,並使用 1 到 5 個紅色星形圖示來顯示評分沒透過istio來進行服務間的溝通時,變成服務本身要自行與對應的服務進行溝通
圖片來源
使用istio時,每個服務間都是透過istio進行溝通
圖片來源
Bookinfo服務裝在namespace: default
上面,所以要先進行istio-injection
,使用sidecar
的方式把istio注入pod裡
kubectl label namespace default istio-injection=enabled
namespace/default labeled
部署samples裡面的bookinfo.yaml檔
kubectl apply -f 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
確定一下pod是否有正常啟動,這邊有node資源最低的要求,4g ram感覺不太夠,會遇到pod因為資源不足無法啟動,所以我這邊的spec是4c8g
kubectl get pods -n default
NAME READY STATUS RESTARTS AGE
details-v1-79f774bdb9-259mt 2/2 Running 0 53s
productpage-v1-6b746f74dc-z2d6k 2/2 Running 0 53s
ratings-v1-b6994bb9-pczcp 2/2 Running 0 53s
reviews-v1-545db77b95-qqgp4 2/2 Running 0 53s
reviews-v2-7bf8c9648f-8ff5x 2/2 Running 0 53s
reviews-v3-84779c7bbc-g6jgf 2/2 Running 0 53s
確認istio是否有透過sidecar執行,看到有istio-init跟istio-proxy的container在執行就沒錯啦~~
測試一下是否一切都正常
kubectl exec -ti ratings-v1-b6994bb9-pczcp -- /bin/bash
node@ratings-v1-b6994bb9-pczcp:/opt/microservices$ curl productpage:9080/productpage
如果有下面的資訊就一切都正常啦
<!DOCTYPE html>
<html>
<head>
<title>Simple Bookstore App</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
....
kubectl apply -f samples/bookinfo/networking/bookinfo-gateway.yaml
gateway.networking.istio.io/bookinfo-gateway created
virtualservice.networking.istio.io/bookinfo created
來看看bookinfo-gateway.yaml做什麼
apiVersion: networking.istio.io/v1alpha3
kind: Gateway #建立一個Gateway
metadata:
name: bookinfo-gateway
spec:
selector:
istio: ingressgateway # use istio default controller
servers:
- port:
number: 80 # 使用80port
name: http
protocol: HTTP
hosts: 這邊是沒指定host name
- "*"
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService 建立virtual service
metadata:
name: bookinfo
spec:
hosts: # 當host是*時,會根據path不同導到productpage
- "*"
gateways:
- bookinfo-gateway
http:
- match:
- uri:
exact: /productpage
- uri:
prefix: /static
- uri:
exact: /login
- uri:
exact: /logout
- uri:
prefix: /api/v1/products
route:
- destination:
host: productpage
port:
number: 9080
因為這邊我是部署到gcp上面,所以有一組外部ip,開啟http://[external_ip]/productpage後會看到部署的bookinfo網頁
下一篇來講講上面提到的一個東西VirtualService