Missing You

Remembering My Father. “Missing You” is published by Linda Osipow ~ Crazy, Almost Old Farm Wife in Creative Passions 💖.

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Automated canary deployments with Flagger and Istio

Continuous delivery is accepted as an enterprise software practice, and is a natural evolution of well-established continuous integration principles. However continuous deployment continues to be notably rare, perhaps due to the complexity of management and the fear of failed deployments impacting system availability.

Flagger can run automated application analysis, promotion and rollback for the following deployment strategies:

For Canary deployments and A/B testing you’ll need a Layer 7 traffic management solution like a service mesh (Istio, Linkerd, App Mesh) or an ingress controller (Contour, NGINX, Gloo). For Blue/Green deployments no service mesh or ingress controller is required.

What follows is a step-by-step guide to setting up and using Flagger on Google Kubernetes Engine (GKE).

Enable the GKE service and create a cluster with the HPA and Istio add-ons:

The above command will create a default node pool consisting of two n1-standard-2 (vCPU: 2, RAM 7.5GB, DISK: 30GB) VMs. Ideally you would want to isolate the Istio components from your workloads but there is no easy way of running the Istio pods on a dedicated node pool. The Istio manifests are considered read-only and GKE will undo any modification like node affinity or pod anti-affinity.

Set up credentials for kubectl:

Create a cluster admin role binding:

Create a service account and a cluster role binding for Tiller:

Deploy Tiller in the kube-system namespace:

Validate your setup with:

In a couple of seconds GCP should allocate an external IP to the istio-ingressgateway service.

Create a static IP address named istio-gateway using the Istio ingress IP:

Next you’ll need an internet domain and access to your DNS registrar. Add two A records (replace example.com with your domain):

Verify that the wildcard DNS is working:

Create a generic Istio gateway to expose services outside the mesh on HTTP:

Save the above resource as public-gateway.yaml and then apply it:

The GKE Istio add-on does not include a Prometheus instance that scrapes the Istio telemetry service. Because Flagger uses the Istio HTTP metrics to run the canary analysis you have to deploy the following Prometheus configuration that’s similar to the one that comes with the official Istio Helm chart.

Add Flagger Helm repository:

Deploy Flagger in the istio-system namespace with Slack notifications enabled:

You can install Flagger in any namespace as long as it can talk to the Istio Prometheus service on port 9090.

Flagger comes with a Grafana dashboard made for canary analysis. Install Grafana in the istio-system namespace:

Expose Grafana through the public gateway by creating a virtual service (replace example.com with your domain):

Save the above resource as grafana-virtual-service.yaml and then apply it:

Navigate to http://grafana.istio.example.com in your browser and you should be redirected to Grafana’s login page.

Flagger takes a Kubernetes deployment and optionally a horizontal pod autoscaler (HPA), then creates a series of objects (Kubernetes deployments, ClusterIP services and Istio virtual services). These objects expose the application on the mesh and drive the canary analysis and promotion.

Create a test namespace with Istio sidecar injection enabled:

Create a deployment and a horizontal pod autoscaler:

Deploy the load testing service to generate traffic during the canary analysis:

Create a canary custom resource (replace example.com with your own domain):

Save the above resource as podinfo-canary.yaml and then apply it:

After a couple of seconds Flagger will create the canary objects:

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.

A canary deployment is triggered by changes in any of the following objects:

Trigger a canary deployment by updating the container image:

Flagger detects that the deployment revision changed and starts to analyse it:

During the analysis the canary’s progress can be monitored with Grafana:

Note that if new changes are applied to the deployment during the canary analysis, Flagger will restart the analysis phase.

List all canaries in your cluster with:

If you’ve enabled the Slack notifications, you should receive the following messages:

During the canary analysis it is possible to generate synthetic HTTP 500 errors and high response latency to test if Flagger pauses the rollout.

Create a tester pod and exec into it:

Generate HTTP 500 errors:

Generate latency:

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.

The canary errors and latency spikes have been recorded as Kubernetes events and logged by Flagger in JSON format:

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:

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).

You can enable mirroring by replacing stepWeight/maxWeight with iterations and by setting canaryAnalysis.mirror to true:

With the above configuration, Flagger will run a canary release with the following steps:

Add a comment

Related posts:

You Are Doing Substance Abuse

How many times have you realized that the first thing you do in the morning after waking up is to check your phone?

My Binance Story

I started the first investment on the Binance exchange in September, 2017. What impressed me the most was a highly stable exchange. With new users like me, Binance provides simple, easy-to-use and…

John McAfee and the Future of Bitcoin

Will the price of bitcoin reach $1,000,000 by the end of 2020? There are different bitcoin predictions from one of the industry giants, but should we listen to him?