将SpringBoot应用服务部署到Istio构建service-mesh, 并做一些路由实践
理论参考 https://istio.io/latest/zh/docs/concepts/traffic-management/
环境准备
docker & minikube & istio & jdk1.8 & maven
- 环境准备
- minikube安装参考 https://minikube.sigs.k8s.io/docs/start/
- istio安装参考https://istio.io/latest/zh/docs/setup/install/istioctl/
- 开启istio sidecar自动注入(将k8s default命名空间标记为 istio-injection=enabled)
kubectl label namespace default istio-injection=enabled --overwrite
- clone
git clone https://github.com/wangyy2113/spring-istio-route-demo.git
cd spring-istio-route-demo
- 启动minikube
minikube start
- start demo
sh bootstrap.sh
- 开启minikube tunnel便于外部请求访问服务
minikube tunnel
- 检查服务运行状态, READY=2/2, STATUS=Running
kubectl get pod|grep istio-route-demo
- HTTP请求路由验证
发送http请求访问gateway,gateway会将请求转发到client, client再构造HTTP请求访问server(server有两个版本server-v1 & server-v2)
curl '127.0.0.1:80/greet/http?featureTag=v2'
curl '127.0.0.1:80/greet/http?featureTag=v1'
curl '127.0.0.1:80/greet/http?featureTag=v3'
curl '127.0.0.1:80/greet/http?featureTag=v4'
- featureTag=v2的请求会打到server-v2, 其余的都会打到server-v1
- 即curl '127.0.0.1:80/greet/http?featureTag=v2' 会得到Response "Client receive Server msg: Http Greeting from server-v2"
- 其他请求会得到Response "Client receive Server msg: Http Greeting from server-v1"
- 关闭服务
sh stopall.sh
对于minikube tunnel 命令行 control + C 即可
关闭minikube
minikube stop