Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Linkerd tutorial to use Kubernetes Gateway API #1516

Merged
merged 5 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed docs/diagrams/flagger-linkerd-traffic-split.png
Binary file not shown.
92 changes: 79 additions & 13 deletions docs/gitbook/tutorials/linkerd-progressive-delivery.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@

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

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

## Prerequisites

Flagger requires a Kubernetes cluster **v1.16** or newer and Linkerd **2.10** or newer.
Flagger requires a Kubernetes cluster **v1.21** or newer and Linkerd **2.14** or newer.

Install Linkerd and Prometheus (part of Linkerd Viz):

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

linkerd install | kubectl apply -f -
Expand Down Expand Up @@ -45,14 +43,9 @@ helm install linkerd-control-plane linkerd/linkerd-control-plane \

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

helm repo add l5d-smi https://linkerd.github.io/linkerd-smi
helm install linkerd-smi l5d-smi/linkerd-smi -n linkerd-smi --create-namespace

# Note that linkerdAuthPolicy.create=true is only required for Linkerd 2.12 and
# later
helm install flagger flagger/flagger \
--n flagger-system \
--set meshProvider=linkerd \
--set meshProvider=gatewayapi:v1beta1 \
--set metricsServer=http://prometheus.linkerd-viz:9090 \
--set linkerdAuthPolicy.create=true
```
Expand Down Expand Up @@ -82,9 +75,65 @@ Create a deployment and a horizontal pod autoscaler:
kubectl apply -k https://github.com/fluxcd/flagger//kustomize/podinfo?ref=main
```

Create a canary custom resource for the podinfo deployment:
Create a metrics template and canary custom resources for the podinfo deployment:

```yaml
---
apiVersion: flagger.app/v1beta1
kind: MetricTemplate
metadata:
name: success-rate
namespace: test
spec:
provider:
type: prometheus
address: http://prometheus.linkerd-viz:9090
query: |
sum(
rate(
response_total{
namespace="{{ namespace }}",
deployment=~"{{ target }}",
classification!="failure",
direction="{{ variables.direction }}"
}[{{ interval }}]
)
)
/
sum(
rate(
response_total{
namespace="{{ namespace }}",
deployment=~"{{ target }}",
direction="{{ variables.direction }}"
}[{{ interval }}]
)
)
* 100
---
apiVersion: flagger.app/v1beta1
kind: MetricTemplate
metadata:
name: latency
namespace: test
spec:
provider:
type: prometheus
address: http://prometheus.linkerd-viz:9090
query: |
histogram_quantile(
0.99,
sum(
rate(
response_latency_ms_bucket{
namespace="{{ namespace }}",
deployment=~"{{ target }}",
direction="{{ variables.direction }}"
}[{{ interval }}]
)
) by (le)
)
---
apiVersion: flagger.app/v1beta1
kind: Canary
metadata:
Expand All @@ -109,6 +158,13 @@ spec:
port: 9898
# container port number or name (optional)
targetPort: 9898
# Reference to the Service that the generated HTTPRoute would attach to.
gatewayRefs:
- name: podinfo
namespace: test
group: core
kind: Service
port: 9898
analysis:
# schedule interval (default 60s)
interval: 30s
Expand All @@ -122,18 +178,28 @@ spec:
stepWeight: 5
# Linkerd Prometheus checks
metrics:
- name: request-success-rate
- name: success-rate
templateRef:
name: success-rate
namespace: test
# minimum req success rate (non 5xx responses)
# percentage (0-100)
thresholdRange:
min: 99
interval: 1m
- name: request-duration
templateVariables:
direction: inbound
- name: latency
templateRef:
name: latency
namespace: test
# maximum req duration P99
# milliseconds
thresholdRange:
max: 500
interval: 30s
templateVariables:
direction: inbound
# testing (optional)
webhooks:
- name: acceptance-test
Expand Down
2 changes: 1 addition & 1 deletion kustomize/linkerd/patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ spec:
args:
- -log-level=info
- -include-label-prefix=app.kubernetes.io
- -mesh-provider=linkerd
- -mesh-provider=gatewayapi:v1beta1
- -metrics-server=http://prometheus.linkerd-viz:9090
---
apiVersion: rbac.authorization.k8s.io/v1
Expand Down
7 changes: 1 addition & 6 deletions test/linkerd/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

set -o errexit

LINKERD_VER="stable-2.13.2"
LINKERD_SMI_VER="0.2.0"
LINKERD_VER="stable-2.14.0"
REPO_ROOT=$(git rev-parse --show-toplevel)

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

echo ">>> Installing Linkerd SMI"
${REPO_ROOT}/bin/linkerd-smi install | kubectl apply -f -
${REPO_ROOT}/bin/linkerd-smi check

echo ">>> Installing Linkerd Viz"
${REPO_ROOT}/bin/linkerd viz install | kubectl apply -f -
kubectl -n linkerd-viz rollout status deploy/prometheus
Expand Down
82 changes: 74 additions & 8 deletions test/linkerd/test-canary.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,40 @@ set -o errexit

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

cat <<EOF | kubectl apply -f -
apiVersion: flagger.app/v1beta1
kind: MetricTemplate
metadata:
name: success-rate
namespace: linkerd
spec:
provider:
type: prometheus
address: http://prometheus.linkerd-viz:9090
query: |
sum(
rate(
response_total{
namespace="{{ namespace }}",
deployment=~"{{ target }}",
classification!="failure",
direction="{{ variables.direction }}"
}[{{ interval }}]
)
)
/
sum(
rate(
response_total{
namespace="{{ namespace }}",
deployment=~"{{ target }}",
direction="{{ variables.direction }}"
}[{{ interval }}]
)
)
* 100
EOF

cat <<EOF | kubectl apply -f -
apiVersion: flagger.app/v1beta1
kind: MetricTemplate
Expand Down Expand Up @@ -47,18 +81,27 @@ spec:
port: 80
targetPort: http
portDiscovery: true
gatewayRefs:
- name: podinfo
namespace: test
group: core
kind: Service
port: 80
analysis:
interval: 15s
threshold: 15
maxWeight: 50
stepWeight: 10
metrics:
- name: request-success-rate
threshold: 99
- name: success-rate
templateRef:
name: success-rate
namespace: linkerd
thresholdRange:
min: 99
interval: 1m
- name: request-duration
threshold: 500
interval: 30s
templateVariables:
direction: inbound
- name: latency
templateRef:
name: latency
Expand Down Expand Up @@ -106,6 +149,12 @@ spec:
service:
port: 9898
portDiscovery: true
gatewayRefs:
- name: podinfo
namespace: test
group: core
kind: Service
port: 9898
analysis:
interval: 15s
threshold: 15
Expand Down Expand Up @@ -194,18 +243,35 @@ spec:
service:
port: 80
targetPort: 9898
gatewayRefs:
- name: podinfo
namespace: test
group: core
kind: Service
port: 80
analysis:
interval: 15s
threshold: 3
maxWeight: 50
stepWeight: 10
metrics:
- name: request-success-rate
threshold: 99
- name: success-rate
templateRef:
name: success-rate
namespace: linkerd
thresholdRange:
min: 99
interval: 1m
- name: request-duration
templateVariables:
direction: inbound
- name: latency
templateRef:
name: latency
namespace: linkerd
threshold: 500
interval: 30s
templateVariables:
direction: inbound
webhooks:
- name: http-acceptance-test
type: pre-rollout
Expand Down
Loading