Progressive Delivery: How To Implement Flagger with Istio

What will be discussed:

Versions:

Progressive Delivery

What is the added value of Flagger

Flagger’s Deployment Strategies:

Demo Canary Release: How To Implement Flagger with Istio

$ helm repo add flagger https://flagger.app
$ kubectl apply -f https://raw.githubusercontent.com/fluxcd/flagger/main/artifacts/flagger/crd.yamlcustomresourcedefinition.apiextensions.k8s.io "canaries.flagger.app" created
customresourcedefinition.apiextensions.k8s.io "metrictemplates.flagger.app" created
customresourcedefinition.apiextensions.k8s.io "alertproviders.flagger.app" created
$ helm repo add istio https://istio-release.storage.googleapis.com/charts
$ helm repo update
$ kubectl create namespace istio-system
$ helm install istio-base istio/base -n istio-system
$ helm install istiod istio/istiod -n istio-system --wait
$ kubectl create namespace istio-ingress
$ kubectl label namespace istio-ingress istio-injection=enabled
$ helm install istio-ingress istio/gateway -n istio-ingress --wait
$ kubectl apply -f https://raw.githubusercontent.com/istio/istio/release-1.12/samples/addons/prometheus.yaml
$ helm upgrade -i flagger flagger/flagger --namespace=istio-system --set crd.create=false --set meshProvider=istio --set metricsServer=http://prometheus.istio-system:9090
$ kubectl create ns test
$ kubectl label namespace test istio-injection=enabled
$ kubectl apply -k https://github.com/fluxcd/flagger//kustomize/podinfo?ref=main
$ kubectl apply -k https://github.com/fluxcd/flagger//kustomize/tester?ref=main
apiVersion: flagger.app/v1beta1
kind: MetricTemplate
metadata:
name: error-rate
namespace: istio-system
spec:
provider:
address: http://prometheus.istio-system.svc.cluster.local:9090
type: prometheus
query: |
100 -
(sum(rate(istio_requests_total{destination_service="podinfo-canary.test.svc.cluster.local", response_code=~"5.*"}[30s]))
/
sum(rate(istio_requests_total{destination_service="podinfo-canary.test.svc.cluster.local"}[30s]))
* 100
)
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
name: podinfo
namespace: test
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: podinfo
minReplicas: 2
maxReplicas: 4
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
# scale up if usage is above
# 99% of the requested CPU (100m)
averageUtilization: 99
kind: Canary
metadata:
name: podinfo
namespace: test
spec:
# deployment reference
targetRef:
apiVersion: apps/v1
kind: Deployment
name: podinfo
service:
# service port number
port: 9898
# Istio traffic policy (optional)
trafficPolicy:
tls:
# use ISTIO_MUTUAL when mTLS is enabled
mode: DISABLE
analysis:
# schedule interval (default 60s)
interval: 10s
# max number of failed metric checks before rollback
threshold: 5
# max traffic percentage routed to canary
# percentage (0-100)
maxWeight: 100
# canary increment step
# percentage (0-100)
stepWeight: 5
metrics:
- name: "500 percentage"
templateRef:
name: error-rate
namespace: istio-system
thresholdRange:
min: 99
interval: 15s
webhooks:
- name: acceptance-test
type: pre-rollout
url: http://flagger-loadtester.test/
timeout: 30s
metadata:
type: bash
cmd: "curl -sd 'test' http://podinfo-canary:9898/token | grep token"
- name: load-test
url: http://flagger-loadtester.test/
timeout: 5s
metadata:
cmd: "hey -z 1m -q 10 -c 2 http://podinfo-canary.test:9898/"

Few things to note regarding the canary release:

# deployment reference
targetRef:
apiVersion: apps/v1
kind: Deployment
name: podinfo
service:
# service port number
port: 9898
analysis:
# schedule interval (default 60s)
interval: 10s
# max number of failed metric checks before rollback
threshold: 5
# max traffic percentage routed to canary
# percentage (0-100)
maxWeight: 100
# canary increment step
# percentage (0-100)
stepWeight: 5
metrics:
- name: "500 percentage"
templateRef:
name: error-rate
namespace: istio-system
thresholdRange:
min: 99
interval: 15s
$ kubectl -n test set image deployment/podinfo \
podinfod=stefanprodan/podinfo:3.1.1
$ kubectl -n test set image deployment/podinfo \
podinfod=stefanprodan/podinfo:3.1.2
$ kubectl -n test exec -it deployment/flagger-loadtester bash
$ watch -n 1 curl http://podinfo-canary:9898/status/500

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store