根据官方文档的翻译,这一章叫基于主机的灰度发布,但是我们都是部署再k8s里的,光是看配置,就是切换svc 来实现的灰度废话不多说,上配置


注意看strategy 中的canary 字段,是基于svc的,这段可以直接拿来用,至于后面的流量控制策略,根据自己需要订制

apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
name: rollouts-demo
spec:
replicas: 1
strategy:
canary:
canaryService: rollouts-demo-canary
stableService: rollouts-demo-stable
trafficRouting:
istio:
virtualServices:
- name: rollout-vsvc # At least one virtualService is required
routes:
- primary # At least one route is required
# - name: rollouts-demo-vsvc2
# routes:
# - secondary # At least one route is required
steps:
- setWeight: 5
- pause:
duration: 10m
revisionHistoryLimit: 2
selector:
matchLabels:
app: rollouts-demo
template:
metadata:
labels:
app: rollouts-demo
istio-injection: enabled
spec:
containers:
- name: rollouts-demo
image: argoproj/rollouts-demo:blue
ports:
- name: http
containerPort: 8080
protocol: TCP
resources:
requests:
memory: 32Mi
cpu: 5m
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: rollout-vsvc
spec:
gateways:
- rollouts-demo-gateway
hosts:
- rollouts.test.com
http:
- name: primary # referenced in canary.trafficRouting.istio.virtualService.routes
route:
- destination:
host: rollouts-demo-stable # referenced in canary.stableService
weight: 100
- destination:
host: rollouts-demo-canary # referenced in canary.canaryService
weight: 0
---
apiVersion: v1
kind: Service
metadata:
name: rollouts-demo-canary
spec:
ports:
- port: 80
targetPort: http
protocol: TCP
name: http
selector:
app: rollouts-demo
# This selector will be updated with the pod-template-hash of the canary ReplicaSet. e.g.:
# rollouts-pod-template-hash: 7bf84f9696
---
apiVersion: v1
kind: Service
metadata:
name: rollouts-demo-stable
spec:
ports:
- port: 80
targetPort: http
protocol: TCP
name: http
selector:
app: rollouts-demo