Merge pull request #1516 from adleong/alex/linkerd

Update Linkerd tutorial to use Kubernetes Gateway API
This commit is contained in:
Stefan Prodan
2023-09-19 12:19:01 +03:00
committed by GitHub
6 changed files with 234 additions and 31 deletions
Binary file not shown.

Before

Width:  |  Height:  |  Size: 41 KiB

@@ -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 -
@@ -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
```
@@ -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:
@@ -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
@@ -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
+1 -1
View File
@@ -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
+1 -6
View File
@@ -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
@@ -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
+74 -8
View File
@@ -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
@@ -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
@@ -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
@@ -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
+79 -3
View File
@@ -4,6 +4,65 @@
set -o errexit
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
metadata:
name: latency
namespace: linkerd
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)
)
EOF
cat <<EOF | kubectl apply -f -
apiVersion: flagger.app/v1beta1
kind: Canary
@@ -20,18 +79,35 @@ 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
stepWeights: [10, 20, 30, 40, 50, 60]
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: load-test
url: http://flagger-loadtester.test/