Skip to content

Commit a517309

Browse files
authored
Merge pull request #1516 from adleong/alex/linkerd
Update Linkerd tutorial to use Kubernetes Gateway API
2 parents aaafdca + 22c96c5 commit a517309

File tree

6 files changed

+234
-31
lines changed

6 files changed

+234
-31
lines changed
-40.6 KB
Binary file not shown.

docs/gitbook/tutorials/linkerd-progressive-delivery.md

+79-13
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22

33
This guide shows you how to use Linkerd and Flagger to automate canary deployments.
44

5-
![Flagger Linkerd Traffic Split](https://raw.githubusercontent.com/fluxcd/flagger/main/docs/diagrams/flagger-linkerd-traffic-split.png)
6-
75
## Prerequisites
86

9-
Flagger requires a Kubernetes cluster **v1.16** or newer and Linkerd **2.10** or newer.
7+
Flagger requires a Kubernetes cluster **v1.21** or newer and Linkerd **2.14** or newer.
108

119
Install Linkerd and Prometheus (part of Linkerd Viz):
1210

1311
```bash
14-
# For linkerd versions 2.12 and later, the CRDs need to be installed beforehand
12+
# The CRDs need to be installed beforehand
1513
linkerd install --crds | kubectl apply -f -
1614

1715
linkerd install | kubectl apply -f -
@@ -45,14 +43,9 @@ helm install linkerd-control-plane linkerd/linkerd-control-plane \
4543

4644
helm install linkerd-viz linkerd/linkerd-viz -n linkerd-viz --create-namespace
4745

48-
helm repo add l5d-smi https://linkerd.github.io/linkerd-smi
49-
helm install linkerd-smi l5d-smi/linkerd-smi -n linkerd-smi --create-namespace
50-
51-
# Note that linkerdAuthPolicy.create=true is only required for Linkerd 2.12 and
52-
# later
5346
helm install flagger flagger/flagger \
5447
--n flagger-system \
55-
--set meshProvider=linkerd \
48+
--set meshProvider=gatewayapi:v1beta1 \
5649
--set metricsServer=http://prometheus.linkerd-viz:9090 \
5750
--set linkerdAuthPolicy.create=true
5851
```
@@ -82,9 +75,65 @@ Create a deployment and a horizontal pod autoscaler:
8275
kubectl apply -k https://github.com/fluxcd/flagger//kustomize/podinfo?ref=main
8376
```
8477

85-
Create a canary custom resource for the podinfo deployment:
78+
Create a metrics template and canary custom resources for the podinfo deployment:
8679

8780
```yaml
81+
---
82+
apiVersion: flagger.app/v1beta1
83+
kind: MetricTemplate
84+
metadata:
85+
name: success-rate
86+
namespace: test
87+
spec:
88+
provider:
89+
type: prometheus
90+
address: http://prometheus.linkerd-viz:9090
91+
query: |
92+
sum(
93+
rate(
94+
response_total{
95+
namespace="{{ namespace }}",
96+
deployment=~"{{ target }}",
97+
classification!="failure",
98+
direction="{{ variables.direction }}"
99+
}[{{ interval }}]
100+
)
101+
)
102+
/
103+
sum(
104+
rate(
105+
response_total{
106+
namespace="{{ namespace }}",
107+
deployment=~"{{ target }}",
108+
direction="{{ variables.direction }}"
109+
}[{{ interval }}]
110+
)
111+
)
112+
* 100
113+
---
114+
apiVersion: flagger.app/v1beta1
115+
kind: MetricTemplate
116+
metadata:
117+
name: latency
118+
namespace: test
119+
spec:
120+
provider:
121+
type: prometheus
122+
address: http://prometheus.linkerd-viz:9090
123+
query: |
124+
histogram_quantile(
125+
0.99,
126+
sum(
127+
rate(
128+
response_latency_ms_bucket{
129+
namespace="{{ namespace }}",
130+
deployment=~"{{ target }}",
131+
direction="{{ variables.direction }}"
132+
}[{{ interval }}]
133+
)
134+
) by (le)
135+
)
136+
---
88137
apiVersion: flagger.app/v1beta1
89138
kind: Canary
90139
metadata:
@@ -109,6 +158,13 @@ spec:
109158
port: 9898
110159
# container port number or name (optional)
111160
targetPort: 9898
161+
# Reference to the Service that the generated HTTPRoute would attach to.
162+
gatewayRefs:
163+
- name: podinfo
164+
namespace: test
165+
group: core
166+
kind: Service
167+
port: 9898
112168
analysis:
113169
# schedule interval (default 60s)
114170
interval: 30s
@@ -122,18 +178,28 @@ spec:
122178
stepWeight: 5
123179
# Linkerd Prometheus checks
124180
metrics:
125-
- name: request-success-rate
181+
- name: success-rate
182+
templateRef:
183+
name: success-rate
184+
namespace: test
126185
# minimum req success rate (non 5xx responses)
127186
# percentage (0-100)
128187
thresholdRange:
129188
min: 99
130189
interval: 1m
131-
- name: request-duration
190+
templateVariables:
191+
direction: inbound
192+
- name: latency
193+
templateRef:
194+
name: latency
195+
namespace: test
132196
# maximum req duration P99
133197
# milliseconds
134198
thresholdRange:
135199
max: 500
136200
interval: 30s
201+
templateVariables:
202+
direction: inbound
137203
# testing (optional)
138204
webhooks:
139205
- name: acceptance-test

kustomize/linkerd/patch.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ spec:
1010
args:
1111
- -log-level=info
1212
- -include-label-prefix=app.kubernetes.io
13-
- -mesh-provider=linkerd
13+
- -mesh-provider=gatewayapi:v1beta1
1414
- -metrics-server=http://prometheus.linkerd-viz:9090
1515
---
1616
apiVersion: rbac.authorization.k8s.io/v1

test/linkerd/install.sh

+1-6
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
set -o errexit
44

5-
LINKERD_VER="stable-2.13.2"
6-
LINKERD_SMI_VER="0.2.0"
5+
LINKERD_VER="stable-2.14.0"
76
REPO_ROOT=$(git rev-parse --show-toplevel)
87

98
mkdir -p ${REPO_ROOT}/bin
@@ -18,10 +17,6 @@ ${REPO_ROOT}/bin/linkerd install --crds | kubectl apply -f -
1817
${REPO_ROOT}/bin/linkerd install | kubectl apply -f -
1918
${REPO_ROOT}/bin/linkerd check
2019

21-
echo ">>> Installing Linkerd SMI"
22-
${REPO_ROOT}/bin/linkerd-smi install | kubectl apply -f -
23-
${REPO_ROOT}/bin/linkerd-smi check
24-
2520
echo ">>> Installing Linkerd Viz"
2621
${REPO_ROOT}/bin/linkerd viz install | kubectl apply -f -
2722
kubectl -n linkerd-viz rollout status deploy/prometheus

test/linkerd/test-canary.sh

+74-8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,40 @@ set -o errexit
66

77
REPO_ROOT=$(git rev-parse --show-toplevel)
88

9+
cat <<EOF | kubectl apply -f -
10+
apiVersion: flagger.app/v1beta1
11+
kind: MetricTemplate
12+
metadata:
13+
name: success-rate
14+
namespace: linkerd
15+
spec:
16+
provider:
17+
type: prometheus
18+
address: http://prometheus.linkerd-viz:9090
19+
query: |
20+
sum(
21+
rate(
22+
response_total{
23+
namespace="{{ namespace }}",
24+
deployment=~"{{ target }}",
25+
classification!="failure",
26+
direction="{{ variables.direction }}"
27+
}[{{ interval }}]
28+
)
29+
)
30+
/
31+
sum(
32+
rate(
33+
response_total{
34+
namespace="{{ namespace }}",
35+
deployment=~"{{ target }}",
36+
direction="{{ variables.direction }}"
37+
}[{{ interval }}]
38+
)
39+
)
40+
* 100
41+
EOF
42+
943
cat <<EOF | kubectl apply -f -
1044
apiVersion: flagger.app/v1beta1
1145
kind: MetricTemplate
@@ -47,18 +81,27 @@ spec:
4781
port: 80
4882
targetPort: http
4983
portDiscovery: true
84+
gatewayRefs:
85+
- name: podinfo
86+
namespace: test
87+
group: core
88+
kind: Service
89+
port: 80
5090
analysis:
5191
interval: 15s
5292
threshold: 15
5393
maxWeight: 50
5494
stepWeight: 10
5595
metrics:
56-
- name: request-success-rate
57-
threshold: 99
96+
- name: success-rate
97+
templateRef:
98+
name: success-rate
99+
namespace: linkerd
100+
thresholdRange:
101+
min: 99
58102
interval: 1m
59-
- name: request-duration
60-
threshold: 500
61-
interval: 30s
103+
templateVariables:
104+
direction: inbound
62105
- name: latency
63106
templateRef:
64107
name: latency
@@ -106,6 +149,12 @@ spec:
106149
service:
107150
port: 9898
108151
portDiscovery: true
152+
gatewayRefs:
153+
- name: podinfo
154+
namespace: test
155+
group: core
156+
kind: Service
157+
port: 9898
109158
analysis:
110159
interval: 15s
111160
threshold: 15
@@ -194,18 +243,35 @@ spec:
194243
service:
195244
port: 80
196245
targetPort: 9898
246+
gatewayRefs:
247+
- name: podinfo
248+
namespace: test
249+
group: core
250+
kind: Service
251+
port: 80
197252
analysis:
198253
interval: 15s
199254
threshold: 3
200255
maxWeight: 50
201256
stepWeight: 10
202257
metrics:
203-
- name: request-success-rate
204-
threshold: 99
258+
- name: success-rate
259+
templateRef:
260+
name: success-rate
261+
namespace: linkerd
262+
thresholdRange:
263+
min: 99
205264
interval: 1m
206-
- name: request-duration
265+
templateVariables:
266+
direction: inbound
267+
- name: latency
268+
templateRef:
269+
name: latency
270+
namespace: linkerd
207271
threshold: 500
208272
interval: 30s
273+
templateVariables:
274+
direction: inbound
209275
webhooks:
210276
- name: http-acceptance-test
211277
type: pre-rollout

0 commit comments

Comments
 (0)