准备工作
- 部署Kubernetes 集群
- 下载istio安装包
- 部署istio
设置 Kubernetes 集群
//生成一个环境变量用于存储运行教程指令要用到的命名空间的名字。
//查看名称空间
[root@master soft]# kubectl get ns
NAME STATUS AGE
default Active 38d
kube-node-lease Active 38d
kube-public Active 38d
kube-system Active 38d
//解压
[root@master ~]# tar -xf istio-1.13.3-linux-amd64.tar.gz -C /usr/local/
[root@master istio]# mv istio-1.13.3/ istio
[root@master istio]# ls
bin LICENSE manifests manifest.yaml README.md samples tools
//添加环境变量
[root@master ~]# echo 'export PATH=/usr/local/istio/bin:$PATH' > /etc/profile.d/istio.sh
[root@master ~]# source /etc/profile.d/istio.sh
[root@master ~]# echo $PATH
/usr/local/istio/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@master istio]# istioctl install --set profile=demo -y
✔ Istio core installed
✔ Istiod installed
✔ Ingress gateways installed
✔ Egress gateways installed
✔ Installation complete Making this installation the default for injection and validation.
Thank you for installing Istio 1.13. Please take a few minutes to tell us about your install/upgrade experience! https://forms.gle/pzWZpAvMVBecaQ9h9
[root@master istio]# kubectl get ns
NAME STATUS AGE
default Active 31d
istio-system Active 46h
kube-node-lease Active 31d
kube-public Active 31d
kube-system Active 31d
[root@master istio]# kubectl describe ns default
Name: default
Labels: istio-injection=enabled
Annotations: <none>
Status: Active
No resource quota.
No LimitRange resource.
//添加一个命名空间标签,以指示 Istio 在稍后部署应用程序时自动注入 Envoy sidecar 代理
[root@master istio]# kubectl label namespace default istio-injection=enabled
namespace/default labeled
使用 Kubernetes 运行 Bookinfo
[root@master istio]# kubectl apply -f samples/bookinfo/platform/kube/bookinfo.yaml
service/details unchanged
serviceaccount/bookinfo-details unchanged
deployment.apps/details-v1 configured
service/ratings unchanged
serviceaccount/bookinfo-ratings unchanged
deployment.apps/ratings-v1 configured
service/reviews unchanged
serviceaccount/bookinfo-reviews unchanged
deployment.apps/reviews-v1 unchanged
deployment.apps/reviews-v2 configured
deployment.apps/reviews-v3 unchanged
service/productpage unchanged
serviceaccount/bookinfo-productpage unchanged
deployment.apps/productpage-v1 configured
[root@master istio]# kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
details ClusterIP 10.106.159.243 <none> 9080/TCP 3h42m
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 38d
productpage ClusterIP 10.110.8.87 <none> 9080/TCP 3h42m
ratings ClusterIP 10.111.23.61 <none> 9080/TCP 3h42m
reviews ClusterIP 10.111.16.157 <none> 9080/TCP 3h42m
[root@master istio]# kubectl get pods
NAME READY STATUS RESTARTS AGE
details-v1-79f774bdb9-n7gxp 2/2 Running 0 39s
productpage-v1-6b746f74dc-rtwpk 2/2 Running 0 39s
ratings-v1-69db447b68-nc7xg 0/2 Terminating 0 69m
ratings-v1-b6994bb9-9gbsc 2/2 Running 0 39s
reviews-v1-545db77b95-9hnzs 2/2 Running 0 3h42m
reviews-v2-7bf8c9648f-6b8h9 2/2 Running 0 39s
reviews-v3-84779c7bbc-2ljp7 2/2 Running 0 3h42
[root@master istio]# kubectl exec "$(kubectl get pod -l app=ratings -o jsonpath='{.items[0].metadata.name}')" -c ratings -- curl -s productpage:9080/productpage | grep -o "<title>.*</title>"
<title>Simple Bookstore App</title>
[root@master istio]# kubectl create namespace bookinfo
namespace/bookinfo created
[root@master istio]# kubectl apply -f samples/bookinfo/networking/bookinfo-gateway.yaml -n bookinfo
gateway.networking.istio.io/bookinfo-gateway created
virtualservice.networking.istio.io/bookinfo created
//查看 gateway
[root@master istio]# kubectl get gateway -n bookinfo
NAME AGE
bookinfo-gateway 21s
配置 Istio Ingress Gateway
执行下面命令以判断你的 Kubernetes 集群环境是否支持外部负载均衡:
[root@master istio]# kubectl get svc istio-ingressgateway -n istio-system
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
istio-ingressgateway LoadBalancer 10.108.251.167 <pending> 15021:31331/TCP,80:31258/TCP,443:30957/TCP,31400:31680/TCP,15443:30788/TCP 3m18s
设置 EXTERNAL-IP 的值之后, 你的环境就有了一个外部的负载均衡,可以用它做入站网关。 但如果 EXTERNAL-IP 的值为 (或者一直是 状态), 则你的环境则没有提供可作为入站流量网关的外部负载均衡。 在这个情况下,你还可以用服务(Service)的 节点端口 访问网关。
//修改 service type
[root@master istio]# kubectl patch service istio-ingressgateway -n istio-system -p '{"spec":{"type":"NodePort"}}'
service/istio-ingressgateway patched
[root@master istio]# kubectl get svc istio-ingressgateway -n istio-system
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
istio-ingressgateway NodePort 10.96.143.174 <none> 15021:31442/TCP,80:30895/TCP,443:31304/TCP,31400:30983/TCP,15443:32582/TCP 5h25m
//如果你的环境中没有外部负载均衡,那就选择一个节点端口来代替.
设置入站的端口:
[root@master istio]# export INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].nodePort}')
[root@master istio]# echo $INGRESS_PORT
30895
[root@master istio]# export SECURE_INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="https")].nodePort}')
[root@master istio]# echo $SECURE_INGRESS_PORT
31304
http://ip:30895/productpage
查看仪表板
//部署 Kiali 仪表板、 以及 Prometheus、 Grafana、 还有 Jaeger
[root@master istio]# kubectl apply -f samples/addons/extras/zipkin.yaml -n istio-system
[root@master istio]# kubectl apply -f samples/addons -n istio-system
[root@master istio]# kubectl apply -f samples/bookinfo/networking/destination-rule-all.yaml
[root@master istio]# kubectl get destinationrules -o yaml
[root@master istio]# kubectl rollout status deployment/kiali -n istio-system
[root@master istio]# kubectl rollout status deployment/jaeger -n istio-system
[root@master istio]# kubectl rollout status deployment/grafana -n istio-system
[root@master istio]# kubectl rollout status deployment/prometheus -n istio-system
[root@master istio]# kubectl apply -f samples/addons/extras/zipkin.yaml -n istio-system
监控 Istio
// 开启grafana
kubectl -n istio-system port-forward $(kubectl -n istio-system get pod -l app=grafana -o jsonpath='{.items[0].metadata.name}') --address 0.0.0.0 3000:3000 &
// 开启zipkin
kubectl -n istio-system port-forward $(kubectl -n istio-system get pod -l app=zipkin -o jsonpath='{.items[0].metadata.name}') --address 0.0.0.0 9411:9411 &
// 开启jaeger
kubectl -n istio-system port-forward $(kubectl -n istio-system get pod -l app=jaeger -o jsonpath='{.items[0].metadata.name}') --address 0.0.0.0 16686:16686 &
//开启kiali
kubectl -n istio-system port-forward $(kubectl -n istio-system get pod -l app=kiali -o jsonpath='{.items[0].metadata.name}') --address 0.0.0.0 20001:20001 &
//开启prometheus
kubectl -n istio-system port-forward $(kubectl -n istio-system get pod -l app=prometheus -o jsonpath='{.items[0].metadata.name}') --address 0.0.0.0 9090:9090 &
[root@master istio]# kubectl get pods -n istio-system
NAME READY STATUS RESTARTS AGE
grafana-69ccf87b97-9msqb 1/1 Running 0 3h51m
istio-egressgateway-5f686bbdfd-t54dh 1/1 Running 0 5h47m
istio-ingressgateway-699d557cd4-tpxcp 1/1 Running 0 5h47m
istiod-5458bd7bc4-4tmts 1/1 Running 0 5h52m
jaeger-648f4f4ddb-27sg9 1/1 Running 0 3h51m
kiali-5ccffdfd97-mwt9d 1/1 Running 0 3h51m
prometheus-f675ff955-zkk9v 2/2 Running 0 3h51m
zipkin-667774848b-7fdxx 1/1 Running 0 140m
[root@master istio]# kubectl get svc -n istio-system
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
grafana ClusterIP 10.99.6.126 <none> 3000/TCP 3h54m
istio-egressgateway ClusterIP 10.101.10.31 <none> 80/TCP,443/TCP 5h50m
istio-ingressgateway NodePort 10.96.143.174 <none> 15021:31442/TCP,80:30895/TCP,443:31304/TCP,31400:30983/TCP,15443:32582/TCP 5h50m
istiod ClusterIP 10.97.144.129 <none> 15010/TCP,15012/TCP,443/TCP,15014/TCP 5h55m
jaeger-collector ClusterIP 10.98.36.111 <none> 14268/TCP,14250/TCP,9411/TCP 3h54m
kiali ClusterIP 10.101.222.50 <none> 20001/TCP,9090/TCP 3h54m
prometheus ClusterIP 10.99.92.229 <none> 9090/TCP 3h54m
tracing ClusterIP 10.96.31.163 <none> 80/TCP 3h54m
zipkin ClusterIP 10.99.171.31 <none> 9411/TCP
在一个单独的终端窗口中设置无限循环,将流量发送到您的应用程序,以模拟现实世界中恒定的用户流量:
[root@master istio]# while :; do curl -s 192.168.129.136:30895/productpage | grep -o "<title>.*</title>"; sleep 1; done<title>Simple Bookstore App</title>
<title>Simple Bookstore App</title>
<title>Simple Bookstore App</title>
<title>Simple Bookstore App</title>
<title>Simple Bookstore App</title>
<title>Simple Bookstore App</title>
在 Kiali 控制台 my-kiali.io/kiali/console 通过 Graph 检查您的命名空
在所有微服务中启用 Istio
http://ip:3000/
http://IP:9411/
http://IP:20001/
在页面上操作
//查询命名空间的所有请求
istio_requests_total{destination_service_namespace="default", reporter="destination",destination_service_name="reviews"}
//查询命名空间请求的总和:
sum(istio_requests_total{destination_service_namespace="default", reporter="destination"})
//查询 reviews 微服务的请求:
istio_requests_total{destination_service_namespace="default", reporter="destination",destination_service_name="reviews"}
//在过去5分钟内, reviews 微服务实例中的所有请求的请求速率:
rate(istio_requests_total{destination_service_namespace="default", reporter="destination",destination_service_name="reviews"}[5m])
http://IP:9090/