Skip to content

Commit b77f009

Browse files
authored
feat: new example: subset-level traffic splitting (idan-codefresh#14)
Signed-off-by: Hui Kang <[email protected]>
1 parent d40152c commit b77f009

9 files changed

+179
-0
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ The following examples are provided:
1616
| [Canary Analysis](examples/analysis) | Rollout which performs canary analysis as part of the update. Uses the prometheus metric provider. |
1717
| [Experiment](examples/experiment) | Experiment which performs an A/B test. Performs analysis against the A and B using the job metric provider |
1818
| [Preview Stack Testing](examples/preview-testing) | Rollout which launches an experiment that tests a preview stack (which receives no production traffic) |
19+
| [Canary with istio (1)](examples/istio) | Rollout which uses host-level traffic splitting during update |
20+
| [Canary with istio (2)](examples/istio-subset) | Rollout which uses subset-level traffic splitting during update |
1921

2022
Before running an example:
2123

examples/istio-subset/analysis.yaml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
apiVersion: argoproj.io/v1alpha1
2+
kind: AnalysisTemplate
3+
metadata:
4+
name: istio-success-rate
5+
spec:
6+
# this analysis template requires a service name and namespace to be supplied to the query
7+
args:
8+
- name: service
9+
- name: namespace
10+
metrics:
11+
- name: success-rate
12+
initialDelay: 60s
13+
interval: 20s
14+
successCondition: result[0] > 0.90
15+
provider:
16+
prometheus:
17+
address: http://prometheus.istio-system:9090
18+
query: >+
19+
sum(irate(istio_requests_total{
20+
reporter="source",
21+
destination_service=~"{{args.service}}.{{args.namespace}}.svc.cluster.local",
22+
response_code!~"5.*"}[40s])
23+
)
24+
/
25+
sum(irate(istio_requests_total{
26+
reporter="source",
27+
destination_service=~"{{args.service}}.{{args.namespace}}.svc.cluster.local"}[40s])
28+
)
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: networking.istio.io/v1alpha3
2+
kind: DestinationRule
3+
metadata:
4+
name: rollout-destrule
5+
spec:
6+
host: istio-rollout
7+
subsets:
8+
- name: canary # referenced in canary.trafficRouting.istio.destinationRule.canarySubsetName
9+
labels: # labels will be injected with canary rollouts-pod-template-hash value
10+
app: istio-rollout
11+
- name: stable # referenced in canary.trafficRouting.istio.destinationRule.stableSubsetName
12+
labels: # labels will be injected with canary rollouts-pod-template-hash value
13+
app: istio-rollout

examples/istio-subset/gateway.yaml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apiVersion: networking.istio.io/v1alpha3
2+
kind: Gateway
3+
metadata:
4+
name: istio-rollout-gateway
5+
spec:
6+
selector:
7+
istio: ingressgateway
8+
servers:
9+
- port:
10+
number: 80
11+
name: http
12+
protocol: HTTP
13+
hosts:
14+
- "*"
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
3+
4+
resources:
5+
- namespace.yaml
6+
- analysis.yaml
7+
- gateway.yaml
8+
- services.yaml
9+
- virtualservice.yaml
10+
- rollout.yaml
11+
- destinationrule.yaml
12+
13+
namespace: rollouts-demo-istio

examples/istio-subset/namespace.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: v1
2+
kind: Namespace
3+
metadata:
4+
labels:
5+
istio-injection: enabled
6+
name: rollouts-demo-istio

examples/istio-subset/rollout.yaml

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
apiVersion: argoproj.io/v1alpha1
2+
kind: Rollout
3+
metadata:
4+
name: istio-rollout
5+
spec:
6+
revisionHistoryLimit: 2
7+
selector:
8+
matchLabels:
9+
app: istio-rollout
10+
template:
11+
metadata:
12+
annotations:
13+
sidecar.istio.io/inject: "true"
14+
labels:
15+
app: istio-rollout
16+
spec:
17+
containers:
18+
- name: istio-rollout
19+
image: argoproj/rollouts-demo:blue
20+
ports:
21+
- name: http
22+
containerPort: 8080
23+
protocol: TCP
24+
resources:
25+
requests:
26+
memory: 32Mi
27+
cpu: 5m
28+
strategy:
29+
canary:
30+
analysis will be performed in background, while rollout is progressing through its steps
31+
analysis:
32+
startingStep: 1 # index of step list, of when to start this analysis
33+
templates:
34+
- templateName: istio-success-rate
35+
args: # arguments allow AnalysisTemplates to be re-used
36+
- name: service
37+
value: canary
38+
- name: namespace
39+
valueFrom:
40+
fieldRef:
41+
fieldPath: metadata.namespace
42+
trafficRouting:
43+
istio:
44+
virtualService:
45+
name: istio-rollout-vsvc
46+
routes:
47+
- primary
48+
destinationRule:
49+
name: rollout-destrule # required
50+
canarySubsetName: canary # required
51+
stableSubsetName: stable # required
52+
steps:
53+
- setWeight: 10
54+
- pause: {} # pause indefinitely
55+
- setWeight: 20
56+
- pause: {duration: 20s}
57+
- setWeight: 30
58+
- pause: {duration: 20s}
59+
- setWeight: 40
60+
- pause: {duration: 20s}
61+
- setWeight: 50
62+
- pause: {duration: 20s}
63+
- setWeight: 60
64+
- pause: {duration: 20s}
65+
- setWeight: 70
66+
- pause: {duration: 20s}
67+
- setWeight: 80
68+
- pause: {duration: 20s}
69+
- setWeight: 90
70+
- pause: {duration: 20s}

examples/istio-subset/services.yaml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: istio-rollout
5+
spec:
6+
ports:
7+
- port: 80
8+
targetPort: http
9+
protocol: TCP
10+
name: http
11+
selector:
12+
app: istio-rollout
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
apiVersion: networking.istio.io/v1alpha3
2+
kind: VirtualService
3+
metadata:
4+
name: istio-rollout-vsvc
5+
spec:
6+
gateways:
7+
- istio-rollout-gateway
8+
hosts:
9+
- istio-rollout.apps.argoproj.io
10+
- istio-rollout.local
11+
http:
12+
- name: primary
13+
route:
14+
- destination:
15+
host: istio-rollout
16+
subset: stable # referenced in canary.trafficRouting.istio.destinationRule.stableSubsetName
17+
weight: 100
18+
- destination:
19+
host: istio-rollout
20+
subset: canary # referenced in canary.trafficRouting.istio.destinationRule.canarySubsetName
21+
weight: 0

0 commit comments

Comments
 (0)