一走敌、Istio / 入門 - 部署示例應用
部署yml文件在孝,位于istio目錄的samples目錄下寒矿。如
C:\Program Install\istio-1.10.3\samples
个扰。
1. 部署B(yǎng)ooking
kubectl apply -f samples/bookinfo/platform/kube/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
2. 查看創(chuàng)建的資源
#kubectl get pods
NAME READY STATUS RESTARTS AGE
details-v1-79f774bdb9-5wft6 2/2 Running 0 4m6s
productpage-v1-6b746f74dc-9xx25 2/2 Running 0 4m6s
ratings-v1-b6994bb9-jn58f 1/2 Running 0 4m6s
reviews-v1-545db77b95-dm4bz 2/2 Running 0 4m6s
reviews-v2-7bf8c9648f-hsgwr 2/2 Running 0 4m6s
reviews-v3-84779c7bbc-bhq66 2/2 Running 0 4m6s
#kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
details ClusterIP 10.101.66.249 <none> 9080/TCP 4m10s
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 6h4m
productpage ClusterIP 10.111.50.235 <none> 9080/TCP 4m9s
ratings ClusterIP 10.110.48.219 <none> 9080/TCP 4m10s
reviews ClusterIP 10.100.11.29 <none> 9080/TCP 4m10s
#kubectl get ingress
No resources found in default namespace.
#kubectl get sidecars
No resources found in default namespace.
驗證
kubectl exec ratings-v1-b6994bb9-jn58f -c ratings -- curl -s productpage:9080/productpage
二打月、Istio / 入門 對外發(fā)布
此時,BookInfo 應用已經(jīng)部署,但還不能被外界訪問碎税。 要開放訪問柏副,需要創(chuàng)建 Istio 入站網(wǎng)關(guān)(Ingress Gateway), 它會在網(wǎng)格邊緣把一個路徑映射到路由。
- 關(guān)聯(lián)應用到Ingress Gateway
#kubectl apply -f samples/bookinfo/networking/bookinfo-gateway.yaml
gateway.networking.istio.io/bookinfo-gateway created
virtualservice.networking.istio.io/bookinfo created
#kubectl get gateway -n default
NAME AGE
bookinfo-gateway 2m46s
#kubectl get vs -n default
NAME GATEWAYS HOSTS AGE
bookinfo ["bookinfo-gateway"] ["*"] 2m55s
- 確保配置文件正確
#istioctl analyze
? No validation issues found when analyzing namespace: default.
三蚣录、Istio / 入門 配置ingress地址和端口
- 對于運行于本地環(huán)境的Kubernetes割择,如minikube:
環(huán)境變量 | 值 | 說明 |
---|---|---|
INGRESS_HOST | 本地IP |
|
INGRESS_PORT | kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].nodePort}' |
windows用單引號,linux用雙引號 |
SECURE_INGRESS_PORT | kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=='https')].nodePort}' |
windows用單引號萎河,linux用雙引號 |
GATEWAY_URL | $INGRESS_HOST:$INGRESS_PORT |
#kubectl -n istio-system get service istio-ingressgateway
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
istio-ingressgateway LoadBalancer 10.110.185.80 localhost 15021:30776/TCP,80:32338/TCP,443:32623/TCP,31400:31980/TCP,15443:31490/TCP 88m
#kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=='http2')]}'
'{"name":"http2","nodePort":32338,"port":80,"protocol":"TCP","targetPort":8080}'
#kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=='http2')].nodePort}'
'32338'
#kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=='https')]}'
'{"name":"https","nodePort":32623,"port":443,"protocol":"TCP","targetPort":8443}'
#kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=='https')].nodePort}'
'32623'
- 對于正經(jīng)Kubernetes集群
執(zhí)行如下荔泳,看是否支持外部負載均衡。范例:
kubectl get svc istio-ingressgateway -n istio-system
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
istio-ingressgateway LoadBalancer 172.21.109.129 130.211.10.121 80:31380/TCP,443:31390/TCP,31400:31400/TCP 17h
如果 EXTERNAL-IP
存在值虐杯,那么就存在外部負載均衡可用于ingress gateway玛歌。 EXTERNAL-IP
值為 <none>
(or <pending>
),那就不存在外部負載均衡擎椰。這時支子,可以通過 node port訪問gateway(如上例)。
環(huán)境變量 | 值 | 說明 |
---|---|---|
INGRESS_HOST | kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.status.loadBalancer.ingress[0].ip}' |
|
INGRESS_PORT | kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].port}' |
nodePort改port |
SECURE_INGRESS_PORT | kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=='https')].port}' |
nodePort改port |
GATEWAY_URL | $INGRESS_HOST:$INGRESS_PORT |
- 外部訪問測試
Istio Bookinfo 示例包含四個獨立的微服務达舒,每個微服務都有多個版本值朋。其中一個微服務reviews
的三個不同版本已經(jīng)部署并同時運行。在瀏覽器中訪問 Bookinfo 應用程序的/productpage
并刷新幾次巩搏。您會注意到昨登,有時書評的輸出包含星級評分,有時則不包含贯底。
四丰辣、Istio / 入門 Dashboard
部署 Kiali 儀表板、 以及 Prometheus禽捆、 Grafana笙什、 還有 Jaeger
部署
#kubectl apply -f samples/addons
#kubectl get svc -n istio-system
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
grafana ClusterIP 10.109.68.9 <none> 3000/TCP 2m58s
istio-egressgateway ClusterIP 10.100.39.94 <none> 80/TCP,443/TCP 116m
istio-ingressgateway LoadBalancer 10.110.185.80 localhost 15021:30776/TCP,80:32338/TCP,443:32623/TCP,31400:31980/TCP,15443:31490/TCP 116m
istiod ClusterIP 10.103.228.126 <none> 15010/TCP,15012/TCP,443/TCP,15014/TCP 116m
jaeger-collector ClusterIP 10.109.202.41 <none> 14268/TCP,14250/TCP 2m56s
kiali ClusterIP 10.107.0.209 <none> 20001/TCP,9090/TCP 2m55s
prometheus ClusterIP 10.109.39.193 <none> 9090/TCP 2m54s
tracing ClusterIP 10.108.251.51 <none> 80/TCP 2m57s
zipkin ClusterIP 10.103.210.61 <none> 9411/TCP 2m56s
#kubectl get pods -n istio-system
NAME READY STATUS RESTARTS AGE
grafana-56d978ff77-24znt 1/1 Running 0 3m9s
istio-egressgateway-5547fcc8fc-dkfk2 1/1 Running 0 116m
istio-ingressgateway-8f568d595-ttbfg 1/1 Running 0 116m
istiod-5c79cf75bf-d67vk 1/1 Running 0 76m
jaeger-5c7c5c8d87-lh8vn 1/1 Running 0 3m9s
kiali-5bb9c9cf49-5xjxf 1/1 Running 0 3m7s
prometheus-5546cc5d8f-txz4x 3/3 Running 0 3m5s
kubectl rollout status deployment/kiali -n istio-system
deployment "kiali" successfully rolled out
查看dashboard,會自動打開一個頁面
C:\Program Install\istio-1.10.3>istioctl dashboard kiali
http://localhost:20001/kiali