蓝绿部署,2个版本同事存在,新版本接替旧版本, 借助 istio 实现
kubectl -n demo-project get virtualservice -o yaml
# 这是一个 Istio 虚拟服务列表,包含 4 个服务:details、productpage、ratings 和 reviews
apiVersion: v1
items:
# 这个虚拟服务配置了 details 服务的路由规则
- apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: details
namespace: demo-project
spec:
hosts:
- details # 应用了此规则的主机
http:
- match:
- port: 9080 # 匹配端口 9080 的流量
route:
- destination:
host: details # 流量被重定向到 details 服务
subset: v1 # 流量被定向到子集 v1
weight: 100 # 100% 的流量被重定向
# 这个虚拟服务配置了 productpage 服务的路由规则
- apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: productpage
namespace: demo-project
spec:
# ...
# 这个虚拟服务配置了 ratings 服务的路由规则
- apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: ratings
namespace: demo-project
spec:
# ...
# 这个虚拟服务最初配置了 reviews 服务的路由规则,后来又更新了
- apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: reviews
namespace: demo-project
spec:
hosts:
- reviews
http:
- match:
- port: 9080
route:
- destination:
host: reviews
subset: v2 # 这次更新将流量路由到子集 v2
weight: 100