diff --git a/.circleci/config.yml b/.circleci/config.yml index 867044a5b..a70235294 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -199,7 +199,7 @@ jobs: - run: name: Publish charts command: | - if echo "${CIRCLE_TAG}" | grep -Eq "[0-9]+(\.[0-9]+)*(-[a-z]+)?$"; then + if echo "${CIRCLE_TAG}" | grep v; then REPOSITORY="https://weaveworksbot:${GITHUB_TOKEN}@github.com/weaveworks/flagger.git" git config user.email weaveworksbot@users.noreply.github.com git config user.name weaveworksbot diff --git a/.gitbook.yaml b/.gitbook.yaml index ef0ea31af..bdd2977aa 100644 --- a/.gitbook.yaml +++ b/.gitbook.yaml @@ -1,6 +1,7 @@ root: ./docs/gitbook redirects: + how-it-works: usage/how-it-works.md usage/progressive-delivery: tutorials/istio-progressive-delivery.md usage/ab-testing: tutorials/istio-ab-testing.md usage/blue-green: tutorials/kubernetes-blue-green.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9536a6442..4dde45927 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -17,12 +17,12 @@ contribution. ## Chat The project uses Slack: To join the conversation, simply join the -[Weave community](https://slack.weave.works/) Slack workspace. +[Weave community](https://slack.weave.works/) Slack workspace #flagger channel. ## Getting Started - Fork the repository on GitHub -- If you want to contribute as a developer, continue reading this document for further instructions +- If you want to contribute as a developer, read [Flagger Development Guide](https://docs.flagger.app/dev-guide) - If you have questions, concerns, get stuck or need a hand, let us know on the Slack channel. We are happy to help and look forward to having you part of the team. No matter in which capacity. @@ -59,7 +59,7 @@ get asked to resubmit the PR or divide the changes into more than one PR. ### Format of the Commit Message -For Flux we prefer the following rules for good commit messages: +For Flagger we prefer the following rules for good commit messages: - Limit the subject to 50 characters and write as the continuation of the sentence "If applied, this commit will ..." @@ -69,4 +69,4 @@ For Flux we prefer the following rules for good commit messages: The [following article](https://chris.beams.io/posts/git-commit/#seven-rules) has some more helpful advice on documenting your work. -This doc is adapted from the [Weaveworks Flux](https://github.com/weaveworks/flux/blob/master/CONTRIBUTING.md) +This doc is adapted from [FluxCD](https://github.com/fluxcd/flux/blob/master/CONTRIBUTING.md). diff --git a/Makefile b/Makefile index 9e2dddf37..02edad791 100644 --- a/Makefile +++ b/Makefile @@ -20,6 +20,9 @@ test-fmt: gofmt -l -s ./ | grep ".*\.go"; if [ "$$?" = "0" ]; then exit 1; fi goimports -l ./ | grep ".*\.go"; if [ "$$?" = "0" ]; then exit 1; fi +codegen: + ./hack/update-codegen.sh + test-codegen: ./hack/verify-codegen.sh @@ -42,16 +45,16 @@ version-set: echo "Version $$next set in code, deployment, chart and kustomize" release: - git tag $(VERSION) - git push origin $(VERSION) + git tag "v$(VERSION)" + git push origin "v$(VERSION)" release-notes: cd /tmp && GH_REL_URL="https://github.com/buchanae/github-release-notes/releases/download/0.2.0/github-release-notes-linux-amd64-0.2.0.tar.gz" && \ curl -sSL $${GH_REL_URL} | tar xz && sudo mv github-release-notes /usr/local/bin/ loadtester-build: - GO111MODULE=on CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o ./bin/loadtester ./cmd/loadtester/* + CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o ./bin/loadtester ./cmd/loadtester/* + docker build -t weaveworks/flagger-loadtester:$(LT_VERSION) . -f Dockerfile.loadtester loadtester-push: - docker build -t weaveworks/flagger-loadtester:$(LT_VERSION) . -f Dockerfile.loadtester docker push weaveworks/flagger-loadtester:$(LT_VERSION) diff --git a/README.md b/README.md index d1fbca2f5..e8222f732 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ When promoting a workload in production, both code (container images) and config For a deployment named _podinfo_, a canary promotion can be defined using Flagger's custom resource: ```yaml -apiVersion: flagger.app/v1alpha3 +apiVersion: flagger.app/v1beta1 kind: Canary metadata: name: podinfo @@ -87,7 +87,7 @@ spec: kind: HorizontalPodAutoscaler name: podinfo service: - # service name (optional) + # service name (defaults to targetRef.name) name: podinfo # ClusterIP port number port: 9898 @@ -95,6 +95,9 @@ spec: targetPort: 9898 # port name can be http or grpc (default http) portName: http + # add all the other container ports + # to the ClusterIP services (default false) + portDiscovery: true # HTTP match conditions (optional) match: - uri: @@ -107,7 +110,7 @@ spec: # promote the canary without analysing it (default false) skipAnalysis: false # define the canary analysis timing and KPIs - canaryAnalysis: + analysis: # schedule interval (default 60s) interval: 1m # max number of failed metric checks before rollback @@ -118,36 +121,59 @@ spec: # canary increment step # percentage (0-100) stepWeight: 5 - # Istio Prometheus checks + # validation (optional) metrics: - # builtin checks - name: request-success-rate + # builtin Prometheus check # minimum req success rate (non 5xx responses) # percentage (0-100) - threshold: 99 + thresholdRange: + min: 99 interval: 1m - name: request-duration + # builtin Prometheus check # maximum req duration P99 # milliseconds - threshold: 500 + thresholdRange: + max: 500 interval: 30s - # custom check - - name: "kafka lag" - threshold: 100 - query: | - avg_over_time( - kafka_consumergroup_lag{ - consumergroup=~"podinfo-consumer-.*", - topic="podinfo" - }[1m] - ) + - name: "database connections" + # custom Prometheus check + templateRef: + name: db-connections + thresholdRange: + min: 2 + max: 100 + interval: 1m # testing (optional) webhooks: - - name: load-test + - name: "conformance test" + type: pre-rollout + url: http://flagger-helmtester.test/ + timeout: 5m + metadata: + type: "helmv3" + cmd: "test run podinfo -n test" + - name: "load test" + type: rollout url: http://flagger-loadtester.test/ - timeout: 5s metadata: cmd: "hey -z 1m -q 10 -c 2 http://podinfo.test:9898/" + # alerting (optional) + alerts: + - name: "dev team Slack" + severity: error + providerRef: + name: dev-slack + namespace: flagger + - name: "qa team Discord" + severity: warn + providerRef: + name: qa-discord + - name: "on-call MS Teams" + severity: info + providerRef: + name: on-call-msteams ``` For more details on how the canary analysis and promotion works please [read the docs](https://docs.flagger.app/how-it-works). diff --git a/docs/gitbook/README.md b/docs/gitbook/README.md index 1aaf6b91c..8452986a2 100644 --- a/docs/gitbook/README.md +++ b/docs/gitbook/README.md @@ -4,13 +4,45 @@ description: Flagger is a progressive delivery Kubernetes operator # Introduction -[Flagger](https://github.com/weaveworks/flagger) is a **Kubernetes** operator that automates the promotion of canary deployments using **Istio**, **Linkerd**, **App Mesh**, **NGINX**, **Contour** or **Gloo** routing for traffic shifting and **Prometheus** metrics for canary analysis. The canary analysis can be extended with webhooks for running system integration/acceptance tests, load tests, or any other custom validation. +[Flagger](https://github.com/weaveworks/flagger) is a **Kubernetes** operator that automates the promotion of +canary deployments using **Istio**, **Linkerd**, **App Mesh**, **NGINX**, **Contour** or **Gloo** routing for +traffic shifting and **Prometheus** metrics for canary analysis. The canary analysis can be extended with webhooks for +running system integration/acceptance tests, load tests, or any other custom validation. -Flagger implements a control loop that gradually shifts traffic to the canary while measuring key performance indicators like HTTP requests success rate, requests average duration and pods health. Based on analysis of the **KPIs** a canary is promoted or aborted, and the analysis result is published to **Slack** or **MS Teams**. +Flagger implements a control loop that gradually shifts traffic to the canary while measuring key performance indicators +like HTTP requests success rate, requests average duration and pods health. +Based on analysis of the **KPIs** a canary is promoted or aborted, and the analysis result is published to **Slack** or **MS Teams**. ![Flagger overview diagram](https://raw.githubusercontent.com/weaveworks/flagger/master/docs/diagrams/flagger-canary-overview.png) -Flagger can be configured with Kubernetes custom resources and is compatible with any CI/CD solutions made for Kubernetes. Since Flagger is declarative and reacts to Kubernetes events, it can be used in **GitOps** pipelines together with Flux CD or JenkinsX. +Flagger can be configured with Kubernetes custom resources and is compatible with any CI/CD solutions made for Kubernetes. +Since Flagger is declarative and reacts to Kubernetes events, +it can be used in **GitOps** pipelines together with Flux CD or JenkinsX. This project is sponsored by [Weaveworks](https://www.weave.works/) +## Getting started + +To get started with Flagger, chose one of the supported routing providers +and [install](install/flagger-install-on-kubernetes.md) Flagger with Helm or Kustomize. + +After install Flagger you can follow one the tutorials: + +**Service mesh tutorials** + +* [Istio](tutorials/istio-progressive-delivery.md) +* [Linkerd](tutorials/linkerd-progressive-delivery.md) +* [AWS App Mesh](tutorials/appmesh-progressive-delivery.md) + +**Ingress controller tutorials** + +* [Contour](tutorials/contour-progressive-delivery.md) +* [Gloo](tutorials/gloo-progressive-delivery.md) +* [NGINX Ingress](tutorials/nginx-progressive-delivery.md) + +**Hands-on GitOps workshops** + +* [Istio](https://github.com/stefanprodan/gitops-istio) +* [Linkerd](https://helm.workshop.flagger.dev) +* [AWS App Mesh](https://eks.hands-on.flagger.dev) + diff --git a/docs/gitbook/SUMMARY.md b/docs/gitbook/SUMMARY.md index 02655e1ed..d85459fc4 100644 --- a/docs/gitbook/SUMMARY.md +++ b/docs/gitbook/SUMMARY.md @@ -1,20 +1,20 @@ # Table of contents * [Introduction](README.md) -* [How it works](how-it-works.md) * [FAQ](faq.md) -* [Development guide](dev-guide.md) ## Install * [Flagger Install on Kubernetes](install/flagger-install-on-kubernetes.md) * [Flagger Install on GKE Istio](install/flagger-install-on-google-cloud.md) * [Flagger Install on EKS App Mesh](install/flagger-install-on-eks-appmesh.md) -* [Flagger Install with SuperGloo](install/flagger-install-with-supergloo.md) ## Usage +* [How it works](usage/how-it-works.md) * [Deployment Strategies](usage/deployment-strategies.md) +* [Metrics Analysis](usage/metrics.md) +* [Webhooks](usage/webhooks.md) * [Alerting](usage/alerting.md) * [Monitoring](usage/monitoring.md) @@ -33,3 +33,8 @@ * [Canaries with Helm charts and GitOps](tutorials/canary-helm-gitops.md) * [Zero downtime deployments](tutorials/zero-downtime-deployments.md) +## Dev + +* [Development Guide](dev/dev-guide.md) +* [Release Guide](dev/release-guide.md) +* [Upgrade Guide](dev/upgrade-guide.md) \ No newline at end of file diff --git a/docs/gitbook/dev-guide.md b/docs/gitbook/dev/dev-guide.md similarity index 57% rename from docs/gitbook/dev-guide.md rename to docs/gitbook/dev/dev-guide.md index fd54e3ebe..9e6e557b6 100644 --- a/docs/gitbook/dev-guide.md +++ b/docs/gitbook/dev/dev-guide.md @@ -1,59 +1,79 @@ -# Development guide +# Development Guide This document describes how to build, test and run Flagger from source. -## Setup dev environment +### Setup dev environment Flagger is written in Go and uses Go modules for dependency management. On your dev machine install the following tools: +* go >= 1.13 +* git >= 2.20 +* bash >= 5.0 +* make >= 3.81 +* kubectl >= 1.16 +* kustomize >= 3.5 +* helm >= 3.0 +* docker >= 19.03 -* go >= 1.13 -* git >= 2.20 -* bash >= 5.0 -* make >= 3.81 -* kubectl >= 1.16 -* kustomize >= 3.5 -* helm >= 3.0 -* docker >= 19.03 +You'll also need a Kubernetes cluster for testing Flagger. +You can use Minikube, Kind, Docker desktop or any remote cluster +(AKS/EKS/GKE/etc) Kubernetes version 1.14 or newer. -You'll also need a Kubernetes cluster for testing Flagger. You can use Minikube, Kind, Docker desktop or any remote cluster \(AKS/EKS/GKE/etc\) Kubernetes version 1.14 or newer. +To start contributing to Flagger, fork the [repository](https://github.com/weaveworks/flagger) on GitHub. -## Build +Create a dir inside your `GOPATH`: -To start contributing to Flagger, fork the repository and clone it locally: +```bash +mkdir -p $GOPATH/src/github.com/weaveworks +``` + +Clone your fork: ```bash -git clone https://github.com//flagger +cd $GOPATH/src/github.com/weaveworks +git clone https://github.com/YOUR_USERNAME/flagger cd flagger ``` -Download Go modules: +Set Flagger repository as upstream: ```bash -go mod download +git remote add upstream https://github.com/weaveworks/flagger.git ``` -Build Flagger binary: +Sync your fork regularly to keep it up-to-date with upstream: ```bash -CGO_ENABLED=0 go build -o ./bin/flagger ./cmd/flagger/ +git fetch upstream +git checkout master +git merge upstream/master ``` -Build Flagger container image: +### Build + +Download Go modules: ```bash -make build +go mod download ``` -## Unit testing +Build Flagger binary and container image: -Make a change to the source code and run the linter and unit tests: +```bash +make build +``` + +Build load tester binary and container image: ```bash -make test +make loadtester-build ``` +### Code changes + +Before submitting a PR, make sure your changes are covered by unit tests. + If you made changes to `go.mod` run: ```bash @@ -63,12 +83,25 @@ go mod tidy If you made changes to `pkg/apis` regenerate Kubernetes client sets with: ```bash -./hack/update-codegen.sh +make codegen +``` + +Run code formatters: + +```bash +make fmt ``` -## Manual testing +Run unit tests: -Install a service mesh and/or an ingress controller on your cluster and deploy Flagger using one of the install options [listed here](https://docs.flagger.app/install/flagger-install-on-kubernetes). +```bash +make test +``` + +### Manual testing + +Install a service mesh and/or an ingress controller on your cluster and deploy Flagger +using one of the install options [listed here](https://docs.flagger.app/install/flagger-install-on-kubernetes). If you made changes to the CRDs, apply your local copy with: @@ -76,7 +109,7 @@ If you made changes to the CRDs, apply your local copy with: kubectl apply -f artifacts/flagger/crd.yaml ``` -Shutdown the Flagger instance installed on your cluster \(replace the namespace with your mesh/ingress one\): +Shutdown the Flagger instance installed on your cluster (replace the namespace with your mesh/ingress one): ```bash kubectl -n istio-system scale deployment/flagger --replicas=0 @@ -112,9 +145,9 @@ kubectl -n istio-system set image deployment/flagger flagger=..svc.cluster.local` - selector `app=-primary` - * `-primary..svc.cluster.local` - selector `app=-primary` - * `-canary..svc.cluster.local` - selector `app=` -This ensures that traffic coming from a namespace outside the mesh to `podinfo.test:9898` will be routed to the latest stable release of your app. +This ensures that traffic coming from a namespace outside the mesh to `podinfo.test:9898` +will be routed to the latest stable release of your app. ```yaml apiVersion: v1 @@ -243,13 +113,16 @@ spec: targetPort: http ``` -The `podinfo-canary.test:9898` address is available only during the canary analysis and can be used for conformance testing or load testing. +The `podinfo-canary.test:9898` address is available only during the +canary analysis and can be used for conformance testing or load testing. -## Multiple ports +### Multiple ports **My application listens on multiple ports, how can I expose them inside the cluster?** -If port discovery is enabled, Flagger scans the deployment spec and extracts the containers ports excluding the port specified in the canary service and Envoy sidecar ports. \`These ports will be used when generating the ClusterIP services. +If port discovery is enabled, Flagger scans the deployment spec and extracts the containers +ports excluding the port specified in the canary service and Envoy sidecar ports. +These ports will be used when generating the ClusterIP services. For a deployment that exposes two ports: @@ -273,7 +146,7 @@ spec: You can enable port discovery so that Prometheus will be able to reach port `9090` over mTLS: ```yaml -apiVersion: flagger.app/v1alpha3 +apiVersion: flagger.app/v1beta1 kind: Canary spec: service: @@ -291,7 +164,7 @@ spec: Both port `8080` and `9090` will be added to the ClusterIP services. -## Label selectors +### Label selectors **What labels selectors are supported by Flagger?** @@ -312,7 +185,8 @@ spec: app: podinfo ``` -Besides `app` Flagger supports `name` and `app.kubernetes.io/name` selectors. If you use a different convention you can specify your label with the `-selector-labels` flag. +Besides `app` Flagger supports `name` and `app.kubernetes.io/name` selectors. If you use a different +convention you can specify your label with the `-selector-labels` flag. **Is pod affinity and anti affinity supported?** @@ -347,16 +221,141 @@ spec: topologyKey: kubernetes.io/hostname ``` -## Istio routing +### Metrics + +**How does Flagger measures the request success rate and duration?** + +Flagger measures the request success rate and duration using Prometheus queries. + +**HTTP requests success rate percentage** + +Spec: + +```yaml + analysis: + metrics: + - name: request-success-rate + # minimum req success rate (non 5xx responses) + # percentage (0-100) + thresholdRange: + min: 99 + interval: 1m +``` + +Istio query: + +```javascript +sum( + rate( + istio_requests_total{ + reporter="destination", + destination_workload_namespace=~"$namespace", + destination_workload=~"$workload", + response_code!~"5.*" + }[$interval] + ) +) +/ +sum( + rate( + istio_requests_total{ + reporter="destination", + destination_workload_namespace=~"$namespace", + destination_workload=~"$workload" + }[$interval] + ) +) +``` + +Envoy query (App Mesh, Contour or Gloo): + +```javascript +sum( + rate( + envoy_cluster_upstream_rq{ + kubernetes_namespace="$namespace", + kubernetes_pod_name=~"$workload", + envoy_response_code!~"5.*" + }[$interval] + ) +) +/ +sum( + rate( + envoy_cluster_upstream_rq{ + kubernetes_namespace="$namespace", + kubernetes_pod_name=~"$workload" + }[$interval] + ) +) +``` + +**HTTP requests milliseconds duration P99** + +Spec: + +```yaml + analysis: + metrics: + - name: request-duration + # maximum req duration P99 + # milliseconds + thresholdRange: + max: 500 + interval: 1m +``` + +Istio query: + +```javascript +histogram_quantile(0.99, + sum( + irate( + istio_request_duration_seconds_bucket{ + reporter="destination", + destination_workload=~"$workload", + destination_workload_namespace=~"$namespace" + }[$interval] + ) + ) by (le) +) +``` + +Envoy query (App Mesh, Contour or Gloo): + +```javascript +histogram_quantile(0.99, + sum( + irate( + envoy_cluster_upstream_rq_time_bucket{ + kubernetes_pod_name=~"$workload", + kubernetes_namespace=~"$namespace" + }[$interval] + ) + ) by (le) +) +``` + +> **Note** that the metric interval should be lower or equal to the control loop interval. + +**Can I use custom metrics?** + +The analysis can be extended with metrics provided by Prometheus, Datadog and AWS CloudWatch. For more details +on how custom metrics can be used please read the [metrics docs](usage/metrics.md). + +### Istio routing **How does Flagger interact with Istio?** -Flagger creates an Istio Virtual Service and Destination Rules based on the Canary service spec. The service configuration lets you expose an app inside or outside the mesh. You can also define traffic policies, HTTP match conditions, URI rewrite rules, CORS policies, timeout and retries. +Flagger creates an Istio Virtual Service and Destination Rules based on the Canary service spec. +The service configuration lets you expose an app inside or outside the mesh. +You can also define traffic policies, HTTP match conditions, URI rewrite rules, CORS policies, timeout and retries. -The following spec exposes the `frontend` workload inside the mesh on `frontend.test.svc.cluster.local:9898` and outside the mesh on `frontend.example.com`. You'll have to specify an Istio ingress gateway for external hosts. +The following spec exposes the `frontend` workload inside the mesh on `frontend.test.svc.cluster.local:9898` +and outside the mesh on `frontend.example.com`. You'll have to specify an Istio ingress gateway for external hosts. ```yaml -apiVersion: flagger.app/v1alpha3 +apiVersion: flagger.app/v1beta1 kind: Canary metadata: name: frontend @@ -417,7 +416,7 @@ metadata: name: frontend namespace: test ownerReferences: - - apiVersion: flagger.app/v1alpha3 + - apiVersion: flagger.app/v1beta1 blockOwnerDeletion: true controller: true kind: Canary @@ -487,12 +486,14 @@ spec: mode: DISABLE ``` -Flagger keeps in sync the virtual service and destination rules with the canary service spec. Any direct modification to the virtual service spec will be overwritten. +Flagger keeps in sync the virtual service and destination rules with the canary service spec. +Any direct modification to the virtual service spec will be overwritten. -To expose a workload inside the mesh on `http://backend.test.svc.cluster.local:9898`, the service spec can contain only the container port and the traffic policy: +To expose a workload inside the mesh on `http://backend.test.svc.cluster.local:9898`, +the service spec can contain only the container port and the traffic policy: ```yaml -apiVersion: flagger.app/v1alpha3 +apiVersion: flagger.app/v1beta1 kind: Canary metadata: name: backend @@ -513,7 +514,7 @@ kind: Service metadata: name: backend-primary ownerReferences: - - apiVersion: flagger.app/v1alpha3 + - apiVersion: flagger.app/v1beta1 blockOwnerDeletion: true controller: true kind: Canary @@ -530,16 +531,18 @@ spec: app: backend-primary ``` -Flagger works for user facing apps exposed outside the cluster via an ingress gateway and for backend HTTP APIs that are accessible only from inside the mesh. +Flagger works for user facing apps exposed outside the cluster via an ingress gateway +and for backend HTTP APIs that are accessible only from inside the mesh. -## Istio Ingress Gateway +### Istio Ingress Gateway **How can I expose multiple canaries on the same external domain?** -Assuming you have two apps, one that servers the main website and one that serves the REST API. For each app you can define a canary object as: +Assuming you have two apps, one that servers the main website and one that serves the REST API. +For each app you can define a canary object as: ```yaml -apiVersion: flagger.app/v1alpha3 +apiVersion: flagger.app/v1beta1 kind: Canary metadata: name: website @@ -556,7 +559,7 @@ spec: rewrite: uri: / --- -apiVersion: flagger.app/v1alpha3 +apiVersion: flagger.app/v1beta1 kind: Canary metadata: name: webapi @@ -574,18 +577,20 @@ spec: uri: / ``` -Based on the above configuration, Flagger will create two virtual services bounded to the same ingress gateway and external host. Istio Pilot will [merge](https://istio.io/help/ops/traffic-management/deploy-guidelines/#multiple-virtual-services-and-destination-rules-for-the-same-host) the two services and the website rule will be moved to the end of the list in the merged configuration. +Based on the above configuration, Flagger will create two virtual services bounded to the same ingress gateway and external host. +Istio Pilot will [merge](https://istio.io/help/ops/traffic-management/deploy-guidelines/#multiple-virtual-services-and-destination-rules-for-the-same-host) +the two services and the website rule will be moved to the end of the list in the merged configuration. Note that host merging only works if the canaries are bounded to a ingress gateway other than the `mesh` gateway. -## Istio Mutual TLS +### Istio Mutual TLS **How can I enable mTLS for a canary?** When deploying Istio with global mTLS enabled, you have to set the TLS mode to `ISTIO_MUTUAL`: ```yaml -apiVersion: flagger.app/v1alpha3 +apiVersion: flagger.app/v1beta1 kind: Canary spec: service: @@ -597,7 +602,7 @@ spec: If you run Istio in permissive mode you can disable TLS: ```yaml -apiVersion: flagger.app/v1alpha3 +apiVersion: flagger.app/v1beta1 kind: Canary spec: service: @@ -633,4 +638,3 @@ spec: ports: - number: 80 ``` - diff --git a/docs/gitbook/how-it-works.md b/docs/gitbook/how-it-works.md deleted file mode 100644 index 9b9f525d3..000000000 --- a/docs/gitbook/how-it-works.md +++ /dev/null @@ -1,908 +0,0 @@ -# How it works - -[Flagger](https://github.com/weaveworks/flagger) takes a Kubernetes deployment and optionally a horizontal pod autoscaler \(HPA\) and creates a series of objects \(Kubernetes deployments, ClusterIP services, virtual service, traffic split or ingress\) to drive the canary analysis and promotion. - -## Canary Custom Resource - -For a deployment named _podinfo_, a canary promotion can be defined using Flagger's custom resource: - -```yaml -apiVersion: flagger.app/v1alpha3 -kind: Canary -metadata: - name: podinfo - namespace: test -spec: - # service mesh provider (optional) - # can be: kubernetes, istio, linkerd, appmesh, nginx, gloo, supergloo - provider: linkerd - # deployment reference - targetRef: - apiVersion: apps/v1 - kind: Deployment - name: podinfo - # the maximum time in seconds for the canary deployment - # to make progress before it is rollback (default 600s) - progressDeadlineSeconds: 60 - # HPA reference (optional) - autoscalerRef: - apiVersion: autoscaling/v2beta1 - kind: HorizontalPodAutoscaler - name: podinfo - service: - # service name (optional) - name: podinfo - # ClusterIP port number - port: 9898 - # ClusterIP port name can be http or grpc (default http) - portName: http - # container port number or name (optional) - targetPort: 9898 - # add all the other container ports - # to the ClusterIP services (default false) - portDiscovery: false - # promote the canary without analysing it (default false) - skipAnalysis: false - # define the canary analysis timing and KPIs - canaryAnalysis: - # schedule interval (default 60s) - interval: 1m - # max number of failed metric checks before rollback - threshold: 10 - # max traffic percentage routed to canary - # percentage (0-100) - maxWeight: 50 - # canary increment step - # percentage (0-100) - stepWeight: 5 - # Prometheus checks - metrics: - - name: request-success-rate - # minimum req success rate (non 5xx responses) - # percentage (0-100) - threshold: 99 - interval: 1m - - name: request-duration - # maximum req duration P99 - # milliseconds - threshold: 500 - interval: 30s - # testing (optional) - webhooks: - - name: load-test - url: http://flagger-loadtester.test/ - timeout: 5s - metadata: - cmd: "hey -z 1m -q 10 -c 2 http://podinfo.test:9898/" -``` - -**Note** that the target deployment must have a single label selector in the format `app: `: - -```yaml -apiVersion: apps/v1 -kind: Deployment -metadata: - name: podinfo -spec: - selector: - matchLabels: - app: podinfo - template: - metadata: - labels: - app: podinfo -``` - -Besides `app` Flagger supports `name` and `app.kubernetes.io/name` selectors. If you use a different convention you can specify your label with the `-selector-labels=my-app-label` command flag in the Flagger deployment manifest under containers args or by setting `--set selectorLabels=my-app-label` when installing Flagger with Helm. - -The target deployment should expose a TCP port that will be used by Flagger to create the ClusterIP Services. The container port from the target deployment should match the `service.port` or `service.targetPort`. - -## Canary status - -Get the current status of canary deployments cluster wide: - -```bash -kubectl get canaries --all-namespaces - -NAMESPACE NAME STATUS WEIGHT LASTTRANSITIONTIME -test podinfo Progressing 15 2019-06-30T14:05:07Z -prod frontend Succeeded 0 2019-06-30T16:15:07Z -prod backend Failed 0 2019-06-30T17:05:07Z -``` - -The status condition reflects the last know state of the canary analysis: - -```bash -kubectl -n test get canary/podinfo -oyaml | awk '/status/,0' -``` - -A successful rollout status: - -```yaml -status: - canaryWeight: 0 - failedChecks: 0 - iterations: 0 - lastAppliedSpec: "14788816656920327485" - lastPromotedSpec: "14788816656920327485" - conditions: - - lastTransitionTime: "2019-07-10T08:23:18Z" - lastUpdateTime: "2019-07-10T08:23:18Z" - message: Canary analysis completed successfully, promotion finished. - reason: Succeeded - status: "True" - type: Promoted -``` - -The `Promoted` status condition can have one of the following reasons: Initialized, Waiting, Progressing, Promoting, Finalising, Succeeded or Failed. A failed canary will have the promoted status set to `false`, the reason to `failed` and the last applied spec will be different to the last promoted one. - -Wait for a successful rollout: - -```bash -kubectl wait canary/podinfo --for=condition=promoted -``` - -CI example: - -```bash -# update the container image -kubectl set image deployment/podinfo podinfod=stefanprodan/podinfo:3.0.1 - -# wait for Flagger to detect the change -ok=false -until ${ok}; do - kubectl get canary/podinfo | grep 'Progressing' && ok=true || ok=false - sleep 5 -done - -# wait for the canary analysis to finish -kubectl wait canary/podinfo --for=condition=promoted --timeout=5m - -# check if the deployment was successful -kubectl get canary/podinfo | grep Succeeded -``` - -## Canary Stages - -![Flagger Canary Stages](https://raw.githubusercontent.com/weaveworks/flagger/master/docs/diagrams/flagger-canary-steps.png) - -A canary deployment is triggered by changes in any of the following objects: - -* Deployment PodSpec \(container image, command, ports, env, resources, etc\) -* ConfigMaps mounted as volumes or mapped to environment variables -* Secrets mounted as volumes or mapped to environment variables - -Gated canary promotion stages: - -* scan for canary deployments -* check primary and canary deployment status - * halt advancement if a rolling update is underway - * halt advancement if pods are unhealthy -* call confirm-rollout webhooks and check results - * halt advancement if any hook returns a non HTTP 2xx result -* call pre-rollout webhooks and check results - * halt advancement if any hook returns a non HTTP 2xx result - * increment the failed checks counter -* increase canary traffic weight percentage from 0% to 5% \(step weight\) -* call rollout webhooks and check results -* check canary HTTP request success rate and latency - * halt advancement if any metric is under the specified threshold - * increment the failed checks counter -* check if the number of failed checks reached the threshold - * route all traffic to primary - * scale to zero the canary deployment and mark it as failed - * call post-rollout webhooks - * post the analysis result to Slack - * wait for the canary deployment to be updated and start over -* increase canary traffic weight by 5% \(step weight\) till it reaches 50% \(max weight\) - * halt advancement if any webhook call fails - * halt advancement while canary request success rate is under the threshold - * halt advancement while canary request duration P99 is over the threshold - * halt advancement while any custom metric check fails - * halt advancement if the primary or canary deployment becomes unhealthy - * halt advancement while canary deployment is being scaled up/down by HPA -* call confirm-promotion webhooks and check results - * halt advancement if any hook returns a non HTTP 2xx result -* promote canary to primary - * copy ConfigMaps and Secrets from canary to primary - * copy canary deployment spec template over primary -* wait for primary rolling update to finish - * halt advancement if pods are unhealthy -* route all traffic to primary -* scale to zero the canary deployment -* mark rollout as finished -* call post-rollout webhooks -* post the analysis result to Slack or MS Teams -* wait for the canary deployment to be updated and start over - -## Canary Analysis - -The canary analysis runs periodically until it reaches the maximum traffic weight or the failed checks threshold. - -Spec: - -```yaml - canaryAnalysis: - # schedule interval (default 60s) - interval: 1m - # max number of failed metric checks before rollback - threshold: 10 - # max traffic percentage routed to canary - # percentage (0-100) - maxWeight: 50 - # canary increment step - # percentage (0-100) - stepWeight: 2 - # deploy straight to production without - # the metrics and webhook checks - skipAnalysis: false -``` - -The above analysis, if it succeeds, will run for 25 minutes while validating the HTTP metrics and webhooks every minute. You can determine the minimum time that it takes to validate and promote a canary deployment using this formula: - -```text -interval * (maxWeight / stepWeight) -``` - -And the time it takes for a canary to be rollback when the metrics or webhook checks are failing: - -```text -interval * threshold -``` - -In emergency cases, you may want to skip the analysis phase and ship changes directly to production. At any time you can set the `spec.skipAnalysis: true`. When skip analysis is enabled, Flagger checks if the canary deployment is healthy and promotes it without analysing it. If an analysis is underway, Flagger cancels it and runs the promotion. - -## A/B Testing - -Besides weighted routing, Flagger can be configured to route traffic to the canary based on HTTP match conditions. In an A/B testing scenario, you'll be using HTTP headers or cookies to target a certain segment of your users. This is particularly useful for frontend applications that require session affinity. - -You can enable A/B testing by specifying the HTTP match conditions and the number of iterations: - -```yaml - canaryAnalysis: - # schedule interval (default 60s) - interval: 1m - # total number of iterations - iterations: 10 - # max number of failed iterations before rollback - threshold: 2 - # canary match condition - match: - - headers: - user-agent: - regex: "^(?!.*Chrome).*Safari.*" - - headers: - cookie: - regex: "^(.*?;)?(user=test)(;.*)?$" -``` - -If Flagger finds a HTTP match condition, it will ignore the `maxWeight` and `stepWeight` settings. - -The above configuration will run an analysis for ten minutes targeting the Safari users and those that have a test cookie. You can determine the minimum time that it takes to validate and promote a canary deployment using this formula: - -```text -interval * iterations -``` - -And the time it takes for a canary to be rollback when the metrics or webhook checks are failing: - -```text -interval * threshold -``` - -Make sure that the analysis threshold is lower than the number of iterations. - -## Blue/Green deployments - -For applications that are not deployed on a service mesh, Flagger can orchestrate blue/green style deployments with Kubernetes L4 networking. When using Istio you have the option to mirror traffic between blue and green. - -You can use the blue/green deployment strategy by replacing `stepWeight/maxWeight` with `iterations` in the `canaryAnalysis` spec: - -```yaml - canaryAnalysis: - # schedule interval (default 60s) - interval: 1m - # total number of iterations - iterations: 10 - # max number of failed iterations before rollback - threshold: 2 - # Traffic shadowing (compatible with Istio only) - mirror: true -``` - -With the above configuration Flagger will run conformance and load tests on the canary pods for ten minutes. If the metrics analysis succeeds, live traffic will be switched from the old version to the new one when the canary is promoted. - -The blue/green deployment strategy is supported for all service mesh providers. - -Blue/Green rollout steps for service mesh: - -* scale up the canary \(green\) -* run conformance tests for the canary pods -* run load tests and metric checks for the canary pods -* route traffic to canary -* promote canary spec over primary \(blue\) -* wait for primary rollout -* route traffic to primary -* scale down canary - -After the analysis finishes, the traffic is routed to the canary \(green\) before triggering the primary \(blue\) rolling update, this ensures a smooth transition to the new version avoiding dropping in-flight requests during the Kubernetes deployment rollout. - -## HTTP Metrics - -The canary analysis is using the following Prometheus queries: - -**HTTP requests success rate percentage** - -Spec: - -```yaml - canaryAnalysis: - metrics: - - name: request-success-rate - # minimum req success rate (non 5xx responses) - # percentage (0-100) - threshold: 99 - interval: 1m -``` - -Istio query: - -```javascript -sum( - rate( - istio_requests_total{ - reporter="destination", - destination_workload_namespace=~"$namespace", - destination_workload=~"$workload", - response_code!~"5.*" - }[$interval] - ) -) -/ -sum( - rate( - istio_requests_total{ - reporter="destination", - destination_workload_namespace=~"$namespace", - destination_workload=~"$workload" - }[$interval] - ) -) -``` - -Envoy query \(App Mesh, Contour or Gloo\): - -```javascript -sum( - rate( - envoy_cluster_upstream_rq{ - kubernetes_namespace="$namespace", - kubernetes_pod_name=~"$workload", - envoy_response_code!~"5.*" - }[$interval] - ) -) -/ -sum( - rate( - envoy_cluster_upstream_rq{ - kubernetes_namespace="$namespace", - kubernetes_pod_name=~"$workload" - }[$interval] - ) -) -``` - -**HTTP requests milliseconds duration P99** - -Spec: - -```yaml - canaryAnalysis: - metrics: - - name: request-duration - # maximum req duration P99 - # milliseconds - threshold: 500 - interval: 1m -``` - -Istio query: - -```javascript -histogram_quantile(0.99, - sum( - irate( - istio_request_duration_seconds_bucket{ - reporter="destination", - destination_workload=~"$workload", - destination_workload_namespace=~"$namespace" - }[$interval] - ) - ) by (le) -) -``` - -Envoy query \(App Mesh, Contour or Gloo\): - -```javascript -histogram_quantile(0.99, - sum( - irate( - envoy_cluster_upstream_rq_time_bucket{ - kubernetes_pod_name=~"$workload", - kubernetes_namespace=~"$namespace" - }[$interval] - ) - ) by (le) -) -``` - -> **Note** that the metric interval should be lower or equal to the control loop interval. - -## Custom Metrics - -The canary analysis can be extended with custom Prometheus queries. - -```yaml - canaryAnalysis: - threshold: 1 - maxWeight: 50 - stepWeight: 5 - metrics: - - name: "404s percentage" - threshold: 5 - query: | - 100 - sum( - rate( - istio_requests_total{ - reporter="destination", - destination_workload_namespace="test", - destination_workload="podinfo", - response_code!="404" - }[1m] - ) - ) - / - sum( - rate( - istio_requests_total{ - reporter="destination", - destination_workload_namespace="test", - destination_workload="podinfo" - }[1m] - ) - ) * 100 -``` - -The above configuration validates the canary by checking if the HTTP 404 req/sec percentage is below 5 percent of the total traffic. If the 404s rate reaches the 5% threshold, then the canary fails. - -```yaml - canaryAnalysis: - threshold: 1 - maxWeight: 50 - stepWeight: 5 - metrics: - - name: "rpc error rate" - threshold: 5 - query: | - 100 - (sum - rate( - grpc_server_handled_total{ - grpc_service="my.TestService", - grpc_code!="OK" - }[1m] - ) - ) - / - sum( - rate( - grpc_server_started_total{ - grpc_service="my.TestService" - }[1m] - ) - ) * 100 -``` - -The above configuration validates the canary by checking if the percentage of non-OK GRPC req/sec is below 5 percent of the total requests. If the non-OK rate reaches the 5% threshold, then the canary fails. - -When specifying a query, Flagger will run the promql query and convert the result to float64. Then it compares the query result value with the metric threshold value. - -## Webhooks - -The canary analysis can be extended with webhooks. Flagger will call each webhook URL and determine from the response status code \(HTTP 2xx\) if the canary is failing or not. - -There are several types of hooks: - -* **confirm-rollout** hooks are executed before scaling up the canary deployment and can be used for manual approval. - - The rollout is paused until the hook returns a successful HTTP status code. - -* **pre-rollout** hooks are executed before routing traffic to canary. - - The canary advancement is paused if a pre-rollout hook fails and if the number of failures reach the - - threshold the canary will be rollback. - -* **rollout** hooks are executed during the analysis on each iteration before the metric checks. - - If a rollout hook call fails the canary advancement is paused and eventfully rolled back. - -* **confirm-promotion** hooks are executed before the promotion step. - - The canary promotion is paused until the hooks return HTTP 200. - - While the promotion is paused, Flagger will continue to run the metrics checks and rollout hooks. - -* **post-rollout** hooks are executed after the canary has been promoted or rolled back. - - If a post rollout hook fails the error is logged. - -* **rollback** hooks are executed while a canary deployment is in either Progressing or Waiting status. - - This provides the ability to rollback during analysis or while waiting for a confirmation. If a rollback hook - - returns a successful HTTP status code, Flagger will stop the analysis and mark the canary release as failed. - -* **event** hooks are executed every time Flagger emits a Kubernetes event. When configured, - - every action that Flagger takes during a canary deployment will be sent as JSON via an HTTP POST request. - -Spec: - -```yaml - canaryAnalysis: - webhooks: - - name: "start gate" - type: confirm-rollout - url: http://flagger-loadtester.test/gate/approve - - name: "smoke test" - type: pre-rollout - url: http://flagger-helmtester.kube-system/ - timeout: 3m - metadata: - type: "helm" - cmd: "test podinfo --cleanup" - - name: "load test" - type: rollout - url: http://flagger-loadtester.test/ - timeout: 15s - metadata: - cmd: "hey -z 1m -q 5 -c 2 http://podinfo-canary.test:9898/" - - name: "promotion gate" - type: confirm-promotion - url: http://flagger-loadtester.test/gate/approve - - name: "notify" - type: post-rollout - url: http://telegram.bot:8080/ - timeout: 5s - metadata: - some: "message" - - name: "rollback gate" - type: rollback - url: http://flagger-loadtester.test/rollback/check - - name: "send to Slack" - type: event - url: http://event-recevier.notifications/slack -``` - -> **Note** that the sum of all rollout webhooks timeouts should be lower than the analysis interval. - -Webhook payload \(HTTP POST\): - -```javascript -{ - "name": "podinfo", - "namespace": "test", - "phase": "Progressing", - "metadata": { - "test": "all", - "token": "16688eb5e9f289f1991c" - } -} -``` - -Response status codes: - -* 200-202 - advance canary by increasing the traffic weight -* timeout or non-2xx - halt advancement and increment failed checks - -On a non-2xx response Flagger will include the response body \(if any\) in the failed checks log and Kubernetes events. - -Event payload \(HTTP POST\): - -```javascript -{ - "name": "string (canary name)", - "namespace": "string (canary namespace)", - "phase": "string (canary phase)", - "metadata": { - "eventMessage": "string (canary event message)", - "eventType": "string (canary event type)", - "timestamp": "string (unix timestamp ms)" - } -} -``` - -The event receiver can create alerts based on the received phase \(possible values: `Initialized`, `Waiting`, `Progressing`, `Promoting`, `Finalising`, `Succeeded` or `Failed`\). - -## Load Testing - -For workloads that are not receiving constant traffic Flagger can be configured with a webhook, that when called, will start a load test for the target workload. If the target workload doesn't receive any traffic during the canary analysis, Flagger metric checks will fail with "no values found for metric request-success-rate". - -Flagger comes with a load testing service based on [rakyll/hey](https://github.com/rakyll/hey) that generates traffic during analysis when configured as a webhook. - -![Flagger Load Testing Webhook](https://raw.githubusercontent.com/weaveworks/flagger/master/docs/diagrams/flagger-load-testing.png) - -First you need to deploy the load test runner in a namespace with sidecar injection enabled: - -```bash -export REPO=https://raw.githubusercontent.com/weaveworks/flagger/master - -kubectl -n test apply -f ${REPO}/artifacts/loadtester/deployment.yaml -kubectl -n test apply -f ${REPO}/artifacts/loadtester/service.yaml -``` - -Or by using Helm: - -```bash -helm repo add flagger https://flagger.app - -helm upgrade -i flagger-loadtester flagger/loadtester \ ---namespace=test \ ---set cmd.timeout=1h -``` - -When deployed the load tester API will be available at `http://flagger-loadtester.test/`. - -Now you can add webhooks to the canary analysis spec: - -```yaml -webhooks: - - name: load-test-get - url: http://flagger-loadtester.test/ - timeout: 5s - metadata: - type: cmd - cmd: "hey -z 1m -q 10 -c 2 http://podinfo-canary.test:9898/" - - name: load-test-post - url: http://flagger-loadtester.test/ - timeout: 5s - metadata: - type: cmd - cmd: "hey -z 1m -q 10 -c 2 -m POST -d '{test: 2}' http://podinfo-canary.test:9898/echo" -``` - -When the canary analysis starts, Flagger will call the webhooks and the load tester will run the `hey` commands in the background, if they are not already running. This will ensure that during the analysis, the `podinfo-canary.test` service will receive a steady stream of GET and POST requests. - -If your workload is exposed outside the mesh you can point `hey` to the public URL and use HTTP2. - -```yaml -webhooks: - - name: load-test-get - url: http://flagger-loadtester.test/ - timeout: 5s - metadata: - type: cmd - cmd: "hey -z 1m -q 10 -c 2 -h2 https://podinfo.example.com/" -``` - -For gRPC services you can use [bojand/ghz](https://github.com/bojand/ghz) which is a similar tool to Hey but for gPRC: - -```yaml -webhooks: - - name: grpc-load-test - url: http://flagger-loadtester.test/ - timeout: 5s - metadata: - type: cmd - cmd: "ghz -z 1m -q 10 -c 2 --insecure podinfo.test:9898" -``` - -`ghz` uses reflection to identify which gRPC method to call. If you do not wish to enable reflection for your gRPC service you can implement a standardized health check from the [grpc-proto](https://github.com/grpc/grpc-proto) library. To use this [health check schema](https://github.com/grpc/grpc-proto/blob/master/grpc/health/v1/health.proto) without reflection you can pass a parameter to `ghz` like this - -```yaml -webhooks: - - name: grpc-load-test-no-reflection - url: http://flagger-loadtester.test/ - timeout: 5s - metadata: - type: cmd - cmd: "ghz --insecure --proto=/tmp/ghz/health.proto --call=grpc.health.v1.Health/Check podinfo.test:9898" -``` - -The load tester can run arbitrary commands as long as the binary is present in the container image. For example if you you want to replace `hey` with another CLI, you can create your own Docker image: - -```text -FROM weaveworks/flagger-loadtester: - -RUN curl -Lo /usr/local/bin/my-cli https://github.com/user/repo/releases/download/ver/my-cli \ - && chmod +x /usr/local/bin/my-cli -``` - -## Load Testing Delegation - -The load tester can also forward testing tasks to external tools, by now [nGrinder](https://github.com/naver/ngrinder) is supported. - -To use this feature, add a load test task of type 'ngrinder' to the canary analysis spec: - -```yaml -webhooks: - - name: load-test-post - url: http://flagger-loadtester.test/ - timeout: 5s - metadata: - # type of this load test task, cmd or ngrinder - type: ngrinder - # base url of your nGrinder controller server - server: http://ngrinder-server:port - # id of the test to clone from, the test must have been defined. - clone: 100 - # user name and base64 encoded password to authenticate against the nGrinder server - username: admin - passwd: YWRtaW4= - # the interval between between nGrinder test status polling, default to 1s - pollInterval: 5s -``` - -When the canary analysis starts, the load tester will initiate a [clone\_and\_start request](https://github.com/naver/ngrinder/wiki/REST-API-PerfTest) to the nGrinder server and start a new performance test. the load tester will periodically poll the nGrinder server for the status of the test, and prevent duplicate requests from being sent in subsequent analysis loops. - -## Integration Testing - -Flagger comes with a testing service that can run Helm tests or Bats tests when configured as a webhook. - -Deploy the Helm test runner in the `kube-system` namespace using the `tiller` service account: - -```bash -helm repo add flagger https://flagger.app - -helm upgrade -i flagger-helmtester flagger/loadtester \ ---namespace=kube-system \ ---set serviceAccountName=tiller -``` - -When deployed the Helm tester API will be available at `http://flagger-helmtester.kube-system/`. - -Now you can add pre-rollout webhooks to the canary analysis spec: - -```yaml - canaryAnalysis: - webhooks: - - name: "smoke test" - type: pre-rollout - url: http://flagger-helmtester.kube-system/ - timeout: 3m - metadata: - type: "helm" - cmd: "test {{ .Release.Name }} --cleanup" -``` - -When the canary analysis starts, Flagger will call the pre-rollout webhooks before routing traffic to the canary. If the helm test fails, Flagger will retry until the analysis threshold is reached and the canary is rolled back. - -If you are using Helm v3, you'll have to create a dedicated service account and add the release namespace to the test command: - -```yaml - canaryAnalysis: - webhooks: - - name: "smoke test" - type: pre-rollout - url: http://flagger-helmtester.kube-system/ - timeout: 3m - metadata: - type: "helmv3" - cmd: "test run {{ .Release.Name }} --cleanup -n {{ .Release.Namespace }}" -``` - -As an alternative to Helm you can use the [Bash Automated Testing System](https://github.com/bats-core/bats-core) to run your tests. - -```yaml - canaryAnalysis: - webhooks: - - name: "acceptance tests" - type: pre-rollout - url: http://flagger-batstester.default/ - timeout: 5m - metadata: - type: "bash" - cmd: "bats /tests/acceptance.bats" -``` - -Note that you should create a ConfigMap with your Bats tests and mount it inside the tester container. - -## Manual Gating - -For manual approval of a canary deployment you can use the `confirm-rollout` and `confirm-promotion` webhooks. The confirmation rollout hooks are executed before the pre-rollout hooks. Flagger will halt the canary traffic shifting and analysis until the confirm webhook returns HTTP status 200. - -For manual rollback of a canary deployment you can use the `rollback` webhook. The rollback hook will be called during the analysis and confirmation states. If a rollback webhook returns a successful HTTP status code, Flagger will shift all traffic back to the primary instance and fail the canary. - -Manual gating with Flagger's tester: - -```yaml - canaryAnalysis: - webhooks: - - name: "gate" - type: confirm-rollout - url: http://flagger-loadtester.test/gate/halt -``` - -The `/gate/halt` returns HTTP 403 thus blocking the rollout. - -If you have notifications enabled, Flagger will post a message to Slack or MS Teams if a canary rollout is waiting for approval. - -Change the URL to `/gate/approve` to start the canary analysis: - -```yaml - canaryAnalysis: - webhooks: - - name: "gate" - type: confirm-rollout - url: http://flagger-loadtester.test/gate/approve -``` - -Manual gating can be driven with Flagger's tester API. Set the confirmation URL to `/gate/check`: - -```yaml - canaryAnalysis: - webhooks: - - name: "ask for confirmation" - type: confirm-rollout - url: http://flagger-loadtester.test/gate/check -``` - -By default the gate is closed, you can start or resume the canary rollout with: - -```bash -kubectl -n test exec -it flagger-loadtester-xxxx-xxxx sh - -curl -d '{"name": "podinfo","namespace":"test"}' http://localhost:8080/gate/open -``` - -You can pause the rollout at any time with: - -```bash -curl -d '{"name": "podinfo","namespace":"test"}' http://localhost:8080/gate/close -``` - -If a canary analysis is paused the status will change to waiting: - -```bash -kubectl get canary/podinfo - -NAME STATUS WEIGHT -podinfo Waiting 0 -``` - -The `confirm-promotion` hook type can be used to manually approve the canary promotion. While the promotion is paused, Flagger will continue to run the metrics checks and load tests. - -```yaml - canaryAnalysis: - webhooks: - - name: "promotion gate" - type: confirm-promotion - url: http://flagger-loadtester.test/gate/halt -``` - -The `rollback` hook type can be used to manually rollback the canary promotion. As with gating, rollbacks can be driven with Flagger's tester API by setting the rollback URL to `/rollback/check` - -```yaml - canaryAnalysis: - webhooks: - - name: "rollback" - type: rollback - url: http://flagger-loadtester.test/rollback/check -``` - -By default rollback is closed, you can rollback a canary rollout with: - -```bash -kubectl -n test exec -it flagger-loadtester-xxxx-xxxx sh - -curl -d '{"name": "podinfo","namespace":"test"}' http://localhost:8080/rollback/open -``` - -You can close the rollback with: - -```bash curl -d '{"name": "podinfo","namespace":"test"}' http://localhost:8080/rollback/close`` - -If you have notifications enabled, Flagger will post a message to Slack or MS Teams if a canary promotion is waiting for approval. - diff --git a/docs/gitbook/install/flagger-install-on-kubernetes.md b/docs/gitbook/install/flagger-install-on-kubernetes.md index 5478d9ca2..48bdc5179 100644 --- a/docs/gitbook/install/flagger-install-on-kubernetes.md +++ b/docs/gitbook/install/flagger-install-on-kubernetes.md @@ -30,7 +30,11 @@ helm upgrade -i flagger flagger/flagger \ --set metricsServer=http://prometheus:9090 ``` -For Istio multi-cluster shared control plane you can install Flagger on each remote cluster and set the Istio control plane host cluster kubeconfig: +Note that Flagger depends on Istio telemetry and Prometheus, if you're installing Istio with istioctl +then you should be using the [default profile](https://istio.io/docs/setup/additional-setup/config-profiles/). + +For Istio multi-cluster shared control plane you can install Flagger +on each remote cluster and set the Istio control plane host cluster kubeconfig: ```bash helm upgrade -i flagger flagger/flagger \ @@ -42,7 +46,9 @@ helm upgrade -i flagger flagger/flagger \ --set istio.kubeconfig.key=kubeconfig ``` -Note that the Istio kubeconfig must be stored in a Kubernetes secret with a data key named `kubeconfig`. For more details on how to configure Istio multi-cluster credentials read the [Istio docs](https://istio.io/docs/setup/install/multicluster/shared-vpn/#credentials). +Note that the Istio kubeconfig must be stored in a Kubernetes secret with a data key named `kubeconfig`. +For more details on how to configure Istio multi-cluster credentials +read the [Istio docs](https://istio.io/docs/setup/install/multicluster/shared-vpn/#credentials). Deploy Flagger for Linkerd: @@ -114,7 +120,8 @@ helm delete flagger The command removes all the Kubernetes components associated with the chart and deletes the release. -> **Note** that on uninstall the Canary CRD will not be removed. Deleting the CRD will make Kubernetes remove all the objects owned by Flagger like Istio virtual services, Kubernetes deployments and ClusterIP services. +> **Note** that on uninstall the Canary CRD will not be removed. Deleting the CRD will make Kubernetes +>remove all the objects owned by Flagger like Istio virtual services, Kubernetes deployments and ClusterIP services. If you want to remove all the objects created by Flagger you have delete the Canary CRD with kubectl: @@ -169,7 +176,8 @@ kubectl apply -k github.com/weaveworks/flagger//kustomize/istio This deploys Flagger in the `istio-system` namespace and sets the metrics server URL to Istio's Prometheus instance. -Note that you'll need kubectl 1.14 to run the above the command or you can download the [kustomize binary](https://github.com/kubernetes-sigs/kustomize/releases) and run: +Note that you'll need kubectl 1.14 to run the above the command or you can download +the [kustomize binary](https://github.com/kubernetes-sigs/kustomize/releases) and run: ```bash kustomize build github.com/weaveworks/flagger//kustomize/istio | kubectl apply -f - @@ -205,14 +213,16 @@ Install Flagger and Prometheus: kubectl apply -k github.com/weaveworks/flagger//kustomize/kubernetes ``` -This deploys Flagger and Prometheus in the `flagger-system` namespace, sets the metrics server URL to `http://flagger-prometheus.flagger-system:9090` and the mesh provider to `kubernetes`. +This deploys Flagger and Prometheus in the `flagger-system` namespace, sets the metrics server URL +to `http://flagger-prometheus.flagger-system:9090` and the mesh provider to `kubernetes`. -The Prometheus instance has a two hours data retention and is configured to scrape all pods in your cluster that have the `prometheus.io/scrape: "true"` annotation. +The Prometheus instance has a two hours data retention and is configured to scrape all pods in your cluster +that have the `prometheus.io/scrape: "true"` annotation. To target a different provider you can specify it in the canary custom resource: ```yaml -apiVersion: flagger.app/v1alpha3 +apiVersion: flagger.app/v1beta1 kind: Canary metadata: name: app @@ -265,5 +275,6 @@ Install Flagger with Slack: kubectl apply -k . ``` -If you want to use MS Teams instead of Slack, replace `-slack-url` with `-msteams-url` and set the webhook address to `https://outlook.office.com/webhook/YOUR/TEAMS/WEBHOOK`. +If you want to use MS Teams instead of Slack, replace `-slack-url` with `-msteams-url` and set the webhook address +to `https://outlook.office.com/webhook/YOUR/TEAMS/WEBHOOK`. diff --git a/docs/gitbook/tutorials/appmesh-progressive-delivery.md b/docs/gitbook/tutorials/appmesh-progressive-delivery.md index cf2d133c7..4ee1fcb23 100644 --- a/docs/gitbook/tutorials/appmesh-progressive-delivery.md +++ b/docs/gitbook/tutorials/appmesh-progressive-delivery.md @@ -51,7 +51,7 @@ helm upgrade -i flagger-loadtester flagger/loadtester \ Create a canary custom resource: ```yaml -apiVersion: flagger.app/v1alpha3 +apiVersion: flagger.app/v1beta1 kind: Canary metadata: name: podinfo @@ -92,7 +92,7 @@ spec: perTryTimeout: 5s retryOn: "gateway-error,client-error,stream-error" # define the canary analysis timing and KPIs - canaryAnalysis: + analysis: # schedule interval (default 60s) interval: 1m # max number of failed metric checks before rollback @@ -108,12 +108,14 @@ spec: - name: request-success-rate # minimum req success rate (non 5xx responses) # percentage (0-100) - threshold: 99 + thresholdRange: + min: 99 interval: 1m - name: request-duration # maximum req duration P99 # milliseconds - threshold: 500 + thresholdRange: + max: 500 interval: 30s # testing (optional) webhooks: @@ -329,7 +331,7 @@ Besides weighted routing, Flagger can be configured to route traffic to the cana Edit the canary analysis, remove the max/step weight and add the match conditions and iterations: ```yaml - canaryAnalysis: + analysis: interval: 1m threshold: 5 iterations: 10 @@ -389,3 +391,4 @@ Routing all traffic to primary Promotion completed! Scaling down podinfo.test ``` +For an in-depth look at the analysis process read the [usage docs](../usage/how-it-works.md). diff --git a/docs/gitbook/tutorials/contour-progressive-delivery.md b/docs/gitbook/tutorials/contour-progressive-delivery.md index 597607990..1e61ff956 100644 --- a/docs/gitbook/tutorials/contour-progressive-delivery.md +++ b/docs/gitbook/tutorials/contour-progressive-delivery.md @@ -16,13 +16,13 @@ kubectl apply -f https://projectcontour.io/quickstart/contour.yaml The above command will deploy Contour and an Envoy daemonset in the `projectcontour` namespace. -Install Flagger using Kustomize \(kubectl 1.14\) in the `projectcontour` namespace: +Install Flagger using Kustomize (kubectl 1.14) in the `projectcontour` namespace: ```bash kubectl apply -k github.com/weaveworks/flagger//kustomize/contour ``` -The above command will deploy Flagger and Prometheus configured to scrape the Contour's Envoy instances. You can also enable Slack or MS Teams notifications, see the Kustomize install [docs](https://docs.flagger.app/install/flagger-install-on-kubernetes#install-flagger-with-kustomize). +The above command will deploy Flagger and Prometheus configured to scrape the Contour's Envoy instances. Or you can install Flagger using Helm: @@ -32,15 +32,17 @@ helm repo add flagger https://flagger.app helm upgrade -i flagger flagger/flagger \ --namespace projectcontour \ --set meshProvider=contour \ ---set prometheus.install=true \ ---set slack.url=https://hooks.slack.com/services/YOUR/SLACK/WEBHOOK \ ---set slack.channel=general \ ---set slack.user=flagger +--set prometheus.install=true ``` +You can also enable Slack, Discord, Rocket or MS Teams notifications, +see the alerting [docs](../usage/alerting.md). + ## Bootstrap -Flagger takes a Kubernetes deployment and optionally a horizontal pod autoscaler \(HPA\), then creates a series of objects \(Kubernetes deployments, ClusterIP services and Contour HTTPProxy\). These objects expose the application in the cluster and drive the canary analysis and promotion. +Flagger takes a Kubernetes deployment and optionally a horizontal pod autoscaler (HPA), +then creates a series of objects (Kubernetes deployments, ClusterIP services and Contour HTTPProxy). +These objects expose the application in the cluster and drive the canary analysis and promotion. Create a test namespace: @@ -60,10 +62,10 @@ Create a deployment and a horizontal pod autoscaler: kubectl apply -k github.com/weaveworks/flagger//kustomize/podinfo ``` -Create a canary custom resource \(replace `app.example.com` with your own domain\): +Create a canary custom resource (replace `app.example.com` with your own domain): ```yaml -apiVersion: flagger.app/v1alpha3 +apiVersion: flagger.app/v1beta1 kind: Canary metadata: name: podinfo @@ -91,7 +93,7 @@ spec: attempts: 3 perTryTimeout: 5s # define the canary analysis timing and KPIs - canaryAnalysis: + analysis: # schedule interval (default 60s) interval: 30s # max number of failed metric checks before rollback @@ -107,11 +109,13 @@ spec: - name: request-success-rate # minimum req success rate (non 5xx responses) # percentage (0-100) - threshold: 99 + thresholdRange: + min: 99 interval: 1m - name: request-duration # maximum req duration P99 in milliseconds - threshold: 500 + thresholdRange: + max: 500 interval: 30s # testing webhooks: @@ -155,7 +159,9 @@ service/podinfo-primary httpproxy.projectcontour.io/podinfo ``` -After the boostrap, the podinfo deployment will be scaled to zero and the traffic to `podinfo.test` will be routed to the primary pods. During the canary analysis, the `podinfo-canary.test` address can be used to target directly the canary pods. +After the boostrap, the podinfo deployment will be scaled to zero and the traffic to `podinfo.test` +will be routed to the primary pods. +During the canary analysis, the `podinfo-canary.test` address can be used to target directly the canary pods. ## Expose the app outside the cluster @@ -167,9 +173,11 @@ export ADDRESS="$(kubectl -n projectcontour get svc/envoy -ojson \ echo $ADDRESS ``` -Configure your DNS server with a CNAME record \(AWS\) or A record \(GKE/AKS/DOKS\) and point a domain e.g. `app.example.com` to the LB address. +Configure your DNS server with a CNAME record \(AWS\) or A record (GKE/AKS/DOKS) +and point a domain e.g. `app.example.com` to the LB address. -Create a HTTPProxy definition and include the podinfo proxy generated by Flagger \(replace `app.example.com` with your own domain\): +Create a HTTPProxy definition and include the podinfo proxy generated by Flagger +(replace `app.example.com` with your own domain): ```yaml apiVersion: projectcontour.io/v1 @@ -205,17 +213,21 @@ podinfo-ingress app.example.com valid Now you can access podinfo UI using your domain address. -Note that you should be using HTTPS when exposing production workloads on internet. You can obtain free TLS certs from Let's Encrypt, read this [guide](https://github.com/stefanprodan/eks-contour-ingress) on how to configure cert-manager to secure Contour with TLS certificates. +Note that you should be using HTTPS when exposing production workloads on internet. +You can obtain free TLS certs from Let's Encrypt, read this [guide](https://github.com/stefanprodan/eks-contour-ingress) +on how to configure cert-manager to secure Contour with TLS certificates. ## Automated canary promotion -Flagger implements a control loop that gradually shifts traffic to the canary while measuring key performance indicators like HTTP requests success rate, requests average duration and pod health. Based on analysis of the KPIs a canary is promoted or aborted. +Flagger implements a control loop that gradually shifts traffic to the canary while measuring +key performance indicators like HTTP requests success rate, requests average duration and pod health. +Based on analysis of the KPIs a canary is promoted or aborted. ![Flagger Canary Stages](https://raw.githubusercontent.com/weaveworks/flagger/master/docs/diagrams/flagger-canary-steps.png) A canary deployment is triggered by changes in any of the following objects: -* Deployment PodSpec \(container image, command, ports, env, resources, etc\) +* Deployment PodSpec (container image, command, ports, env, resources, etc) * ConfigMaps and Secrets mounted as volumes or mapped to environment variables Trigger a canary deployment by updating the container image: @@ -300,7 +312,8 @@ Generate latency: watch -n 1 curl http://app.example.com/delay/1 ``` -When the number of failed checks reaches the canary analysis threshold, the traffic is routed back to the primary, the canary is scaled to zero and the rollout is marked as failed. +When the number of failed checks reaches the canary analysis threshold, the traffic is routed back to the primary, +the canary is scaled to zero and the rollout is marked as failed. ```text kubectl -n projectcontour logs deploy/flagger -f | jq .msg @@ -319,20 +332,23 @@ Rolling back podinfo.test failed checks threshold reached 5 Canary failed! Scaling down podinfo.test ``` -If you’ve enabled the Slack notifications, you’ll receive a message if the progress deadline is exceeded, or if the analysis reached the maximum number of failed checks: +If you’ve enabled the Slack notifications, you’ll receive a message if the progress deadline is exceeded, +or if the analysis reached the maximum number of failed checks: ![Flagger Slack Notifications](https://raw.githubusercontent.com/weaveworks/flagger/master/docs/screens/slack-canary-failed.png) ## A/B Testing -Besides weighted routing, Flagger can be configured to route traffic to the canary based on HTTP match conditions. In an A/B testing scenario, you'll be using HTTP headers or cookies to target a certain segment of your users. This is particularly useful for frontend applications that require session affinity. +Besides weighted routing, Flagger can be configured to route traffic to the canary based on HTTP match conditions. +In an A/B testing scenario, you'll be using HTTP headers or cookies to target a certain segment of your users. +This is particularly useful for frontend applications that require session affinity. ![Flagger A/B Testing Stages](https://raw.githubusercontent.com/weaveworks/flagger/master/docs/diagrams/flagger-abtest-steps.png) Edit the canary analysis, remove the max/step weight and add the match conditions and iterations: ```yaml -canaryAnalysis: +analysis: interval: 1m threshold: 5 iterations: 10 @@ -421,3 +437,4 @@ match: suffix: "Firefox/71.0" ``` +For an in-depth look at the analysis process read the [usage docs](../usage/how-it-works.md). diff --git a/docs/gitbook/tutorials/crossover-progressive-delivery.md b/docs/gitbook/tutorials/crossover-progressive-delivery.md index 31ce7098d..8f92bfa02 100644 --- a/docs/gitbook/tutorials/crossover-progressive-delivery.md +++ b/docs/gitbook/tutorials/crossover-progressive-delivery.md @@ -64,7 +64,10 @@ helm upgrade -i flagger flagger/flagger \ ## Bootstrap -Flagger takes a Kubernetes deployment and optionally a horizontal pod autoscaler \(HPA\), then creates a series of objects \(Kubernetes deployments, ClusterIP services, SMI traffic splits\). These objects expose the application on the mesh and drive the canary analysis and promotion. There's no SMI object you need to create by yourself. +Flagger takes a Kubernetes deployment and optionally a horizontal pod autoscaler (HPA), +then creates a series of objects (Kubernetes deployments, ClusterIP services, SMI traffic splits). +These objects expose the application on the mesh and drive the canary analysis and promotion. +There's no SMI object you need to create by yourself. Create a deployment and a horizontal pod autoscaler: @@ -82,7 +85,7 @@ helm upgrade -i flagger-loadtester flagger/loadtester \ Create a canary custom resource: ```yaml -apiVersion: flagger.app/v1alpha3 +apiVersion: flagger.app/v1beta1 kind: Canary metadata: name: podinfo @@ -109,7 +112,7 @@ spec: # container port number or name (optional) targetPort: 9898 # define the canary analysis timing and KPIs - canaryAnalysis: + analysis: # schedule interval (default 60s) interval: 1m # max number of failed metric checks before rollback @@ -125,12 +128,14 @@ spec: - name: request-success-rate # minimum req success rate (non 5xx responses) # percentage (0-100) - threshold: 99 + thresholdRange: + min: 99 interval: 1m - name: request-duration # maximum req duration P99 # milliseconds - threshold: 500 + thresholdRange: + max: 500 interval: 30s # testing (optional) webhooks: @@ -171,17 +176,21 @@ service/podinfo-primary trafficsplits.split.smi-spec.io/podinfo ``` -After the boostrap, the podinfo deployment will be scaled to zero and the traffic to `podinfo.test` will be routed to the primary pods. During the canary analysis, the `podinfo-canary.test` address can be used to target directly the canary pods. +After the boostrap, the podinfo deployment will be scaled to zero and the traffic to `podinfo.test` +will be routed to the primary pods. During the canary analysis, +the `podinfo-canary.test` address can be used to target directly the canary pods. ## Automated canary promotion -Flagger implements a control loop that gradually shifts traffic to the canary while measuring key performance indicators like HTTP requests success rate, requests average duration and pod health. Based on analysis of the KPIs a canary is promoted or aborted, and the analysis result is published to Slack. +Flagger implements a control loop that gradually shifts traffic to the canary while measuring +key performance indicators like HTTP requests success rate, requests average duration and pod health. +Based on analysis of the KPIs a canary is promoted or aborted, and the analysis result is published to Slack. ![Flagger Canary Stages](https://raw.githubusercontent.com/weaveworks/flagger/master/docs/diagrams/flagger-canary-steps.png) A canary deployment is triggered by changes in any of the following objects: -* Deployment PodSpec \(container image, command, ports, env, resources, etc\) +* Deployment PodSpec (container image, command, ports, env, resources, etc) * ConfigMaps and Secrets mounted as volumes or mapped to environment variables Trigger a canary deployment by updating the container image: @@ -288,7 +297,8 @@ Generate latency: watch -n 1 curl -H 'Host: podinfo.test' http://envoy.test:10000/delay/1 ``` -When the number of failed checks reaches the canary analysis threshold, the traffic is routed back to the primary, the canary is scaled to zero and the rollout is marked as failed. +When the number of failed checks reaches the canary analysis threshold, the traffic is routed back to the primary, +the canary is scaled to zero and the rollout is marked as failed. ```text kubectl -n test logs deploy/flagger -f | jq .msg @@ -307,7 +317,8 @@ Rolling back podinfo.test failed checks threshold reached 5 Canary failed! Scaling down podinfo.test ``` -If you’ve enabled the Slack notifications, you’ll receive a message if the progress deadline is exceeded, or if the analysis reached the maximum number of failed checks: +If you’ve enabled the Slack notifications, you’ll receive a message if the progress deadline is exceeded, +or if the analysis reached the maximum number of failed checks: ![Flagger Slack Notifications](https://raw.githubusercontent.com/weaveworks/flagger/master/docs/screens/slack-canary-failed.png) diff --git a/docs/gitbook/tutorials/flagger-smi-istio.md b/docs/gitbook/tutorials/flagger-smi-istio.md index 902e3c16f..90291e48f 100644 --- a/docs/gitbook/tutorials/flagger-smi-istio.md +++ b/docs/gitbook/tutorials/flagger-smi-istio.md @@ -106,7 +106,7 @@ kubectl apply -k github.com/weaveworks/flagger//kustomize/tester Create a canary custom resource \(replace example.com with your own domain\): ```yaml -apiVersion: flagger.app/v1alpha3 +apiVersion: flagger.app/v1beta1 kind: Canary metadata: name: podinfo @@ -134,7 +134,7 @@ spec: # Istio virtual service host names (optional) hosts: - app.example.com - canaryAnalysis: + analysis: # schedule interval (default 60s) interval: 10s # max number of failed metric checks before rollback @@ -149,12 +149,14 @@ spec: - name: request-success-rate # minimum req success rate (non 5xx responses) # percentage (0-100) - threshold: 99 + thresholdRange: + min: 99 interval: 1m - name: request-duration # maximum req duration P99 # milliseconds - threshold: 500 + thresholdRange: + max: 500 interval: 30s # generate traffic during analysis webhooks: diff --git a/docs/gitbook/tutorials/gloo-progressive-delivery.md b/docs/gitbook/tutorials/gloo-progressive-delivery.md index 4e3624b63..d95e434c4 100644 --- a/docs/gitbook/tutorials/gloo-progressive-delivery.md +++ b/docs/gitbook/tutorials/gloo-progressive-delivery.md @@ -28,20 +28,11 @@ helm upgrade -i flagger flagger/flagger \ --set meshProvider=gloo ``` -Optionally you can enable Slack notifications: - -```bash -helm upgrade -i flagger flagger/flagger \ ---reuse-values \ ---namespace gloo-system \ ---set slack.url=https://hooks.slack.com/services/YOUR/SLACK/WEBHOOK \ ---set slack.channel=general \ ---set slack.user=flagger -``` - ## Bootstrap -Flagger takes a Kubernetes deployment and optionally a horizontal pod autoscaler \(HPA\), then creates a series of objects \(Kubernetes deployments, ClusterIP services and Gloo upstream groups\). These objects expose the application outside the cluster and drive the canary analysis and promotion. +Flagger takes a Kubernetes deployment and optionally a horizontal pod autoscaler (HPA), +then creates a series of objects (Kubernetes deployments, ClusterIP services and Gloo upstream groups). +These objects expose the application outside the cluster and drive the canary analysis and promotion. Create a test namespace: @@ -61,7 +52,8 @@ Deploy the load testing service to generate traffic during the canary analysis: kubectl -n test apply -k github.com/weaveworks/flagger//kustomize/tester ``` -Create an virtual service definition that references an upstream group that will be generated by Flagger \(replace `app.example.com` with your own domain\): +Create an virtual service definition that references an upstream group that will be generated by Flagger +(replace `app.example.com` with your own domain): ```yaml apiVersion: gateway.solo.io/v1 @@ -88,10 +80,10 @@ Save the above resource as podinfo-virtualservice.yaml and then apply it: kubectl apply -f ./podinfo-virtualservice.yaml ``` -Create a canary custom resource \(replace `app.example.com` with your own domain\): +Create a canary custom resource (replace `app.example.com` with your own domain): ```yaml -apiVersion: flagger.app/v1alpha3 +apiVersion: flagger.app/v1beta1 kind: Canary metadata: name: podinfo @@ -113,7 +105,7 @@ spec: port: 9898 # container port number or name (optional) targetPort: 9898 - canaryAnalysis: + analysis: # schedule interval (default 60s) interval: 10s # max number of failed metric checks before rollback @@ -129,12 +121,14 @@ spec: - name: request-success-rate # minimum req success rate (non 5xx responses) # percentage (0-100) - threshold: 99 + thresholdRange: + min: 99 interval: 1m - name: request-duration # maximum req duration P99 # milliseconds - threshold: 500 + thresholdRange: + max: 500 interval: 30s # testing (optional) webhooks: @@ -188,7 +182,9 @@ podinfo Initialized 0 2019-05-17T08:09:51Z ## Automated canary promotion -Flagger implements a control loop that gradually shifts traffic to the canary while measuring key performance indicators like HTTP requests success rate, requests average duration and pod health. Based on analysis of the KPIs a canary is promoted or aborted, and the analysis result is published to Slack. +Flagger implements a control loop that gradually shifts traffic to the canary while measuring +key performance indicators like HTTP requests success rate, requests average duration and pod health. +Based on analysis of the KPIs a canary is promoted or aborted, and the analysis result is published to Slack. ![Flagger Canary Stages](https://raw.githubusercontent.com/weaveworks/flagger/master/docs/diagrams/flagger-canary-steps.png) @@ -265,7 +261,8 @@ Generate high latency: watch curl -H 'Host: app.example.com' http://gateway-proxy-v2.gloo-system/delay/2 ``` -When the number of failed checks reaches the canary analysis threshold, the traffic is routed back to the primary, the canary is scaled to zero and the rollout is marked as failed. +When the number of failed checks reaches the canary analysis threshold, the traffic is routed back to the primary, +the canary is scaled to zero and the rollout is marked as failed. ```text kubectl -n test describe canary/podinfo @@ -294,37 +291,57 @@ Events: The canary analysis can be extended with Prometheus queries. -The demo app is instrumented with Prometheus so you can create a custom check that will use the HTTP request duration histogram to validate the canary. +The demo app is instrumented with Prometheus so you can create a custom check that will use +the HTTP request duration histogram to validate the canary. + +Create a metric template and apply it on the cluster: + +```yaml +apiVersion: flagger.app/v1beta1 +kind: MetricTemplate +metadata: + name: not-found-percentage + namespace: test +spec: + provider: + type: prometheus + address: http://flagger-promethues.gloo-system:9090 + query: | + 100 - sum( + rate( + http_request_duration_seconds_count{ + kubernetes_namespace="{{ namespace }}", + kubernetes_pod_name=~"{{ target }}-[0-9a-zA-Z]+(-[0-9a-zA-Z]+)" + status!="{{ interval }}" + }[1m] + ) + ) + / + sum( + rate( + http_request_duration_seconds_count{ + kubernetes_namespace="{{ namespace }}", + kubernetes_pod_name=~"{{ target }}-[0-9a-zA-Z]+(-[0-9a-zA-Z]+)" + }[{{ interval }}] + ) + ) * 100 +``` Edit the canary analysis and add the following metric: ```yaml - canaryAnalysis: + analysis: metrics: - - name: "404s percentage" - threshold: 5 - query: | - 100 - sum( - rate( - http_request_duration_seconds_count{ - kubernetes_namespace="test", - kubernetes_pod_name=~"podinfo-[0-9a-zA-Z]+(-[0-9a-zA-Z]+)" - status!="404" - }[1m] - ) - ) - / - sum( - rate( - http_request_duration_seconds_count{ - kubernetes_namespace="test", - kubernetes_pod_name=~"podinfo-[0-9a-zA-Z]+(-[0-9a-zA-Z]+)" - }[1m] - ) - ) * 100 + - name: "404s percentage" + templateRef: + name: not-found-percentage + thresholdRange: + max: 5 + interval: 1m ``` -The above configuration validates the canary by checking if the HTTP 404 req/sec percentage is below 5 percent of the total traffic. If the 404s rate reaches the 5% threshold, then the canary fails. +The above configuration validates the canary by checking if the HTTP 404 req/sec percentage is +below 5 percent of the total traffic. If the 404s rate reaches the 5% threshold, then the canary fails. Trigger a canary deployment by updating the container image: @@ -357,5 +374,8 @@ Rolling back podinfo.test failed checks threshold reached 5 Canary failed! Scaling down podinfo.test ``` -If you have Slack configured, Flagger will send a notification with the reason why the canary failed. +If you have [alerting](../usage/alerting.md) configured, +Flagger will send a notification with the reason why the canary failed. + +For an in-depth look at the analysis process read the [usage docs](../usage/how-it-works.md). diff --git a/docs/gitbook/tutorials/istio-ab-testing.md b/docs/gitbook/tutorials/istio-ab-testing.md index deec896cd..e47afce8c 100644 --- a/docs/gitbook/tutorials/istio-ab-testing.md +++ b/docs/gitbook/tutorials/istio-ab-testing.md @@ -2,10 +2,48 @@ This guide shows you how to automate A/B testing with Istio and Flagger. -Besides weighted routing, Flagger can be configured to route traffic to the canary based on HTTP match conditions. In an A/B testing scenario, you'll be using HTTP headers or cookies to target a certain segment of your users. This is particularly useful for frontend applications that require session affinity. +Besides weighted routing, Flagger can be configured to route traffic to the canary based on HTTP match conditions. +In an A/B testing scenario, you'll be using HTTP headers or cookies to target a certain segment of your users. +This is particularly useful for frontend applications that require session affinity. ![Flagger A/B Testing Stages](https://raw.githubusercontent.com/weaveworks/flagger/master/docs/diagrams/flagger-abtest-steps.png) +## Prerequisites + +Flagger requires a Kubernetes cluster **v1.11** or newer and Istio **v1.0** or newer. + +Install Istio with telemetry support and Prometheus: + +```bash +istioctl manifest apply --set profile=default +``` + +Install Flagger using Kustomize (kubectl 1.14) in the `istio-system` namespace: + +```bash +kubectl apply -k github.com/weaveworks/flagger//kustomize/istio +``` + +Create an ingress gateway to expose the demo app outside of the mesh: + +```yaml +apiVersion: networking.istio.io/v1alpha3 +kind: Gateway +metadata: + name: public-gateway + namespace: istio-system +spec: + selector: + istio: ingressgateway + servers: + - port: + number: 80 + name: http + protocol: HTTP + hosts: + - "*" +``` + ## Bootstrap Create a test namespace with Istio sidecar injection enabled: @@ -30,7 +68,7 @@ kubectl apply -k github.com/weaveworks/flagger//kustomize/tester Create a canary custom resource \(replace example.com with your own domain\): ```yaml -apiVersion: flagger.app/v1alpha3 +apiVersion: flagger.app/v1beta1 kind: Canary metadata: name: podinfo @@ -63,7 +101,7 @@ spec: tls: # use ISTIO_MUTUAL when mTLS is enabled mode: DISABLE - canaryAnalysis: + analysis: # schedule interval (default 60s) interval: 1m # total number of iterations @@ -82,12 +120,14 @@ spec: - name: request-success-rate # minimum req success rate (non 5xx responses) # percentage (0-100) - threshold: 99 + thresholdRange: + min: 99 interval: 1m - name: request-duration # maximum req duration P99 # milliseconds - threshold: 500 + thresholdRange: + max: 500 interval: 30s # generate traffic during analysis webhooks: @@ -130,7 +170,7 @@ virtualservice.networking.istio.io/podinfo Trigger a canary deployment by updating the container image: ```bash -kubectl -n test set image deployment/abtest \ +kubectl -n test set image deployment/podinfo \ podinfod=stefanprodan/podinfo:3.1.1 ``` @@ -158,8 +198,8 @@ Events: Normal Synced 55s flagger Advance podinfo.test canary iteration 8/10 Normal Synced 45s flagger Advance podinfo.test canary iteration 9/10 Normal Synced 35s flagger Advance podinfo.test canary iteration 10/10 - Normal Synced 25s flagger Copying podinfo.test template spec to abtest-primary.test - Warning Synced 15s flagger Waiting for abtest-primary.test rollout to finish: 1 of 2 updated replicas are available + Normal Synced 25s flagger Copying podinfo.test template spec to podinfo-primary.test + Warning Synced 15s flagger Waiting for podinfo-primary.test rollout to finish: 1 of 2 updated replicas are available Normal Synced 5s flagger Promotion completed! Scaling down podinfo.test ``` @@ -171,7 +211,7 @@ You can monitor all canaries with: watch kubectl get canaries --all-namespaces NAMESPACE NAME STATUS WEIGHT LASTTRANSITIONTIME -test abtest Progressing 100 2019-03-16T14:05:07Z +test podinfo Progressing 100 2019-03-16T14:05:07Z prod frontend Succeeded 0 2019-03-15T16:15:07Z prod backend Failed 0 2019-03-14T17:05:07Z ``` @@ -192,10 +232,11 @@ Generate latency: watch curl -b 'type=insider' http://app.example.com/delay/1 ``` -When the number of failed checks reaches the canary analysis threshold, the traffic is routed back to the primary, the canary is scaled to zero and the rollout is marked as failed. +When the number of failed checks reaches the canary analysis threshold, the traffic is routed back to the primary, +the canary is scaled to zero and the rollout is marked as failed. ```text -kubectl -n test describe canary/abtest +kubectl -n test describe canary/podinfo Status: Failed Checks: 2 @@ -213,3 +254,7 @@ Events: Warning Synced 1m flagger Canary failed! Scaling down podinfo.test ``` +The above procedure can be extended with [custom metrics](../usage/metrics.md) checks, +[webhooks](../usage/webhooks.md), +[manual promotion](../usage/webhooks.md#manual-gating) approval and +[Slack or MS Teams](../usage/alerting.md) notifications. \ No newline at end of file diff --git a/docs/gitbook/tutorials/istio-progressive-delivery.md b/docs/gitbook/tutorials/istio-progressive-delivery.md index 5fc944f08..413f4b40b 100644 --- a/docs/gitbook/tutorials/istio-progressive-delivery.md +++ b/docs/gitbook/tutorials/istio-progressive-delivery.md @@ -4,9 +4,48 @@ This guide shows you how to use Istio and Flagger to automate canary deployments ![Flagger Canary Stages](https://raw.githubusercontent.com/weaveworks/flagger/master/docs/diagrams/flagger-canary-steps.png) +## Prerequisites + +Flagger requires a Kubernetes cluster **v1.11** or newer and Istio **v1.0** or newer. + +Install Istio with telemetry support and Prometheus: + +```bash +istioctl manifest apply --set profile=default +``` + +Install Flagger using Kustomize (kubectl 1.14) in the `istio-system` namespace: + +```bash +kubectl apply -k github.com/weaveworks/flagger//kustomize/istio +``` + +Create an ingress gateway to expose the demo app outside of the mesh: + +```yaml +apiVersion: networking.istio.io/v1alpha3 +kind: Gateway +metadata: + name: public-gateway + namespace: istio-system +spec: + selector: + istio: ingressgateway + servers: + - port: + number: 80 + name: http + protocol: HTTP + hosts: + - "*" +``` + ## Bootstrap -Flagger takes a Kubernetes deployment and optionally a horizontal pod autoscaler \(HPA\), then creates a series of objects \(Kubernetes deployments, ClusterIP services, Istio destination rules and virtual services\). These objects expose the application inside the mesh and drive the canary analysis and promotion. +Flagger takes a Kubernetes deployment and optionally a horizontal pod autoscaler (HPA), +then creates a series of objects (Kubernetes deployments, ClusterIP services, +Istio destination rules and virtual services). +These objects expose the application inside the mesh and drive the canary analysis and promotion. Create a test namespace with Istio sidecar injection enabled: @@ -27,10 +66,10 @@ Deploy the load testing service to generate traffic during the canary analysis: kubectl apply -k github.com/weaveworks/flagger//kustomize/tester ``` -Create a canary custom resource \(replace example.com with your own domain\): +Create a canary custom resource (replace example.com with your own domain): ```yaml -apiVersion: flagger.app/v1alpha3 +apiVersion: flagger.app/v1beta1 kind: Canary metadata: name: podinfo @@ -70,7 +109,7 @@ spec: attempts: 3 perTryTimeout: 1s retryOn: "gateway-error,connect-failure,refused-stream" - canaryAnalysis: + analysis: # schedule interval (default 60s) interval: 1m # max number of failed metric checks before rollback @@ -85,12 +124,14 @@ spec: - name: request-success-rate # minimum req success rate (non 5xx responses) # percentage (0-100) - threshold: 99 + thresholdRange: + min: 99 interval: 1m - name: request-duration # maximum req duration P99 # milliseconds - threshold: 500 + thresholdRange: + max: 500 interval: 30s # testing (optional) webhooks: @@ -114,7 +155,8 @@ Save the above resource as podinfo-canary.yaml and then apply it: kubectl apply -f ./podinfo-canary.yaml ``` -When the canary analysis starts, Flagger will call the pre-rollout webhooks before routing traffic to the canary. The canary analysis will run for five minutes while validating the HTTP metrics and rollout hooks every minute. +When the canary analysis starts, Flagger will call the pre-rollout webhooks before routing traffic to the canary. +The canary analysis will run for five minutes while validating the HTTP metrics and rollout hooks every minute. ![Flagger Canary Process](https://raw.githubusercontent.com/weaveworks/flagger/master/docs/diagrams/flagger-canary-hpa.png) @@ -224,7 +266,8 @@ Generate latency: watch curl http://podinfo-canary:9898/delay/1 ``` -When the number of failed checks reaches the canary analysis threshold, the traffic is routed back to the primary, the canary is scaled to zero and the rollout is marked as failed. +When the number of failed checks reaches the canary analysis threshold, the traffic is routed back to the primary, +the canary is scaled to zero and the rollout is marked as failed. ```text kubectl -n test describe canary/podinfo @@ -253,20 +296,23 @@ Events: ![Flagger Canary Traffic Shadowing](https://raw.githubusercontent.com/weaveworks/flagger/master/docs/diagrams/flagger-canary-traffic-mirroring.png) -For applications that perform read operations, Flagger can be configured to drive canary releases with traffic mirroring. Istio traffic mirroring will copy each incoming request, sending one request to the primary and one to the canary service. The response from the primary is sent back to the user and the response from the canary is discarded. Metrics are collected on both requests so that the deployment will only proceed if the canary metrics are within the threshold values. +For applications that perform read operations, Flagger can be configured to drive canary releases with traffic mirroring. +Istio traffic mirroring will copy each incoming request, sending one request to the primary and one to the canary service. +The response from the primary is sent back to the user and the response from the canary is discarded. +Metrics are collected on both requests so that the deployment will only proceed if the canary metrics are within the threshold values. -Note that mirroring should be used for requests that are **idempotent** or capable of being processed twice \(once by the primary and once by the canary\). +Note that mirroring should be used for requests that are **idempotent** or capable of being processed twice (once by the primary and once by the canary). -You can enable mirroring by replacing `stepWeight/maxWeight` with `iterations` and by setting `canaryAnalysis.mirror` to `true`: +You can enable mirroring by replacing `stepWeight/maxWeight` with `iterations` and by setting `analysis.mirror` to `true`: ```yaml -apiVersion: flagger.app/v1alpha3 +apiVersion: flagger.app/v1beta1 kind: Canary metadata: name: podinfo namespace: test spec: - canaryAnalysis: + analysis: # schedule interval interval: 1m # max number of failed metric checks before rollback @@ -277,10 +323,12 @@ spec: mirror: true metrics: - name: request-success-rate - threshold: 99 + thresholdRange: + min: 99 interval: 1m - name: request-duration - threshold: 500 + thresholdRange: + max: 500 interval: 1m webhooks: - name: acceptance-test @@ -299,7 +347,7 @@ spec: With the above configuration, Flagger will run a canary release with the following steps: -* detect new revision \(deployment spec, secrets or configmaps changes\) +* detect new revision (deployment spec, secrets or configmaps changes) * scale from zero the canary deployment * wait for the HPA to set the canary minimum replicas * check canary pods health @@ -311,7 +359,7 @@ With the above configuration, Flagger will run a canary release with the followi * abort the canary release if the metrics check failure threshold is reached * stop traffic mirroring after the number of iterations is reached * route live traffic to the canary pods -* promote the canary \(update the primary secrets, configmaps and deployment spec\) +* promote the canary (update the primary secrets, configmaps and deployment spec) * wait for the primary deployment rollout to finish * wait for the HPA to set the primary minimum replicas * check primary pods health @@ -319,5 +367,7 @@ With the above configuration, Flagger will run a canary release with the followi * scale to zero the canary * send notification with the canary analysis result -The above procedure can be extended with [custom metrics](https://docs.flagger.app/how-it-works#custom-metrics) checks, [webhooks](https://docs.flagger.app/how-it-works#webhooks), [manual promotion](https://docs.flagger.app/how-it-works#manual-gating) approval and [Slack or MS Teams](https://docs.flagger.app/usage/alerting) notifications. - +The above procedure can be extended with [custom metrics](../usage/metrics.md) checks, +[webhooks](../usage/webhooks.md), +[manual promotion](../usage/webhooks.md#manual-gating) approval and +[Slack or MS Teams](../usage/alerting.md) notifications. diff --git a/docs/gitbook/tutorials/kubernetes-blue-green.md b/docs/gitbook/tutorials/kubernetes-blue-green.md index be0bcde14..0b9cac29a 100644 --- a/docs/gitbook/tutorials/kubernetes-blue-green.md +++ b/docs/gitbook/tutorials/kubernetes-blue-green.md @@ -2,7 +2,9 @@ This guide shows you how to automate Blue/Green deployments with Flagger and Kubernetes. -For applications that are not deployed on a service mesh, Flagger can orchestrate Blue/Green style deployments with Kubernetes L4 networking. When using a service mesh blue/green can be used as specified [here](https://docs.flagger.app/how-it-works#blue-green-deployments). +For applications that are not deployed on a service mesh, Flagger can orchestrate Blue/Green style deployments +with Kubernetes L4 networking. When using a service mesh blue/green can be used as +specified [here](../usage/deployment-strategies.md). ![Flagger Blue/Green Stages](https://raw.githubusercontent.com/weaveworks/flagger/master/docs/diagrams/flagger-bluegreen-steps.png) @@ -42,7 +44,9 @@ helm upgrade -i flagger flagger/flagger \ ## Bootstrap -Flagger takes a Kubernetes deployment and optionally a horizontal pod autoscaler \(HPA\), then creates a series of objects \(Kubernetes deployment and ClusterIP services\). These objects expose the application inside the cluster and drive the canary analysis and Blue/Green promotion. +Flagger takes a Kubernetes deployment and optionally a horizontal pod autoscaler (HPA), +then creates a series of objects (Kubernetes deployment and ClusterIP services). +These objects expose the application inside the cluster and drive the canary analysis and Blue/Green promotion. Create a test namespace: @@ -53,23 +57,19 @@ kubectl create ns test Create a deployment and a horizontal pod autoscaler: ```bash -export REPO=https://raw.githubusercontent.com/weaveworks/flagger/master - -kubectl apply -f ${REPO}/artifacts/canaries/deployment.yaml -kubectl apply -f ${REPO}/artifacts/canaries/hpa.yaml +kubectl apply -k github.com/weaveworks/flagger//kustomize/podinfo ``` Deploy the load testing service to generate traffic during the analysis: ```bash -kubectl -n test apply -f ${REPO}/artifacts/loadtester/deployment.yaml -kubectl -n test apply -f ${REPO}/artifacts/loadtester/service.yaml +kubectl apply -k github.com/weaveworks/flagger//kustomize/tester ``` Create a canary custom resource: ```yaml -apiVersion: flagger.app/v1alpha3 +apiVersion: flagger.app/v1beta1 kind: Canary metadata: name: podinfo @@ -93,7 +93,7 @@ spec: service: port: 9898 portDiscovery: true - canaryAnalysis: + analysis: # schedule interval (default 60s) interval: 30s # max number of failed checks before rollback @@ -106,12 +106,14 @@ spec: - name: request-success-rate # minimum req success rate (non 5xx responses) # percentage (0-100) - threshold: 99 + thresholdRange: + min: 99 interval: 1m - name: request-duration # maximum req duration P99 # milliseconds - threshold: 500 + thresholdRange: + max: 500 interval: 30s # acceptance/load testing hooks webhooks: @@ -156,8 +158,10 @@ service/podinfo-primary Blue/Green scenario: -* on bootstrap, Flagger will create three ClusterIP services \(`app-primary`,`app-canary`, `app`\) and a shadow deployment named `app-primary` that represents the blue version -* when a new version is detected, Flagger would scale up the green version and run the conformance tests \(the tests should target the `app-canary` ClusterIP service to reach the green version\) +* on bootstrap, Flagger will create three ClusterIP services (`app-primary`,`app-canary`, `app`) +and a shadow deployment named `app-primary` that represents the blue version +* when a new version is detected, Flagger would scale up the green version and run the conformance tests +(the tests should target the `app-canary` ClusterIP service to reach the green version) * if the conformance tests are passing, Flagger would start the load tests and validate them with custom Prometheus queries * if the load test analysis is successful, Flagger will promote the new version to `app-primary` and scale down the green version @@ -253,37 +257,58 @@ Events: ## Custom metrics -The analysis can be extended with Prometheus queries. The demo app is instrumented with Prometheus so you can create a custom check that will use the HTTP request duration histogram to validate the canary \(green version\). +The analysis can be extended with Prometheus queries. The demo app is instrumented with Prometheus so you can +create a custom check that will use the HTTP request duration histogram to validate the canary (green version). + + +Create a metric template and apply it on the cluster: + +```yaml +apiVersion: flagger.app/v1beta1 +kind: MetricTemplate +metadata: + name: not-found-percentage + namespace: test +spec: + provider: + type: prometheus + address: http://flagger-promethues.flagger:9090 + query: | + 100 - sum( + rate( + http_request_duration_seconds_count{ + kubernetes_namespace="{{ namespace }}", + kubernetes_pod_name=~"{{ target }}-[0-9a-zA-Z]+(-[0-9a-zA-Z]+)" + status!="{{ interval }}" + }[1m] + ) + ) + / + sum( + rate( + http_request_duration_seconds_count{ + kubernetes_namespace="{{ namespace }}", + kubernetes_pod_name=~"{{ target }}-[0-9a-zA-Z]+(-[0-9a-zA-Z]+)" + }[{{ interval }}] + ) + ) * 100 +``` Edit the canary analysis and add the following metric: ```yaml - canaryAnalysis: + analysis: metrics: - - name: "404s percentage" - threshold: 5 - query: | - 100 - sum( - rate( - http_request_duration_seconds_count{ - kubernetes_namespace="test", - kubernetes_pod_name=~"podinfo-[0-9a-zA-Z]+(-[0-9a-zA-Z]+)" - status!="404" - }[1m] - ) - ) - / - sum( - rate( - http_request_duration_seconds_count{ - kubernetes_namespace="test", - kubernetes_pod_name=~"podinfo-[0-9a-zA-Z]+(-[0-9a-zA-Z]+)" - }[1m] - ) - ) * 100 + - name: "404s percentage" + templateRef: + name: not-found-percentage + thresholdRange: + max: 5 + interval: 1m ``` -The above configuration validates the canary \(green version\) by checking if the HTTP 404 req/sec percentage is below 5 percent of the total traffic. If the 404s rate reaches the 5% threshold, then the rollout is rolled back. +The above configuration validates the canary (green version) by checking if the HTTP 404 req/sec percentage is +below 5 percent of the total traffic. If the 404s rate reaches the 5% threshold, then the rollout is rolled back. Trigger a deployment by updating the container image: @@ -312,7 +337,8 @@ Rolling back podinfo.test failed checks threshold reached 2 Canary failed! Scaling down podinfo.test ``` -If you have Slack configured, Flagger will send a notification with the reason why the canary failed. +If you have [alerting](../usage/alerting.md) configured, +Flagger will send a notification with the reason why the canary failed. ## Conformance Testing with Helm @@ -333,7 +359,7 @@ When deployed the Helm tester API will be available at `http://flagger-helmteste Add a helm test pre-rollout hook to your chart: ```yaml - canaryAnalysis: + analysis: webhooks: - name: "conformance testing" type: pre-rollout @@ -344,5 +370,8 @@ Add a helm test pre-rollout hook to your chart: cmd: "test {{ .Release.Name }} --cleanup" ``` -When the canary analysis starts, Flagger will call the pre-rollout webhooks. If the helm test fails, Flagger will retry until the analysis threshold is reached and the canary is rolled back. +When the canary analysis starts, Flagger will call the pre-rollout webhooks. +If the helm test fails, Flagger will retry until the analysis threshold is reached and the canary is rolled back. + +For an in-depth look at the analysis process read the [usage docs](../usage/how-it-works.md). diff --git a/docs/gitbook/tutorials/linkerd-progressive-delivery.md b/docs/gitbook/tutorials/linkerd-progressive-delivery.md index 8d32efcb2..87c161d1c 100644 --- a/docs/gitbook/tutorials/linkerd-progressive-delivery.md +++ b/docs/gitbook/tutorials/linkerd-progressive-delivery.md @@ -16,11 +16,11 @@ kubectl apply -k github.com/weaveworks/flagger//kustomize/linkerd Note that you'll need kubectl 1.14 or newer to run the above command. -To enable Slack or MS Teams notifications, see Flagger's [install docs](https://docs.flagger.app/install/flagger-install-on-kubernetes) for Kustomize or Helm options. - ## Bootstrap -Flagger takes a Kubernetes deployment and optionally a horizontal pod autoscaler \(HPA\), then creates a series of objects \(Kubernetes deployments, ClusterIP services and SMI traffic split\). These objects expose the application inside the mesh and drive the canary analysis and promotion. +Flagger takes a Kubernetes deployment and optionally a horizontal pod autoscaler (HPA), +then creates a series of objects (Kubernetes deployments, ClusterIP services and SMI traffic split). +These objects expose the application inside the mesh and drive the canary analysis and promotion. Create a test namespace and enable Linkerd proxy injection: @@ -44,7 +44,7 @@ kubectl apply -k github.com/weaveworks/flagger//kustomize/podinfo Create a canary custom resource for the podinfo deployment: ```yaml -apiVersion: flagger.app/v1alpha3 +apiVersion: flagger.app/v1beta1 kind: Canary metadata: name: podinfo @@ -68,7 +68,7 @@ spec: port: 9898 # container port number or name (optional) targetPort: 9898 - canaryAnalysis: + analysis: # schedule interval (default 60s) interval: 30s # max number of failed metric checks before rollback @@ -84,12 +84,14 @@ spec: - name: request-success-rate # minimum req success rate (non 5xx responses) # percentage (0-100) - threshold: 99 + thresholdRange: + min: 99 interval: 1m - name: request-duration # maximum req duration P99 # milliseconds - threshold: 500 + thresholdRange: + max: 500 interval: 30s # testing (optional) webhooks: @@ -113,7 +115,8 @@ Save the above resource as podinfo-canary.yaml and then apply it: kubectl apply -f ./podinfo-canary.yaml ``` -When the canary analysis starts, Flagger will call the pre-rollout webhooks before routing traffic to the canary. The canary analysis will run for five minutes while validating the HTTP metrics and rollout hooks every half a minute. +When the canary analysis starts, Flagger will call the pre-rollout webhooks before routing traffic to the canary. +The canary analysis will run for five minutes while validating the HTTP metrics and rollout hooks every half a minute. After a couple of seconds Flagger will create the canary objects: @@ -133,11 +136,15 @@ service/podinfo-primary trafficsplits.split.smi-spec.io/podinfo ``` -After the boostrap, the podinfo deployment will be scaled to zero and the traffic to `podinfo.test` will be routed to the primary pods. During the canary analysis, the `podinfo-canary.test` address can be used to target directly the canary pods. +After the boostrap, the podinfo deployment will be scaled to zero and the traffic to `podinfo.test` +will be routed to the primary pods. +During the canary analysis, the `podinfo-canary.test` address can be used to target directly the canary pods. ## Automated canary promotion -Flagger implements a control loop that gradually shifts traffic to the canary while measuring key performance indicators like HTTP requests success rate, requests average duration and pod health. Based on analysis of the KPIs a canary is promoted or aborted, and the analysis result is published to Slack. +Flagger implements a control loop that gradually shifts traffic to the canary while measuring +key performance indicators like HTTP requests success rate, requests average duration and pod health. +Based on analysis of the KPIs a canary is promoted or aborted, and the analysis result is published to Slack. ![Flagger Canary Stages](https://raw.githubusercontent.com/weaveworks/flagger/master/docs/diagrams/flagger-canary-steps.png) @@ -198,7 +205,8 @@ prod backend Failed 0 2019-06-30T17:05:07Z ## Automated rollback -During the canary analysis you can generate HTTP 500 errors and high latency to test if Flagger pauses and rolls back the faulted version. +During the canary analysis you can generate HTTP 500 errors and high latency to +test if Flagger pauses and rolls back the faulted version. Trigger another canary deployment: @@ -225,7 +233,8 @@ Generate latency: watch -n 1 curl http://podinfo-canary.test:9898/delay/1 ``` -When the number of failed checks reaches the canary analysis threshold, the traffic is routed back to the primary, the canary is scaled to zero and the rollout is marked as failed. +When the number of failed checks reaches the canary analysis threshold, the traffic is routed back to the primary, +the canary is scaled to zero and the rollout is marked as failed. ```text kubectl -n test describe canary/podinfo @@ -256,7 +265,7 @@ The canary analysis can be extended with Prometheus queries. Let's a define a check for not found errors. Edit the canary analysis and add the following metric: ```yaml - canaryAnalysis: + analysis: metrics: - name: "404s percentage" threshold: 3 @@ -284,7 +293,9 @@ Let's a define a check for not found errors. Edit the canary analysis and add th * 100 ``` -The above configuration validates the canary version by checking if the HTTP 404 req/sec percentage is below three percent of the total traffic. If the 404s rate reaches the 3% threshold, then the analysis is aborted and the canary is marked as failed. +The above configuration validates the canary version by checking if the HTTP 404 req/sec percentage +is below three percent of the total traffic. +If the 404s rate reaches the 3% threshold, then the analysis is aborted and the canary is marked as failed. Trigger a canary deployment by updating the container image: @@ -329,7 +340,8 @@ helm upgrade -i nginx-ingress stable/nginx-ingress \ --namespace ingress-nginx ``` -Create an ingress definition for podinfo that rewrites the incoming header to the internal service name \(required by Linkerd\): +Create an ingress definition for podinfo that rewrites the incoming header +to the internal service name (required by Linkerd): ```yaml apiVersion: extensions/v1beta1 @@ -355,18 +367,23 @@ spec: servicePort: 9898 ``` -When using an ingress controller, the Linkerd traffic split does not apply to incoming traffic since NGINX in running outside of the mesh. In order to run a canary analysis for a frontend app, Flagger creates a shadow ingress and sets the NGINX specific annotations. +When using an ingress controller, the Linkerd traffic split does not apply to incoming traffic +since NGINX in running outside of the mesh. In order to run a canary analysis for a frontend app, +Flagger creates a shadow ingress and sets the NGINX specific annotations. ## A/B Testing -Besides weighted routing, Flagger can be configured to route traffic to the canary based on HTTP match conditions. In an A/B testing scenario, you'll be using HTTP headers or cookies to target a certain segment of your users. This is particularly useful for frontend applications that require session affinity. +Besides weighted routing, Flagger can be configured to route traffic to the canary based on HTTP match conditions. +In an A/B testing scenario, you'll be using HTTP headers or cookies to target a certain segment of your users. +This is particularly useful for frontend applications that require session affinity. ![Flagger Linkerd Ingress](https://raw.githubusercontent.com/weaveworks/flagger/master/docs/diagrams/flagger-nginx-linkerd.png) -Edit podinfo canary analysis, set the provider to `nginx`, add the ingress reference, remove the max/step weight and add the match conditions and iterations: +Edit podinfo canary analysis, set the provider to `nginx`, add the ingress reference, +remove the max/step weight and add the match conditions and iterations: ```yaml -apiVersion: flagger.app/v1alpha3 +apiVersion: flagger.app/v1beta1 kind: Canary metadata: name: podinfo @@ -389,7 +406,7 @@ spec: service: # container port port: 9898 - canaryAnalysis: + analysis: interval: 1m threshold: 10 iterations: 10 @@ -405,10 +422,12 @@ spec: # Linkerd Prometheus checks metrics: - name: request-success-rate - threshold: 99 + thresholdRange: + min: 99 interval: 1m - name: request-duration - threshold: 500 + thresholdRange: + max: 500 interval: 30s webhooks: - name: acceptance-test @@ -425,7 +444,8 @@ spec: cmd: "hey -z 2m -q 10 -c 2 -H 'Cookie: canary=always' http://app.example.com" ``` -The above configuration will run an analysis for ten minutes targeting users that have a `canary` cookie set to `always` or those that call the service using the `X-Canary: always` header. +The above configuration will run an analysis for ten minutes targeting users that have +a `canary` cookie set to `always` or those that call the service using the `X-Canary: always` header. **Note** that the load test now targets the external address and uses the canary cookie. @@ -459,3 +479,7 @@ Events: Promotion completed! Scaling down podinfo.test ``` +The above procedure can be extended with [custom metrics](../usage/metrics.md) checks, +[webhooks](../usage/webhooks.md), +[manual promotion](../usage/webhooks.md#manual-gating) approval and +[Slack or MS Teams](../usage/alerting.md) notifications. \ No newline at end of file diff --git a/docs/gitbook/tutorials/nginx-progressive-delivery.md b/docs/gitbook/tutorials/nginx-progressive-delivery.md index 8a8ce8c12..f6d9de2f5 100644 --- a/docs/gitbook/tutorials/nginx-progressive-delivery.md +++ b/docs/gitbook/tutorials/nginx-progressive-delivery.md @@ -44,7 +44,9 @@ helm upgrade -i flagger flagger/flagger \ ## Bootstrap -Flagger takes a Kubernetes deployment and optionally a horizontal pod autoscaler \(HPA\), then creates a series of objects \(Kubernetes deployments, ClusterIP services and canary ingress\). These objects expose the application outside the cluster and drive the canary analysis and promotion. +Flagger takes a Kubernetes deployment and optionally a horizontal pod autoscaler (HPA), +then creates a series of objects (Kubernetes deployments, ClusterIP services and canary ingress). +These objects expose the application outside the cluster and drive the canary analysis and promotion. Create a test namespace: @@ -96,7 +98,7 @@ kubectl apply -f ./podinfo-ingress.yaml Create a canary custom resource \(replace `app.example.com` with your own domain\): ```yaml -apiVersion: flagger.app/v1alpha3 +apiVersion: flagger.app/v1beta1 kind: Canary metadata: name: podinfo @@ -126,7 +128,7 @@ spec: port: 80 # container port number or name targetPort: 9898 - canaryAnalysis: + analysis: # schedule interval (default 60s) interval: 10s # max number of failed metric checks before rollback @@ -142,7 +144,8 @@ spec: - name: request-success-rate # minimum req success rate (non 5xx responses) # percentage (0-100) - threshold: 99 + thresholdRange: + min: 99 interval: 1m # testing (optional) webhooks: @@ -186,7 +189,9 @@ ingresses.extensions/podinfo-canary ## Automated canary promotion -Flagger implements a control loop that gradually shifts traffic to the canary while measuring key performance indicators like HTTP requests success rate, requests average duration and pod health. Based on analysis of the KPIs a canary is promoted or aborted, and the analysis result is published to Slack. +Flagger implements a control loop that gradually shifts traffic to the canary while measuring +key performance indicators like HTTP requests success rate, requests average duration and pod health. +Based on analysis of the KPIs a canary is promoted or aborted, and the analysis result is published to Slack or MS Teams. ![Flagger Canary Stages](https://raw.githubusercontent.com/weaveworks/flagger/master/docs/diagrams/flagger-canary-steps.png) @@ -257,7 +262,8 @@ Generate HTTP 500 errors: watch curl http://app.example.com/status/500 ``` -When the number of failed checks reaches the canary analysis threshold, the traffic is routed back to the primary, the canary is scaled to zero and the rollout is marked as failed. +When the number of failed checks reaches the canary analysis threshold, the traffic is routed back to the primary, +the canary is scaled to zero and the rollout is marked as failed. ```text kubectl -n test describe canary/podinfo @@ -286,30 +292,49 @@ Events: The canary analysis can be extended with Prometheus queries. -The demo app is instrumented with Prometheus so you can create a custom check that will use the HTTP request duration histogram to validate the canary. +The demo app is instrumented with Prometheus so you can create a custom check that will use the +HTTP request duration histogram to validate the canary. -Edit the canary analysis and add the following metric: +Create a metric template and apply it on the cluster: ```yaml - canaryAnalysis: +apiVersion: flagger.app/v1beta1 +kind: MetricTemplate +metadata: + name: latency + namespace: test +spec: + provider: + type: prometheus + address: http://flagger-promethues.ingress-nginx:9090 + query: | + histogram_quantile(0.99, + sum( + rate( + http_request_duration_seconds_bucket{ + kubernetes_namespace="{{ namespace }}", + kubernetes_pod_name=~"{{ target }}-[0-9a-zA-Z]+(-[0-9a-zA-Z]+)" + }[1m] + ) + ) by (le) + ) +``` + +Edit the canary analysis and add the latency check: + +```yaml + analysis: metrics: - name: "latency" - threshold: 0.5 + templateRef: + name: latency + thresholdRange: + max: 0.5 interval: 1m - query: | - histogram_quantile(0.99, - sum( - rate( - http_request_duration_seconds_bucket{ - kubernetes_namespace="test", - kubernetes_pod_name=~"podinfo-[0-9a-zA-Z]+(-[0-9a-zA-Z]+)" - }[1m] - ) - ) by (le) - ) ``` -The threshold is set to 500ms so if the average request duration in the last minute goes over half a second then the analysis will fail and the canary will not be promoted. +The threshold is set to 500ms so if the average request duration in the last minute goes over half a second +then the analysis will fail and the canary will not be promoted. Trigger a canary deployment by updating the container image: @@ -342,18 +367,20 @@ Rolling back podinfo.test failed checks threshold reached 5 Canary failed! Scaling down podinfo.test ``` -If you have Slack configured, Flagger will send a notification with the reason why the canary failed. +If you have alerting configured, Flagger will send a notification with the reason why the canary failed. ## A/B Testing -Besides weighted routing, Flagger can be configured to route traffic to the canary based on HTTP match conditions. In an A/B testing scenario, you'll be using HTTP headers or cookies to target a certain segment of your users. This is particularly useful for frontend applications that require session affinity. +Besides weighted routing, Flagger can be configured to route traffic to the canary based on HTTP match conditions. +In an A/B testing scenario, you'll be using HTTP headers or cookies to target a certain segment of your users. +This is particularly useful for frontend applications that require session affinity. ![Flagger A/B Testing Stages](https://raw.githubusercontent.com/weaveworks/flagger/master/docs/diagrams/flagger-abtest-steps.png) Edit the canary analysis, remove the max/step weight and add the match conditions and iterations: ```yaml - canaryAnalysis: + analysis: interval: 1m threshold: 10 iterations: 10 @@ -368,7 +395,8 @@ Edit the canary analysis, remove the max/step weight and add the match condition exact: "canary" metrics: - name: request-success-rate - threshold: 99 + thresholdRange: + min: 99 interval: 1m webhooks: - name: load-test @@ -378,7 +406,8 @@ Edit the canary analysis, remove the max/step weight and add the match condition cmd: "hey -z 1m -q 10 -c 2 -H 'Cookie: canary=always' http://app.example.com/" ``` -The above configuration will run an analysis for ten minutes targeting users that have a `canary` cookie set to `always` or those that call the service using the `X-Canary: insider` header. +The above configuration will run an analysis for ten minutes targeting users that have a `canary` cookie +set to `always` or those that call the service using the `X-Canary: insider` header. Trigger a canary deployment by updating the container image: @@ -416,3 +445,7 @@ Events: Normal Synced 5s flagger Promotion completed! Scaling down podinfo.test ``` +The above procedure can be extended with [custom metrics](../usage/metrics.md) checks, +[webhooks](../usage/webhooks.md), +[manual promotion](../usage/webhooks.md#manual-gating) approval and +[Slack or MS Teams](../usage/alerting.md) notifications. diff --git a/docs/gitbook/tutorials/zero-downtime-deployments.md b/docs/gitbook/tutorials/zero-downtime-deployments.md index c85e44421..e72e4f956 100644 --- a/docs/gitbook/tutorials/zero-downtime-deployments.md +++ b/docs/gitbook/tutorials/zero-downtime-deployments.md @@ -166,7 +166,7 @@ The above HPA ensures your app will be scaled up before the pods reach the CPU o To minimise the impact of downscaling operations you can make use of Envoy retry capabilities. ```yaml -apiVersion: flagger.app/v1alpha3 +apiVersion: flagger.app/v1beta1 kind: Canary spec: service: diff --git a/docs/gitbook/usage/alerting.md b/docs/gitbook/usage/alerting.md index 212888c3e..4671be93a 100644 --- a/docs/gitbook/usage/alerting.md +++ b/docs/gitbook/usage/alerting.md @@ -1,6 +1,9 @@ # Alerting -## Slack +Flagger can be configured to send alerts to various chat platforms. You can define a global alert provider at +install time or configure alerts on a per canary basis. + +### Global configuration Flagger can be configured to send Slack notifications: @@ -11,16 +14,16 @@ helm upgrade -i flagger flagger/flagger \ --set slack.user=flagger ``` -Once configured with a Slack incoming **webhook**, Flagger will post messages when a canary deployment has been initialised, when a new revision has been detected and if the canary analysis failed or succeeded. +Once configured with a Slack incoming **webhook**, Flagger will post messages when a canary deployment +has been initialised, when a new revision has been detected and if the canary analysis failed or succeeded. ![Slack Notifications](https://raw.githubusercontent.com/weaveworks/flagger/master/docs/screens/slack-canary-notifications.png) -A canary deployment will be rolled back if the progress deadline exceeded or if the analysis reached the maximum number of failed checks: +A canary deployment will be rolled back if the progress deadline exceeded or if the analysis reached the +maximum number of failed checks: ![Slack Notifications](https://raw.githubusercontent.com/weaveworks/flagger/master/docs/screens/slack-canary-failed.png) -## Microsoft Teams - Flagger can be configured to send notifications to Microsoft Teams: ```bash @@ -28,17 +31,89 @@ helm upgrade -i flagger flagger/flagger \ --set msteams.url=https://outlook.office.com/webhook/YOUR/TEAMS/WEBHOOK ``` -Flagger will post a message card to MS Teams when a new revision has been detected and if the canary analysis failed or succeeded: +Similar to Slack, Flagger alerts on canary analysis events: ![MS Teams Notifications](https://raw.githubusercontent.com/weaveworks/flagger/master/docs/screens/flagger-ms-teams-notifications.png) -And you'll get a notification on rollback: - ![MS Teams Notifications](https://raw.githubusercontent.com/weaveworks/flagger/master/docs/screens/flagger-ms-teams-failed.png) -## Prometheus Alert Manager +### Canary configuration + +Configuring alerting globally has several limitations as it's not possible to specify different channels +or configure the verbosity on a per canary basis. +To make the alerting move flexible, the canary analysis can be extended +with a list of alerts that reference an alert provider. +For each alert, users can configure the severity level. +The alerts section overrides the global setting. + +Slack example: + +```yaml +apiVersion: flagger.app/v1beta1 +kind: AlertProvider +metadata: + name: on-call + namespace: flagger +spec: + type: slack + channel: on-call-alerts + username: flagger + # webhook address (ignored if secretRef is specified) + address: https://hooks.slack.com/services/YOUR/SLACK/WEBHOOK + # secret containing the webhook address (optional) + secretRef: + name: on-call-url +--- +apiVersion: v1 +kind: Secret +metadata: + name: on-call-url + namespace: flagger +data: + address: +``` + +The alert provider **type** can be: `slack`, `msteams`, `rocket` or `discord`. When set to `discord`, +Flagger will use [Slack formatting](https://birdie0.github.io/discord-webhooks-guide/other/slack_formatting.html) +and will append `/slack` to the Discord address. + +When not specified, **channel** defaults to `general` and **username** defaults to `flagger`. + +When **secretRef** is specified, the Kubernetes secret must contain a data field named `address`, +the address in the secret will take precedence over the **address** field in the provider spec. + +The canary analysis can have a list of alerts, each alert referencing an alert provider: + +```yaml + analysis: + alerts: + - name: "on-call Slack" + severity: error + providerRef: + name: on-call + namespace: flagger + - name: "qa Discord" + severity: warn + providerRef: + name: qa-discord + - name: "dev MS Teams" + severity: info + providerRef: + name: dev-msteams +``` + +Alert fields: +* **name** (required) +* **severity** levels: `info`, `warn`, `error` (default info) +* **providerRef.name** alert provider name (required) +* **providerRef.namespace** alert provider namespace (defaults to the canary namespace) + +When the severity is set to `warn`, Flagger will alert when waiting on manual confirmation or if the analysis fails. +When the severity is set to `error`, Flagger will alert only if the canary analysis fails. + +### Prometheus Alert Manager -Besides Slack, you can use Alertmanager to trigger alerts when a canary deployment failed: +You can use Alertmanager to trigger alerts when a canary deployment failed: ```yaml - alert: canary_rollback diff --git a/docs/gitbook/usage/deployment-strategies.md b/docs/gitbook/usage/deployment-strategies.md index 8b01c0476..633b9b657 100644 --- a/docs/gitbook/usage/deployment-strategies.md +++ b/docs/gitbook/usage/deployment-strategies.md @@ -1,36 +1,38 @@ # Deployment Strategies Flagger can run automated application analysis, promotion and rollback for the following deployment strategies: - -* Canary release \(progressive traffic shifting\) - * Istio, Linkerd, App Mesh, NGINX, Contour, Gloo -* A/B Testing \(HTTP headers and cookies traffic routing\) - * Istio, App Mesh, NGINX, Contour -* Blue/Green \(traffic switch\) - * Kubernetes CNI, Istio, Linkerd, App Mesh, NGINX, Contour, Gloo -* Blue/Green \(traffic mirroring\) - * Istio - -For Canary releases and A/B testing you'll need a Layer 7 traffic management solution like a service mesh or an ingress controller. For Blue/Green deployments no service mesh or ingress controller is required. +* **Canary Release** (progressive traffic shifting) + * Istio, Linkerd, App Mesh, NGINX, Contour, Gloo +* **A/B Testing** (HTTP headers and cookies traffic routing) + * Istio, App Mesh, NGINX, Contour +* **Blue/Green** (traffic switching) + * Kubernetes CNI, Istio, Linkerd, App Mesh, NGINX, Contour, Gloo +* **Blue/Green Mirroring** (traffic shadowing) + * Istio + +For Canary releases and A/B testing you'll need a Layer 7 traffic management solution like a service mesh or an ingress controller. +For Blue/Green deployments no service mesh or ingress controller is required. A canary analysis is triggered by changes in any of the following objects: -* Deployment PodSpec \(container image, command, ports, env, resources, etc\) +* Deployment PodSpec (container image, command, ports, env, resources, etc) * ConfigMaps mounted as volumes or mapped to environment variables * Secrets mounted as volumes or mapped to environment variables -## Canary Release +### Canary Release -Flagger implements a control loop that gradually shifts traffic to the canary while measuring key performance indicators like HTTP requests success rate, requests average duration and pod health. Based on analysis of the KPIs a canary is promoted or aborted. +Flagger implements a control loop that gradually shifts traffic to the canary while measuring key performance +indicators like HTTP requests success rate, requests average duration and pod health. +Based on analysis of the KPIs a canary is promoted or aborted. ![Flagger Canary Stages](https://raw.githubusercontent.com/weaveworks/flagger/master/docs/diagrams/flagger-canary-steps.png) -The canary analysis runs periodically until it reaches the maximum traffic weight or the failed checks threshold. +The canary analysis runs periodically until it reaches the maximum traffic weight or the failed checks threshold. Spec: ```yaml - canaryAnalysis: + analysis: # schedule interval (default 60s) interval: 1m # max number of failed metric checks before rollback @@ -46,32 +48,81 @@ Spec: skipAnalysis: false ``` -The above analysis, if it succeeds, will run for 25 minutes while validating the HTTP metrics and webhooks every minute. You can determine the minimum time that it takes to validate and promote a canary deployment using this formula: +The above analysis, if it succeeds, will run for 25 minutes while validating the HTTP metrics and webhooks every minute. +You can determine the minimum time that it takes to validate and promote a canary deployment using this formula: -```text +``` interval * (maxWeight / stepWeight) ``` And the time it takes for a canary to be rollback when the metrics or webhook checks are failing: -```text -interval * threshold +``` +interval * threshold ``` -In emergency cases, you may want to skip the analysis phase and ship changes directly to production. At any time you can set the `spec.skipAnalysis: true`. When skip analysis is enabled, Flagger checks if the canary deployment is healthy and promotes it without analysing it. If an analysis is underway, Flagger cancels it and runs the promotion. - -## A/B Testing - -For frontend applications that require session affinity you should use HTTP headers or cookies match conditions to ensure a set of users will stay on the same version for the whole duration of the canary analysis. +In emergency cases, you may want to skip the analysis phase and ship changes directly to production. +At any time you can set the `spec.skipAnalysis: true`. +When skip analysis is enabled, Flagger checks if the canary deployment is healthy and +promotes it without analysing it. If an analysis is underway, Flagger cancels it and runs the promotion. + +Gated canary promotion stages: + +* scan for canary deployments +* check primary and canary deployment status + * halt advancement if a rolling update is underway + * halt advancement if pods are unhealthy +* call confirm-rollout webhooks and check results + * halt advancement if any hook returns a non HTTP 2xx result +* call pre-rollout webhooks and check results + * halt advancement if any hook returns a non HTTP 2xx result + * increment the failed checks counter +* increase canary traffic weight percentage from 0% to 2% (step weight) +* call rollout webhooks and check results +* check canary HTTP request success rate and latency + * halt advancement if any metric is under the specified threshold + * increment the failed checks counter +* check if the number of failed checks reached the threshold + * route all traffic to primary + * scale to zero the canary deployment and mark it as failed + * call post-rollout webhooks + * post the analysis result to Slack + * wait for the canary deployment to be updated and start over +* increase canary traffic weight by 2% (step weight) till it reaches 50% (max weight) + * halt advancement if any webhook call fails + * halt advancement while canary request success rate is under the threshold + * halt advancement while canary request duration P99 is over the threshold + * halt advancement while any custom metric check fails + * halt advancement if the primary or canary deployment becomes unhealthy + * halt advancement while canary deployment is being scaled up/down by HPA +* call confirm-promotion webhooks and check results + * halt advancement if any hook returns a non HTTP 2xx result +* promote canary to primary + * copy ConfigMaps and Secrets from canary to primary + * copy canary deployment spec template over primary +* wait for primary rolling update to finish + * halt advancement if pods are unhealthy +* route all traffic to primary +* scale to zero the canary deployment +* mark rollout as finished +* call post-rollout webhooks +* send notification with the canary analysis result +* wait for the canary deployment to be updated and start over + +### A/B Testing + +For frontend applications that require session affinity you should use HTTP headers or cookies match conditions +to ensure a set of users will stay on the same version for the whole duration of the canary analysis. ![Flagger A/B Testing Stages](https://raw.githubusercontent.com/weaveworks/flagger/master/docs/diagrams/flagger-abtest-steps.png) -You can enable A/B testing by specifying the HTTP match conditions and the number of iterations. If Flagger finds a HTTP match condition, it will ignore the `maxWeight` and `stepWeight` settings. +You can enable A/B testing by specifying the HTTP match conditions and the number of iterations. +If Flagger finds a HTTP match condition, it will ignore the `maxWeight` and `stepWeight` settings. Istio example: ```yaml - canaryAnalysis: + analysis: # schedule interval (default 60s) interval: 1m # total number of iterations @@ -88,22 +139,23 @@ Istio example: regex: "^(.*?;)?(canary=always)(;.*)?$" ``` -The above configuration will run an analysis for ten minutes targeting the Safari users and those that have a test cookie. You can determine the minimum time that it takes to validate and promote a canary deployment using this formula: +The above configuration will run an analysis for ten minutes targeting the Safari users and those that have a test cookie. +You can determine the minimum time that it takes to validate and promote a canary deployment using this formula: -```text +``` interval * iterations ``` And the time it takes for a canary to be rollback when the metrics or webhook checks are failing: -```text -interval * threshold +``` +interval * threshold ``` App Mesh example: ```yaml - canaryAnalysis: + analysis: interval: 1m threshold: 10 iterations: 2 @@ -118,7 +170,7 @@ Note that App Mesh supports a single condition. Contour example: ```yaml - canaryAnalysis: + analysis: interval: 1m threshold: 10 iterations: 2 @@ -133,7 +185,7 @@ Note that Contour does not support regex, you can use prefix, suffix or exact. NGINX example: ```yaml - canaryAnalysis: + analysis: interval: 1m threshold: 10 iterations: 2 @@ -155,16 +207,17 @@ curl -H 'X-Canary: insider' http://app.example.com curl -b 'canary=always' http://app.example.com ``` -## Blue/Green Deployments +### Blue/Green Deployments -For applications that are not deployed on a service mesh, Flagger can orchestrate blue/green style deployments with Kubernetes L4 networking. When using Istio you have the option to mirror traffic between blue and green. +For applications that are not deployed on a service mesh, Flagger can orchestrate blue/green style deployments +with Kubernetes L4 networking. When using Istio you have the option to mirror traffic between blue and green. ![Flagger Blue/Green Stages](https://raw.githubusercontent.com/weaveworks/flagger/master/docs/diagrams/flagger-bluegreen-steps.png) You can use the blue/green deployment strategy by replacing `stepWeight/maxWeight` with `iterations` in the `canaryAnalysis` spec: ```yaml - canaryAnalysis: + analysis: # schedule interval (default 60s) interval: 1m # total number of iterations @@ -173,35 +226,49 @@ You can use the blue/green deployment strategy by replacing `stepWeight/maxWeigh threshold: 2 ``` -With the above configuration Flagger will run conformance and load tests on the canary pods for ten minutes. If the metrics analysis succeeds, live traffic will be switched from the old version to the new one when the canary is promoted. +With the above configuration Flagger will run conformance and load tests on the canary pods for ten minutes. +If the metrics analysis succeeds, live traffic will be switched from the old version to the new one when the +canary is promoted. The blue/green deployment strategy is supported for all service mesh providers. Blue/Green rollout steps for service mesh: - -* scale up the canary \(green\) +* detect new revision (deployment spec, secrets or configmaps changes) +* scale up the canary (green) * run conformance tests for the canary pods -* run load tests and metric checks for the canary pods +* run load tests and metric checks for the canary pods every minute +* abort the canary release if the failure threshold is reached * route traffic to canary -* promote canary spec over primary \(blue\) +* promote canary spec over primary (blue) * wait for primary rollout * route traffic to primary * scale down canary -After the analysis finishes, the traffic is routed to the canary \(green\) before triggering the primary \(blue\) rolling update, this ensures a smooth transition to the new version avoiding dropping in-flight requests during the Kubernetes deployment rollout. +After the analysis finishes, the traffic is routed to the canary (green) before triggering the primary (blue) +rolling update, this ensures a smooth transition to the new version avoiding dropping in-flight requests during +the Kubernetes deployment rollout. -## Blue/Green with Traffic Mirroring +### Blue/Green with Traffic Mirroring -Traffic Mirroring is a pre-stage in a Canary \(progressive traffic shifting\) or Blue/Green deployment strategy. Traffic mirroring will copy each incoming request, sending one request to the primary and one to the canary service. The response from the primary is sent back to the user. The response from the canary is discarded. Metrics are collected on both requests so that the deployment will only proceed if the canary metrics are healthy. +Traffic Mirroring is a pre-stage in a Canary (progressive traffic shifting) or +Blue/Green deployment strategy. Traffic mirroring will copy each incoming +request, sending one request to the primary and one to the canary service. +The response from the primary is sent back to the user. The response from the canary +is discarded. Metrics are collected on both requests so that the deployment will +only proceed if the canary metrics are healthy. -Mirroring must only be used for requests that are **idempotent** or capable of being processed twice \(once by the primary and once by the canary\). Reads are idempotent. Before using mirroring on requests that may be writes, you should consider what will happen if a write is duplicated and handled by the primary and canary. +Mirroring should be used for requests that are **idempotent** or capable of +being processed twice (once by the primary and once by the canary). Reads are +idempotent. Before using mirroring on requests that may be writes, you should +consider what will happen if a write is duplicated and handled by the primary +and canary. -To use mirroring, set `spec.canaryAnalysis.mirror` to `true`. +To use mirroring, set `spec.canaryAnalysis.mirror` to `true`. Istio example: ```yaml - canaryAnalysis: + analysis: # schedule interval (default 60s) interval: 1m # total number of iterations @@ -212,3 +279,27 @@ Istio example: mirror: true ``` +Mirroring rollout steps for service mesh: +* detect new revision (deployment spec, secrets or configmaps changes) +* scale from zero the canary deployment +* wait for the HPA to set the canary minimum replicas +* check canary pods health +* run the acceptance tests +* abort the canary release if tests fail +* start the load tests +* mirror traffic from primary to canary +* check request success rate and request duration every minute +* abort the canary release if the failure threshold is reached +* stop traffic mirroring after the number of iterations is reached +* route live traffic to the canary pods +* promote the canary (update the primary secrets, configmaps and deployment spec) +* wait for the primary deployment rollout to finish +* wait for the HPA to set the primary minimum replicas +* check primary pods health +* switch live traffic back to primary +* scale to zero the canary +* send notification with the canary analysis result + +After the analysis finishes, the traffic is routed to the canary (green) before triggering the primary (blue) +rolling update, this ensures a smooth transition to the new version avoiding dropping in-flight requests during +the Kubernetes deployment rollout. \ No newline at end of file diff --git a/docs/gitbook/usage/how-it-works.md b/docs/gitbook/usage/how-it-works.md new file mode 100644 index 000000000..4b0cea479 --- /dev/null +++ b/docs/gitbook/usage/how-it-works.md @@ -0,0 +1,285 @@ +# How it works + +[Flagger](https://github.com/weaveworks/flagger) can be configured to automate the release process +for Kubernetes workloads with a custom resource named canary. + +### Canary custom resource + +The canary custom resource defines the release process of an application running on Kubernetes +and is portable across clusters, service meshes and ingress providers. + +For a deployment named _podinfo_, a canary release with progressive traffic shifting can be defined as: + +```yaml +apiVersion: flagger.app/v1beta1 +kind: Canary +metadata: + name: podinfo +spec: + targetRef: + apiVersion: apps/v1 + kind: Deployment + name: podinfo + service: + port: 9898 + analysis: + interval: 1m + threshold: 10 + maxWeight: 50 + stepWeight: 5 + metrics: + - name: request-success-rate + thresholdRange: + min: 99 + interval: 1m + - name: request-duration + thresholdRange: + max: 500 + interval: 1m + webhooks: + - name: load-test + url: http://flagger-loadtester.test/ + metadata: + cmd: "hey -z 1m -q 10 -c 2 http://podinfo-canary.test:9898/" +``` + +When you deploy a new version of an app, Flagger gradually shifts traffic to the canary, +and at the same time, measures the requests success rate as well as the average response duration. +You can extend the canary analysis with custom metrics, acceptance and load testing +to harden the validation process of your app release process. + +If you are running multiple service meshes or ingress controllers in the same cluster, +you can override the global provider for a specific canary with `spec.provider`. + +### Canary target + +A canary resource can target a Kubernetes Deployment or DaemonSet. + +Kubernetes Deployment example: + +```yaml +spec: + progressDeadlineSeconds: 60 + targetRef: + apiVersion: apps/v1 + kind: Deployment + name: podinfo + autoscalerRef: + apiVersion: autoscaling/v2beta1 + kind: HorizontalPodAutoscaler + name: podinfo +``` + +Based on the above configuration, Flagger generates the following Kubernetes objects: + +* `deployment/-primary` +* `hpa/-primary` + +The primary deployment is considered the stable release of your app, by default all traffic is routed to this version +and the target deployment is scaled to zero. +Flagger will detect changes to the target deployment (including secrets and configmaps) and will perform a +canary analysis before promoting the new version as primary. + +If the target deployment uses secrets and/or configmaps, Flagger will create a copy of each object using the `-primary` +prefix and will reference these objects in the primary deployment. You can disable the secrets/configmaps tracking +with the `-enable-config-tracking=false` command flag in the Flagger deployment manifest under containers args +or by setting `--set configTracking.enabled=false` when installing Flagger with Helm. + +**Note** that the target deployment must have a single label selector in the format `app: `: + +```yaml +apiVersion: apps/v1 +kind: Deployment +metadata: + name: podinfo +spec: + selector: + matchLabels: + app: podinfo + template: + metadata: + labels: + app: podinfo +``` + +Besides `app` Flagger supports `name` and `app.kubernetes.io/name` selectors. +If you use a different convention you can specify your label with +the `-selector-labels=my-app-label` command flag in the Flagger deployment manifest under containers args +or by setting `--set selectorLabels=my-app-label` when installing Flagger with Helm. + +The autoscaler reference is optional, when specified, Flagger will pause the traffic increase while the +target and primary deployments are scaled up or down. HPA can help reduce the resource usage during the canary analysis. + +The progress deadline represents the maximum time in seconds for the canary deployment to make progress +before it is rolled back, defaults to ten minutes. + +### Canary service + +A canary resource dictates how the target workload is exposed inside the cluster. +The canary target should expose a TCP port that will be used by Flagger to create the ClusterIP Services. + +```yaml +spec: + service: + name: podinfo + port: 9898 + portName: http + targetPort: 9898 + portDiscovery: true +``` + +The container port from the target workload should match the `service.port` or `service.targetPort`. +The `service.name` is optional, defaults to `spec.targetRef.name`. +The `service.targetPort` can be a container port number or name. +The `service.portName` is optional (defaults to `http`), if your workload uses gPRC then set the port name to `grcp`. + +If port discovery is enabled, Flagger scans the target workload and extracts the containers +ports excluding the port specified in the canary service and service mesh sidecar ports. +These ports will be used when generating the ClusterIP services. + +Based on the canary spec service, Flagger creates the following Kubernetes ClusterIP service: + +* `..svc.cluster.local` + selector `app=-primary` +* `-primary..svc.cluster.local` + selector `app=-primary` +* `-canary..svc.cluster.local` + selector `app=` + +This ensures that traffic to `podinfo.test:9898` will be routed to the latest stable release of your app. +The `podinfo-canary.test:9898` address is available only during the +canary analysis and can be used for conformance testing or load testing. + +Besides the port mapping, the service specification can contain URI match and rewrite rules, +timeout and retry polices: + +```yaml +spec: + service: + port: 9898 + match: + - uri: + prefix: / + rewrite: + uri: / + retries: + attempts: 3 + perTryTimeout: 1s + timeout: 5s +``` + +When using **Istio** as the mesh provider, you can also specify +HTTP header operations, CORS and traffic policies, Istio gateways and hosts. +The Istio routing configuration can be found [here](../faq.md#istio-routing). + +### Canary status + +You can use kubectl to get the current status of canary deployments cluster wide: + +```bash +kubectl get canaries --all-namespaces + +NAMESPACE NAME STATUS WEIGHT LASTTRANSITIONTIME +test podinfo Progressing 15 2019-06-30T14:05:07Z +prod frontend Succeeded 0 2019-06-30T16:15:07Z +prod backend Failed 0 2019-06-30T17:05:07Z +``` + +The status condition reflects the last known state of the canary analysis: + +```bash +kubectl -n test get canary/podinfo -oyaml | awk '/status/,0' +``` + +A successful rollout status: + +```yaml +status: + canaryWeight: 0 + failedChecks: 0 + iterations: 0 + lastAppliedSpec: "14788816656920327485" + lastPromotedSpec: "14788816656920327485" + conditions: + - lastTransitionTime: "2019-07-10T08:23:18Z" + lastUpdateTime: "2019-07-10T08:23:18Z" + message: Canary analysis completed successfully, promotion finished. + reason: Succeeded + status: "True" + type: Promoted +``` + +The `Promoted` status condition can have one of the following reasons: +Initialized, Waiting, Progressing, Promoting, Finalising, Succeeded or Failed. +A failed canary will have the promoted status set to `false`, +the reason to `failed` and the last applied spec will be different to the last promoted one. + +Wait for a successful rollout: + +```bash +kubectl wait canary/podinfo --for=condition=promoted +``` + +CI example: + +```bash +# update the container image +kubectl set image deployment/podinfo podinfod=stefanprodan/podinfo:3.0.1 + +# wait for Flagger to detect the change +ok=false +until ${ok}; do + kubectl get canary/podinfo | grep 'Progressing' && ok=true || ok=false + sleep 5 +done + +# wait for the canary analysis to finish +kubectl wait canary/podinfo --for=condition=promoted --timeout=5m + +# check if the deployment was successful +kubectl get canary/podinfo | grep Succeeded +``` + +### Canary analysis + +The canary analysis defines: +* the type of [deployment strategy](deployment-strategies.md) +* the [metrics](metrics.md) used to validate the canary version +* the [webhooks](webhooks.md) used for conformance testing, load testing and manual gating +* the [alerting settings](alerting.md) + +Spec: + +```yaml + analysis: + # schedule interval (default 60s) + interval: + # max number of failed metric checks before rollback + threshold: + # max traffic percentage routed to canary + # percentage (0-100) + maxWeight: + # canary increment step + # percentage (0-100) + stepWeight: + # total number of iterations + # used for A/B Testing and Blue/Green + iterations: + # canary match conditions + # used for A/B Testing + match: + - # HTTP header + # key performance indicators + metrics: + - # metric check + # alerting + alerts: + - # alert provider + # external checks + webhooks: + - # hook +``` + +The canary analysis runs periodically until it reaches the maximum traffic weight or the number of iterations. +On each run, Flagger calls the webhooks, checks the metrics and if the failed checks threshold is reached, stops the +analysis and rolls back the canary. If alerting is configured, Flagger will post the analysis result using the alert providers. diff --git a/docs/gitbook/usage/metrics.md b/docs/gitbook/usage/metrics.md new file mode 100644 index 000000000..3c037cf10 --- /dev/null +++ b/docs/gitbook/usage/metrics.md @@ -0,0 +1,235 @@ +# Metrics Analysis + +As part of the analysis process, Flagger can validate service level objectives (SLOs) like +availability, error rate percentage, average response time and any other objective based on app specific metrics. +If a drop in performance is noticed during the SLOs analysis, +the release will be automatically rolled back with minimum impact to end-users. + +### Builtin metrics + +Flagger comes with two builtin metric checks: HTTP request success rate and duration. + +```yaml + analysis: + metrics: + - name: request-success-rate + interval: 1m + # minimum req success rate (non 5xx responses) + # percentage (0-100) + thresholdRange: + min: 99 + - name: request-duration + interval: 1m + # maximum req duration P99 + # milliseconds + thresholdRange: + max: 500 +``` + +For each metric you can specify a range of accepted values with `thresholdRange` +and the window size or the time series with `interval`. +The builtin checks are available for every service mesh / ingress controller +and are implemented with [Prometheus queries](../faq.md#metrics). + +### Custom metrics + +The canary analysis can be extended with custom metric checks. Using a `MetricTemplate` custom resource, you +configure Flagger to connect to a metric provider and run a query that returns a `float64` value. +The query result is used to validate the canary based on the specified threshold range. + +```yaml +apiVersion: flagger.app/v1beta1 +kind: MetricTemplate +metadata: + name: my-metric +spec: + provider: + type: # can be prometheus or datadog + address: # API URL + secretRef: + name: # name of the secret containing the API credentials + query: # metric query +``` + +The following variables are available in query templates: + +- `name` (canary.metadata.name) +- `namespace` (canary.metadata.namespace) +- `target` (canary.spec.targetRef.name) +- `service` (canary.spec.service.name) +- `ingress` (canary.spec.ingresRef.name) +- `interval` (canary.spec.canaryAnalysis.metrics[].interval) + +A canary analysis metric can reference a template with `templateRef`: + +```yaml + analysis: + metrics: + - name: "my metric" + templateRef: + name: my-metric + # namespace is optional + # when not specified, the canary namespace will be used + namespace: flagger + # accepted values + thresholdRange: + min: 10 + max: 1000 + # metric query time window + interval: 1m +``` + +### Prometheus + +You can create custom metric checks targeting a Prometheus server +by setting the provider type to `prometheus` and writing the query in PromQL. + +Prometheus template example: + +```yaml +apiVersion: flagger.app/v1beta1 +kind: MetricTemplate +metadata: + name: not-found-percentage + namespace: istio-system +spec: + provider: + type: prometheus + address: http://promethues.istio-system:9090 + query: | + 100 - sum( + rate( + istio_requests_total{ + reporter="destination", + destination_workload_namespace="{{ namespace }}", + destination_workload="{{ target }}", + response_code!="404" + }[{{ interval }}] + ) + ) + / + sum( + rate( + istio_requests_total{ + reporter="destination", + destination_workload_namespace="{{ namespace }}", + destination_workload="{{ target }}" + }[{{ interval }}] + ) + ) * 100 +``` + +Reference the template in the canary analysis: + +```yaml + analysis: + metrics: + - name: "404s percentage" + templateRef: + name: not-found-percentage + namespace: istio-system + thresholdRange: + max: 5 + interval: 1m +``` + +The above configuration validates the canary by checking +if the HTTP 404 req/sec percentage is below 5 percent of the total traffic. +If the 404s rate reaches the 5% threshold, then the canary fails. + +Prometheus gRPC error rate example: + +```yaml +apiVersion: flagger.app/v1beta1 +kind: MetricTemplate +metadata: + name: grpc-error-rate-percentage + namespace: flagger +spec: + provider: + type: prometheus + address: http://flagger-promethues.flagger-system:9090 + query: | + 100 - sum( + rate( + grpc_server_handled_total{ + grpc_code!="OK", + kubernetes_namespace="{{ namespace }}", + kubernetes_pod_name=~"{{ target }}-[0-9a-zA-Z]+(-[0-9a-zA-Z]+)" + }[{{ interval }}] + ) + ) + / + sum( + rate( + grpc_server_started_total{ + kubernetes_namespace="{{ namespace }}", + kubernetes_pod_name=~"{{ target }}-[0-9a-zA-Z]+(-[0-9a-zA-Z]+)" + }[{{ interval }}] + ) + ) * 100 +``` + +The above template is for gPRC services instrumented with [go-grpc-prometheus](https://github.com/grpc-ecosystem/go-grpc-prometheus). + +### Datadog + +You can create custom metric checks using the Datadog provider. + +Create a secret with your Datadog API credentials: + +```yaml +apiVersion: v1 +kind: Secret +metadata: + name: datadog + namespace: istio-system +data: + datadog_api_key: your-datadog-api-key + datadog_application_key: your-datadog-application-key +``` + +Datadog template example: + +```yaml +apiVersion: flagger.app/v1beta1 +kind: MetricTemplate +metadata: + name: not-found-percentage + namespace: istio-system +spec: + provider: + type: datadog + address: https://api.datadoghq.com + secretRef: + name: datadog + query: | + 100 - ( + sum:istio.mesh.request.count{ + reporter:destination, + destination_workload_namespace:{{ namespace }}, + destination_workload:{{ target }}, + !response_code:404 + }.as_count() + / + sum:istio.mesh.request.count{ + reporter:destination, + destination_workload_namespace:{{ namespace }}, + destination_workload:{{ target }} + }.as_count() + ) * 100 +``` + +Reference the template in the canary analysis: + +```yaml + analysis: + metrics: + - name: "404s percentage" + templateRef: + name: not-found-percentage + namespace: istio-system + thresholdRange: + max: 5 + interval: 1m +``` diff --git a/docs/gitbook/usage/monitoring.md b/docs/gitbook/usage/monitoring.md index 3eb41990b..15dc10e7e 100644 --- a/docs/gitbook/usage/monitoring.md +++ b/docs/gitbook/usage/monitoring.md @@ -84,7 +84,7 @@ Example: The event webhook can be overwritten at canary level with: ```yaml - canaryAnalysis: + analysis: webhooks: - name: "send to Slack" type: event diff --git a/docs/gitbook/usage/webhooks.md b/docs/gitbook/usage/webhooks.md new file mode 100644 index 000000000..16056db51 --- /dev/null +++ b/docs/gitbook/usage/webhooks.md @@ -0,0 +1,401 @@ +# Webhooks + +The canary analysis can be extended with webhooks. Flagger will call each webhook URL and +determine from the response status code (HTTP 2xx) if the canary is failing or not. + +There are several types of hooks: +* **confirm-rollout** hooks are executed before scaling up the canary deployment and can be used for manual approval. +The rollout is paused until the hook returns a successful HTTP status code. +* **pre-rollout** hooks are executed before routing traffic to canary. +The canary advancement is paused if a pre-rollout hook fails and if the number of failures reach the +threshold the canary will be rollback. +* **rollout** hooks are executed during the analysis on each iteration before the metric checks. +If a rollout hook call fails the canary advancement is paused and eventfully rolled back. +* **confirm-promotion** hooks are executed before the promotion step. +The canary promotion is paused until the hooks return HTTP 200. +While the promotion is paused, Flagger will continue to run the metrics checks and rollout hooks. +* **post-rollout** hooks are executed after the canary has been promoted or rolled back. +If a post rollout hook fails the error is logged. +* **rollback** hooks are executed while a canary deployment is in either Progressing or Waiting status. +This provides the ability to rollback during analysis or while waiting for a confirmation. If a rollback hook +returns a successful HTTP status code, Flagger will stop the analysis and mark the canary release as failed. +* **event** hooks are executed every time Flagger emits a Kubernetes event. When configured, +every action that Flagger takes during a canary deployment will be sent as JSON via an HTTP POST request. + +Spec: + +```yaml + analysis: + webhooks: + - name: "start gate" + type: confirm-rollout + url: http://flagger-loadtester.test/gate/approve + - name: "smoke test" + type: pre-rollout + url: http://flagger-helmtester.kube-system/ + timeout: 3m + metadata: + type: "helm" + cmd: "test podinfo --cleanup" + - name: "load test" + type: rollout + url: http://flagger-loadtester.test/ + timeout: 15s + metadata: + cmd: "hey -z 1m -q 5 -c 2 http://podinfo-canary.test:9898/" + - name: "promotion gate" + type: confirm-promotion + url: http://flagger-loadtester.test/gate/approve + - name: "notify" + type: post-rollout + url: http://telegram.bot:8080/ + timeout: 5s + metadata: + some: "message" + - name: "rollback gate" + type: rollback + url: http://flagger-loadtester.test/rollback/check + - name: "send to Slack" + type: event + url: http://event-recevier.notifications/slack +``` + +> **Note** that the sum of all rollout webhooks timeouts should be lower than the analysis interval. + +Webhook payload (HTTP POST): + +```json +{ + "name": "podinfo", + "namespace": "test", + "phase": "Progressing", + "metadata": { + "test": "all", + "token": "16688eb5e9f289f1991c" + } +} +``` + +Response status codes: + +* 200-202 - advance canary by increasing the traffic weight +* timeout or non-2xx - halt advancement and increment failed checks + +On a non-2xx response Flagger will include the response body (if any) in the failed checks log and Kubernetes events. + +Event payload (HTTP POST): + +```json +{ + "name": "string (canary name)", + "namespace": "string (canary namespace)", + "phase": "string (canary phase)", + "metadata": { + "eventMessage": "string (canary event message)", + "eventType": "string (canary event type)", + "timestamp": "string (unix timestamp ms)" + } +} +``` + +The event receiver can create alerts based on the received phase +(possible values: ` Initialized`, `Waiting`, `Progressing`, `Promoting`, `Finalising`, `Succeeded` or `Failed`). + +### Load Testing + +For workloads that are not receiving constant traffic Flagger can be configured with a webhook, +that when called, will start a load test for the target workload. +If the target workload doesn't receive any traffic during the canary analysis, +Flagger metric checks will fail with "no values found for metric request-success-rate". + +Flagger comes with a load testing service based on [rakyll/hey](https://github.com/rakyll/hey) +that generates traffic during analysis when configured as a webhook. + +![Flagger Load Testing Webhook](https://raw.githubusercontent.com/weaveworks/flagger/master/docs/diagrams/flagger-load-testing.png) + +First you need to deploy the load test runner in a namespace with sidecar injection enabled: + +```bash +export REPO=https://raw.githubusercontent.com/weaveworks/flagger/master + +kubectl -n test apply -f ${REPO}/artifacts/loadtester/deployment.yaml +kubectl -n test apply -f ${REPO}/artifacts/loadtester/service.yaml +``` + +Or by using Helm: + +```bash +helm repo add flagger https://flagger.app + +helm upgrade -i flagger-loadtester flagger/loadtester \ +--namespace=test \ +--set cmd.timeout=1h +``` + +When deployed the load tester API will be available at `http://flagger-loadtester.test/`. + +Now you can add webhooks to the canary analysis spec: + +```yaml +webhooks: + - name: load-test-get + url: http://flagger-loadtester.test/ + timeout: 5s + metadata: + type: cmd + cmd: "hey -z 1m -q 10 -c 2 http://podinfo-canary.test:9898/" + - name: load-test-post + url: http://flagger-loadtester.test/ + timeout: 5s + metadata: + type: cmd + cmd: "hey -z 1m -q 10 -c 2 -m POST -d '{test: 2}' http://podinfo-canary.test:9898/echo" +``` + +When the canary analysis starts, Flagger will call the webhooks and the load tester will run the `hey` commands +in the background, if they are not already running. This will ensure that during the +analysis, the `podinfo-canary.test` service will receive a steady stream of GET and POST requests. + +If your workload is exposed outside the mesh you can point `hey` to the +public URL and use HTTP2. + +```yaml +webhooks: + - name: load-test-get + url: http://flagger-loadtester.test/ + timeout: 5s + metadata: + type: cmd + cmd: "hey -z 1m -q 10 -c 2 -h2 https://podinfo.example.com/" +``` + +For gRPC services you can use [bojand/ghz](https://github.com/bojand/ghz) which is a similar tool to Hey but for gPRC: + +```yaml +webhooks: + - name: grpc-load-test + url: http://flagger-loadtester.test/ + timeout: 5s + metadata: + type: cmd + cmd: "ghz -z 1m -q 10 -c 2 --insecure podinfo.test:9898" +``` + +`ghz` uses reflection to identify which gRPC method to call. If you do not wish to enable reflection for your gRPC service you can implement a standardized health check from the [grpc-proto](https://github.com/grpc/grpc-proto) library. To use this [health check schema](https://github.com/grpc/grpc-proto/blob/master/grpc/health/v1/health.proto) without reflection you can pass a parameter to `ghz` like this + +```yaml +webhooks: + - name: grpc-load-test-no-reflection + url: http://flagger-loadtester.test/ + timeout: 5s + metadata: + type: cmd + cmd: "ghz --insecure --proto=/tmp/ghz/health.proto --call=grpc.health.v1.Health/Check podinfo.test:9898" +``` + +The load tester can run arbitrary commands as long as the binary is present in the container image. +For example if you you want to replace `hey` with another CLI, you can create your own Docker image: + +```dockerfile +FROM weaveworks/flagger-loadtester: + +RUN curl -Lo /usr/local/bin/my-cli https://github.com/user/repo/releases/download/ver/my-cli \ + && chmod +x /usr/local/bin/my-cli +``` + +### Load Testing Delegation + +The load tester can also forward testing tasks to external tools, by now [nGrinder](https://github.com/naver/ngrinder) +is supported. + +To use this feature, add a load test task of type 'ngrinder' to the canary analysis spec: + +```yaml +webhooks: + - name: load-test-post + url: http://flagger-loadtester.test/ + timeout: 5s + metadata: + # type of this load test task, cmd or ngrinder + type: ngrinder + # base url of your nGrinder controller server + server: http://ngrinder-server:port + # id of the test to clone from, the test must have been defined. + clone: 100 + # user name and base64 encoded password to authenticate against the nGrinder server + username: admin + passwd: YWRtaW4= + # the interval between between nGrinder test status polling, default to 1s + pollInterval: 5s +``` +When the canary analysis starts, the load tester will initiate a [clone_and_start request](https://github.com/naver/ngrinder/wiki/REST-API-PerfTest) +to the nGrinder server and start a new performance test. the load tester will periodically poll the nGrinder server +for the status of the test, and prevent duplicate requests from being sent in subsequent analysis loops. + +### Integration Testing + +Flagger comes with a testing service that can run Helm tests or Bats tests when configured as a webhook. + +Deploy the Helm test runner in the `kube-system` namespace using the `tiller` service account: + +```bash +helm repo add flagger https://flagger.app + +helm upgrade -i flagger-helmtester flagger/loadtester \ +--namespace=kube-system \ +--set serviceAccountName=tiller +``` + +When deployed the Helm tester API will be available at `http://flagger-helmtester.kube-system/`. + +Now you can add pre-rollout webhooks to the canary analysis spec: + +```yaml + analysis: + webhooks: + - name: "smoke test" + type: pre-rollout + url: http://flagger-helmtester.kube-system/ + timeout: 3m + metadata: + type: "helm" + cmd: "test {{ .Release.Name }} --cleanup" +``` + +When the canary analysis starts, Flagger will call the pre-rollout webhooks before routing traffic to the canary. +If the helm test fails, Flagger will retry until the analysis threshold is reached and the canary is rolled back. + +If you are using Helm v3, you'll have to create a dedicated service account and add the release namespace to the test command: + +```yaml + analysis: + webhooks: + - name: "smoke test" + type: pre-rollout + url: http://flagger-helmtester.kube-system/ + timeout: 3m + metadata: + type: "helmv3" + cmd: "test run {{ .Release.Name }} --timeout 3m -n {{ .Release.Namespace }}" +``` + +As an alternative to Helm you can use the [Bash Automated Testing System](https://github.com/bats-core/bats-core) to run your tests. + +```yaml + analysis: + webhooks: + - name: "acceptance tests" + type: pre-rollout + url: http://flagger-batstester.default/ + timeout: 5m + metadata: + type: "bash" + cmd: "bats /tests/acceptance.bats" +``` + +Note that you should create a ConfigMap with your Bats tests and mount it inside the tester container. + +### Manual Gating + +For manual approval of a canary deployment you can use the `confirm-rollout` and `confirm-promotion` webhooks. +The confirmation rollout hooks are executed before the pre-rollout hooks. +Flagger will halt the canary traffic shifting and analysis until the confirm webhook returns HTTP status 200. + +For manual rollback of a canary deployment you can use the `rollback` webhook. The rollback hook will be called +during the analysis and confirmation states. If a rollback webhook returns a successful HTTP status code, Flagger +will shift all traffic back to the primary instance and fail the canary. + +Manual gating with Flagger's tester: + +```yaml + analysis: + webhooks: + - name: "gate" + type: confirm-rollout + url: http://flagger-loadtester.test/gate/halt +``` + +The `/gate/halt` returns HTTP 403 thus blocking the rollout. + +If you have notifications enabled, Flagger will post a message to Slack or MS Teams if a canary rollout is waiting for approval. + +Change the URL to `/gate/approve` to start the canary analysis: + +```yaml + analysis: + webhooks: + - name: "gate" + type: confirm-rollout + url: http://flagger-loadtester.test/gate/approve +``` + +Manual gating can be driven with Flagger's tester API. Set the confirmation URL to `/gate/check`: + +```yaml + analysis: + webhooks: + - name: "ask for confirmation" + type: confirm-rollout + url: http://flagger-loadtester.test/gate/check +``` + +By default the gate is closed, you can start or resume the canary rollout with: + +```bash +kubectl -n test exec -it flagger-loadtester-xxxx-xxxx sh + +curl -d '{"name": "podinfo","namespace":"test"}' http://localhost:8080/gate/open +``` + +You can pause the rollout at any time with: + +```bash +curl -d '{"name": "podinfo","namespace":"test"}' http://localhost:8080/gate/close +``` + +If a canary analysis is paused the status will change to waiting: + +```bash +kubectl get canary/podinfo + +NAME STATUS WEIGHT +podinfo Waiting 0 +``` + +The `confirm-promotion` hook type can be used to manually approve the canary promotion. +While the promotion is paused, Flagger will continue to run the metrics checks and load tests. + +```yaml + analysis: + webhooks: + - name: "promotion gate" + type: confirm-promotion + url: http://flagger-loadtester.test/gate/halt +``` + +The `rollback` hook type can be used to manually rollback the canary promotion. As with gating, rollbacks can be driven +with Flagger's tester API by setting the rollback URL to `/rollback/check` + +```yaml + analysis: + webhooks: + - name: "rollback" + type: rollback + url: http://flagger-loadtester.test/rollback/check +``` + +By default rollback is closed, you can rollback a canary rollout with: + +```bash +kubectl -n test exec -it flagger-loadtester-xxxx-xxxx sh + +curl -d '{"name": "podinfo","namespace":"test"}' http://localhost:8080/rollback/open +``` + +You can close the rollback with: + +```bash +curl -d '{"name": "podinfo","namespace":"test"}' http://localhost:8080/rollback/close +``` + +If you have notifications enabled, Flagger will post a message to Slack or MS Teams if a canary has been rolled back. diff --git a/test/container-push.sh b/test/container-push.sh index bf2a7fe13..66dec947c 100755 --- a/test/container-push.sh +++ b/test/container-push.sh @@ -2,7 +2,6 @@ set -o errexit - push () { echo $DOCKER_PASS | docker login -u=$DOCKER_USER --password-stdin @@ -11,8 +10,9 @@ push () { docker tag test/flagger:latest weaveworks/flagger:${BRANCH_COMMIT}; docker push weaveworks/flagger:${BRANCH_COMMIT}; else - docker tag test/flagger:latest weaveworks/flagger:${CIRCLE_TAG}; - docker push weaveworks/flagger:${CIRCLE_TAG}; + VER=${CIRCLE_TAG:1} + docker tag test/flagger:latest weaveworks/flagger:${VER}; + docker push weaveworks/flagger:${VER}; fi } @@ -21,4 +21,3 @@ if [[ -z "$DOCKER_PASS" ]]; then else push fi -