根據(jù)官方文檔的翻譯,這一章叫基于主機的灰度發(fā)布,但是我們都是部署再k8s里的,光是看配置,就是切換svc 來實現(xiàn)的灰度廢話不多說,上配置


注意看strategy 中的canary 字段,是基于svc的,這段可以直接拿來用,至于后面的流量控制策略,根據(jù)自己需要訂制

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