⚡️:在上篇文章中提到了
Istio
实现灰度发布的原理,也提到了Desctination
的重要性,这篇我们结合统一网关来指定服务灰度发布的方案.
现在我们知道了,Istio灰度无非就是制定好 VirtualService和DestinationRule 规则
,来进行流量管理,那么,我们在对center—gatewaysvr 服务进行小部分调整即可实现。
Center-Gatewaysvr
我们查看下Helm 中VirtualService模板,可以看到,我们这里也新增了对服务灰度的开关。
---
{{- define "http-routes" -}}
{{- range $route := .Values.routes }}
{{- range $preferTag := $route.preferTag }}
- match:
- headers:
x-asm-prefer-tag:
exact: {{ $preferTag }}
uri:
prefix: /gstrain
ignoreUriCase: true
rewrite:
uri: /{{ $preferTag }}
route:
- destination:
host: {{ $route.destination.host }}
port:
number: {{ $route.destination.port }}
subset: {{ $route.destination.host }}
{{- if $route.canary.enabled }}
weight: {{ $route.canary.stable.weight | default 100 }}
- destination:
host: {{ $route.destination.host }}
port:
number: {{ $route.destination.port }}
subset: {{ $route.destination.host }}-canary
weight: {{ $route.canary.canary.weight | default 0 }}
{{- end}}
{{- end}}
{{- end}}
{{- end}}
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: {{ include "center-gatewaysvc.fullname" . }}
labels:
{{- include "center-gatewaysvc.labels" . | nindent 4 }}
spec:
gateways:
- {{ include "center-gatewaysvc.fullname" . }}
hosts:
{{- toYaml .Values.gateway.hostnames | nindent 4 }}
http:
{{- template "http-routes" . }}
这样做呢,和我们之前不同的是,我们把整个服务的Vs整合在一个下面,方便管理与配置
Value
先看来看渲染值,灰度调整好之后,我们只需要调整开关。
route:
## Values for mobilesvr
- preferTag:
- AcctInfo
- CacheStore
- CacheGet
destination:
host: ycloud
port: 8080
canary:
enabled: false
stable:
weight: 80
canary:
weight: 20