...

/

Creating Canary Resources with Flagger

Creating Canary Resources with Flagger

In this lesson, we will learn how to create canary resources with Flagger.

Let’s say we want to deploy our new release only to 20% of the users and that we will monitor metrics for 60 seconds. During that period, we’ll be validating whether the error rate is within a predefined threshold and whether the time it takes to process requests is within some limits. If everything seems right, we’ll increase the percentage of users who can use our new release for another 20%, and continue monitoring metrics to decide whether to proceed. The process should repeat until the new release is rolled out to everyone, twenty percent at a time every thirty seconds.

Now that we have a general idea of what we want to accomplish and that all the tools are set up, all that’s missing is to create Flagger Canary definition.

Fortunately, canary deployments with Flagger are available in Jenkins X build packs since January 2020. So, there’s not much work to do to convert our application to use the canary deployment process.

The Canary resource definition #

Let’s take a look at the Canary resource definition already available in our project.

Press + to interact
cat charts/jx-progressive/templates/canary.yaml

The output is as follows.

Press + to interact
{{- if .Values.canary.enabled }}
apiVersion: flagger.app/v1alpha3
kind: Canary
metadata:
name: {{ template "fullname" . }}
labels:
draft: {{ default "draft-app" .Values.draft }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
spec:
provider: istio
targetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ template "fullname" . }}
progressDeadlineSeconds: {{ .Values.canary.progressDeadlineSeconds }}
{{- if .Values.hpa.enabled }}
autoscalerRef:
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
name: {{ template "fullname" . }}
{{- end }}
service:
port: {{ .Values.service.externalPort }}
targetPort: {{ .Values.service.internalPort }}
gateways:
- {{ template "fullname" . }}
hosts:
- {{ .Values.canary.host }}
analysis:
interval: {{ .Values.canary.canaryAnalysis.interval }}
threshold: {{ .Values.canary.canaryAnalysis.threshold }}
maxWeight: {{ .Values.canary.canaryAnalysis.maxWeight }}
stepWeight: {{ .Values.canary.canaryAnalysis.stepWeight }}
metrics:
- name: request-success-rate
threshold: {{ .Values.canary.canaryAnalysis.metrics.requestSuccessRate.threshold }}
interval: {{ .Values.canary.canaryAnalysis.metrics.requestSuccessRate.interval }}
- name: request-duration
threshold: {{ .Values.canary.canaryAnalysis.metrics.requestDuration.threshold }}
interval: {{ .Values.canary.canaryAnalysis.metrics.requestDuration.interval }}
---
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: {{ template "fullname" . }}
spec:
selector:
istio: ingressgateway
servers:
- port:
number: {{ .Values.service.externalPort }}
name: http
protocol: HTTP
hosts:
- {{ .Values.canary.host }}
{{- end }}

canary.enabled

The whole ...

Access this course and 1400+ top-rated courses and projects.