Blue Green Deployment with Helm Charts Blue Green Deployment with Helm Charts kubernetes kubernetes

Blue Green Deployment with Helm Charts


Let's start from definitions

Since there are many deployment strategies, let's start from the definition.

As per Martin Flower:

The blue-green deployment approach does this by ensuring you have two production environments, as identical as possible. At any time one of them, let's say blue for the example, is live. As you prepare a new release of your software you do your final stage of testing in the green environment. Once the software is working in the green environment, you switch the router so that all incoming requests go to the green environment - the blue one is now idle.

Blue/Green is not recommended in Helm. But there are workaround solutions

  • As per to helm issue #3518, it's not recommended to use Helm for blue/green or canary deployment.

  • There are at least 3 solutions based on top of Helm, see below

  • However there is a Helm chart for that case.

Helm itself (TL;DR: not recommended)

Helm itself is not intended for the case. See their explanation:

direct support for blue / green deployment pattern in helm · Issue #3518 · helm/helm

Helm works more in the sense of a traditional package manager, upgrading charts from one version to the next in a graceful manner (thanks to pod liveness/readiness probes and deployment update strategies), much like how one expects something like apt upgrade to work. Blue/green deployments are a very different beast compared to the package manager style of upgrade workflows; blue/green sits at a level higher in the toolchain because the use cases around these deployments require step-in/step-out policies, gradual traffic migrations and rollbacks. Because of that, we decided that blue/green deployments are something out of scope for Helm, though a tool that utilizes Helm under the covers (or something parallel like istio) could more than likely be able to handle that use case.

Other solutions based on Helm

There are at least three solution based on top of Helm, described and compared here:

Shipper by Booking.com

bookingcom/shipper: Kubernetes native multi-cluster canary or blue-green rollouts using Helm

It does this by relying on Helm, and using Helm Charts as the unit of configuration deployment. Shipper's Application object provides an interface for specifying values to a Chart just like the helm command line tool.Shipper consumes Charts directly from a Chart repository like ChartMuseum, and installs objects into clusters itself. This has the nice property that regular Kubernetes authentication and RBAC controls can be used to manage access to Shipper APIs.

Kubernetes native multi-cluster canary or blue-green rollouts using Helm

Istio

You can try something like this:

kubectl create -f <(istioctl kube-inject -f cowsay-v1.yaml) # deploy v1
kubectl create -f <(istioctl kube-inject -f cowsay-v2.yaml) # deploy v1

Flagger.

There is guide written by Flagger team: Blue/Green Deployments - FlaggerThis guide shows you how to automate Blue/Green deployments with Flagger and Kubernetes

You might try Helm itself

Also, as Kamol Hasan recommended, you can try that chart: puneetsaraswat/HelmCharts/blue-green.

blue.yml sample

{{ if .Values.blue.enabled }}apiVersion: extensions/v1beta1kind: Deploymentmetadata:  name: {{ template "blue-green.fullname" . }}-blue  labels:    release: {{ .Release.Name }}    chart: {{ .Chart.Name }}-{{ .Chart.Version }}    app: {{ template "blue-green.name" . }}spec:  replicas: {{ .Values.replicaCount }}  template:    metadata:      labels:        app: {{ template "blue-green.name" . }}        release: {{ .Release.Name }}        slot: blue    spec:      containers:        - name: {{ template "blue-green.name" . }}-blue          image: nginx:stable          imagePullPolicy: IfNotPresent          ports:            - name: http              containerPort: 80              protocol: TCP          # This (and the volumes section below) mount the config map as a volume.          volumeMounts:            - mountPath: /usr/share/nginx/html              name: wwwdata-volume      volumes:        - name: wwwdata-volume          configMap:            name: {{ template "blue-green.fullname" . }}{{ end }}

Medium blog post: Blue/Green Deployments using Helm Charts