目录
istio
部署
部署示例应用
部署遥测组件
流量管理
熔断
官网:https://istio.io/latest/zh/about/service-mesh/
访问应用:http://192.168.81.106/productpage
访问kiali:http://192.168.56.100:20001/
将所有流量路由到每个微服务的 v1 版本
[root@k8s2 istio-1.19.3]# kubectl apply -f samples/bookinfo/networking/destination-rule-all.yaml
[root@k8s2 istio-1.19.3]# kubectl apply -f samples/bookinfo/networking/virtual-service-all-v1.yaml
来自名为 Jason 的用户的所有流量将被路由到服务 reviews:v2
[root@k8s2 istio-1.19.3]# kubectl apply -f samples/bookinfo/networking/virtual-service-reviews-test-v2.yaml
创建故障注入规则以延迟来自测试用户 jason 的流量
kubectl apply -f samples/bookinfo/networking/virtual-service-ratings-test-delay.yaml
设置流量转移,将所有流量转移到 reviews:v3
[root@k8s2 istio-1.19.3]# vim samples/bookinfo/networking/virtual-service-reviews-test-v2.yaml
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: reviews
spec:
hosts:
- reviews
http:
- match:
- headers:
end-user:
exact: jason
route:
- destination:
host: reviews
subset: v3
- route:
- destination:
host: reviews
subset: v1
[root@k8s2 istio-1.19.3]# kubectl apply -f samples/bookinfo/networking/virtual-service-reviews-test-v2.yaml
修改延迟规则为任何低于 2.5 秒的数值,例如 2 秒
[root@k8s2 istio-1.19.3]# vim samples/bookinfo/networking/virtual-service-ratings-test-delay.yaml
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: ratings
spec:
hosts:
- ratings
http:
- match:
- headers:
end-user:
exact: jason
fault:
delay:
percentage:
value: 100.0
fixedDelay: 2s
route:
- destination:
host: ratings
subset: v1
- route:
- destination:
host: ratings
subset: v1
[root@k8s2 istio-1.19.3]# kubectl apply -f samples/bookinfo/networking/virtual-service-ratings-test-delay.yaml
把 50% 的流量从 reviews:v1 转移到 reviews:v3
[root@k8s2 istio-1.19.3]# kubectl apply -f samples/bookinfo/networking/virtual-service-reviews-50-v3.yaml
当reviews:v3 微服务已经稳定,可以通过应用 Virtual Service 规则将 100% 的流量路由 reviews:v3:
[root@k8s2 istio-1.19.3]# kubectl apply -f samples/bookinfo/networking/virtual-service-reviews-v3.yaml
清理
[root@k8s2 istio-1.19.3]# samples/bookinfo/platform/kube/cleanup.sh
部署 httpbin 服务
[root@k8s2 istio-1.19.3]# kubectl apply -f samples/httpbin/httpbin.yaml
配置熔断规则
[root@k8s2 istio-1.19.3]# kubectl apply -f - <
增加一个客户端
[root@k8s2 istio-1.19.3]# kubectl apply -f samples/httpbin/sample-client/fortio-deploy.yaml
登入客户端 Pod 并使用 Fortio 工具调用 httpbin 服务
[root@k8s2 istio-1.19.3]# export FORTIO_POD=$(kubectl get pods -l app=fortio -o 'jsonpath={.items[0].metadata.name}')
[root@k8s2 istio-1.19.3]# kubectl exec "$FORTIO_POD" -c fortio -- /usr/bin/fortio curl -quiet http://httpbin:8000/get
发送并发数为 2 的连接(-c 2),请求 20 次(-n 20)
[root@k8s2 istio-1.19.3]# kubectl exec "$FORTIO_POD" -c fortio -- /usr/bin/fortio load -c 2 -qps 0 -n 20 -loglevel Warning http://httpbin:8000/get
将并发连接数提高到 3 个
[root@k8s2 istio-1.19.3]# kubectl exec "$FORTIO_POD" -c fortio -- /usr/bin/fortio load -c 3 -qps 0 -n 30 -loglevel Warning http://httpbin:8000/get
清理
kubectl delete destinationrule httpbin
kubectl delete -f samples/httpbin/sample-client/fortio-deploy.yaml
kubectl delete -f samples/httpbin/httpbin.yaml
卸载istio
istioctl uninstall -y --purge
kubectl label namespace default istio-injection-