来自AI助手的总结
Istio流量全部发往v2并镜像到v1,验证日志可见双版本访问

一、将流量全部发往forecast-v2,而不发往forecast-v1
[root@master01 ~]# cd /root/cloud-native-istio/10_canary-release/10.2
[root@master01 10.2]# kaf vs-forecast-weight-based-v2.yaml
vs策略
[root@master01 10.2]# kubectl -n weather get vs forecast-route -o yaml
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"networking.istio.io/v1alpha3","kind":"VirtualService","metadata":{"annotations":{},"name":"forecast-route","namespace":"weather"},"spec":{"hosts":["forecast"],"http":[{"route":[{"destination":{"host":"forecast","subset":"v1"},"weight":0},{"destination":{"host":"forecast","subset":"v2"},"weight":100}]}]}}
creationTimestamp: "2023-11-09T01:59:22Z"
generation: 7
name: forecast-route
namespace: weather
resourceVersion: "1225544"
uid: 37e35b32-7449-4c5f-832a-178fe1a55583
spec:
hosts:
- forecast
http:
- route:
- destination:
host: forecast
subset: v1
weight: 0
- destination:
host: forecast
subset: v2
weight: 100
二、在生效策略之前,我们先做个测试
- 2.1 浏览器访问http://192.168.1.60:3000/dashboard,点击查询天气
2.1 查询frontend示例的istio-proxy日志,观察到只有到forecast-v2的日志
[root@master01 ~]# kubectl -n weather logs `kubectl -n weather get po |grep frontend-v1|awk '{print $1}'` -c istio-proxy |grep '/weather'
[2023-11-11T02:52:51.492Z] "HEAD /weather?locate=hangzhou HTTP/1.1" 200 - via_upstream - "-" 0 0 48 48 "-" "curl/7.52.1" "ce335861-1759-9f74-a029-14b5867fa41a" "forecast:3002" "172.20.59.216:3002" outbound|3002|v2|forecast.weather.svc.cluster.local 172.21.231.181:53720 10.0.80.175:3002 172.21.231.181:52340 - -
[2023-11-11T02:54:22.275Z] "HEAD /weather?locate=hangzhou HTTP/1.1" 504 UT response_timeout - "-" 0 0 1000 - "-" "curl/7.52.1" "048762a0-f045-9d0c-8178-2675ac204600" "forecast:3002" "172.20.59.216:3002" outbound|3002|v2|forecast.weather.svc.cluster.local 172.21.231.181:53720 10.0.80.175:3002 172.21.231.181:53304 - -
[2023-11-11T02:58:39.187Z] "HEAD /weather?locate=hangzhou HTTP/1.1" 503 URX via_upstream - "-" 0 0 372 372 "-" "curl/7.52.1" "351aabaf-b56b-9ec3-b45f-3b759b044ed9" "forecast:3002" "172.20.59.216:3002" outbound|3002|v2|forecast.weather.svc.cluster.local 172.21.231.181:57404 10.0.80.175:3002 172.21.231.181:56024 - -
2.2 同时也可以查看forecast-v1以及forecast-v2的istio-proxy日志,可以根据时间来判定
[root@master01 ~]# kubectl -n weather logs `kubectl -n weather get po |grep forecast-v1|awk '{print $1}'` -c istio-proxy |grep '/weather'
[root@master01 ~]# kubectl -n weather logs `kubectl -n weather get po |grep forecast-v2|awk '{print $1}'` -c istio-proxy |grep '/weather'
三、下面配置镜像策略
[root@master01 ~]# cd /root/cloud-native-istio/11_traffic-management/11.14
[root@master01 11.14]# kaf vs-forecast-mirroring.yaml
查看策略
[root@master01 11.14]# kubectl -n weather get vs forecast-route -o yaml
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"networking.istio.io/v1alpha3","kind":"VirtualService","metadata":{"annotations":{},"name":"forecast-route","namespace":"weather"},"spec":{"hosts":["forecast"],"http":[{"route":[{"destination":{"host":"forecast","subset":"v1"},"weight":0},{"destination":{"host":"forecast","subset":"v2"},"weight":100}]}]}}
creationTimestamp: "2023-11-09T01:59:22Z"
generation: 7
name: forecast-route
namespace: weather
resourceVersion: "1225544"
uid: 37e35b32-7449-4c5f-832a-178fe1a55583
spec:
hosts:
- forecast
http:
- route:
- destination:
host: forecast
subset: v1
weight: 0
- destination:
host: forecast
subset: v2
weight: 100
说明:
该策略,会将流量都发送到v2(weight: 100),然后会镜像一份到v1。
四、测试
- 4.1 浏览器继续访问http://192.168.1.60:3000/dashboard,点击查询天气
4.1 查询frontend示例的istio-proxy日志,观察到只有v2的日志
[root@master01 11.14]# kubectl -n weather logs `kubectl -n weather get po |grep frontend-v1|awk '{print $1}'` -c istio-proxy |grep '/weather'
[2023-11-11T02:52:51.492Z] "HEAD /weather?locate=hangzhou HTTP/1.1" 200 - via_upstream - "-" 0 0 48 48 "-" "curl/7.52.1" "ce335861-1759-9f74-a029-14b5867fa41a" "forecast:3002" "172.20.59.216:3002" outbound|3002|v2|forecast.weather.svc.cluster.local 172.21.231.181:53720 10.0.80.175:3002 172.21.231.181:52340 - -
[2023-11-11T02:54:22.275Z] "HEAD /weather?locate=hangzhou HTTP/1.1" 504 UT response_timeout - "-" 0 0 1000 - "-" "curl/7.52.1" "048762a0-f045-9d0c-8178-2675ac204600" "forecast:3002" "172.20.59.216:3002" outbound|3002|v2|forecast.weather.svc.cluster.local 172.21.231.181:53720 10.0.80.175:3002 172.21.231.181:53304 - -
[2023-11-11T02:58:39.187Z] "HEAD /weather?locate=hangzhou HTTP/1.1" 503 URX via_upstream - "-" 0 0 372 372 "-" "curl/7.52.1" "351aabaf-b56b-9ec3-b45f-3b759b044ed9" "forecast:3002" "172.20.59.216:3002" outbound|3002|v2|forecast.weather.svc.cluster.local 172.21.231.181:57404 10.0.80.175:3002 172.21.231.181:56024 - -
4.2 再去查看两个forecast-v1以及forecast-v2的istio-proxy日志,会发现两个版本里都有访问日志
[root@master01 11.14]# kubectl -n weather logs `kubectl -n weather get po |grep forecast-v1|awk '{print $1}'` -c istio-proxy |grep '/weather'
[root@master01 11.14]# kubectl -n weather logs `kubectl -n weather get po |grep forecast-v2|awk '{print $1}'` -c istio-proxy |grep '/weather'
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END







暂无评论内容