Use ASM to deploy an application in blue-green release mode and phased release mode

Updated at:

This topic shows you how to use virtual services and destination rules in ASM to perform blue-green and canary releases.

Prerequisites

Create a destination rule

Create the required destination rules for the Bookinfo sample application. For more information, see Manage destination rules. The configuration is as follows.

apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: productpage
spec:
  host: productpage
  subsets:
    - name: v1
      labels:
        version: v1
---
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: reviews
spec:
  host: reviews
  subsets:
    - name: v1
      labels:
        version: v1
    - name: v2
      labels:
        version: v2
    - name: v3
      labels:
        version: v3
---
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: ratings
spec:
  host: ratings
  subsets:
    - name: v1
      labels:
        version: v1
    - name: v2
      labels:
        version: v2
    - name: v2-mysql
      labels:
        version: v2-mysql
    - name: v2-mysql-vm
      labels:
        version: v2-mysql-vm
---
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: details
spec:
  host: details
  subsets:
    - name: v1
      labels:
        version: v1
    - name: v2
      labels:
        version: v2

Create a virtual service

Create the required virtual services for the Bookinfo sample application. For more information, see Manage virtual services. The configuration is as follows.
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: productpage
spec:
  hosts:
  - productpage
  http:
  - route:
    - destination:
        host: productpage
        subset: v1
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: reviews
spec:
  hosts:
  - reviews
  http:
  - route:
    - destination:
        host: reviews
        subset: v1
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: ratings
spec:
  hosts:
  - ratings
  http:
  - route:
    - destination:
        host: ratings
        subset: v1
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: details
spec:
  hosts:
  - details
  http:
  - route:
    - destination:
        host: details
        subset: v1

Deploy version 2 in blue-green release mode

After the preceding destination rule and virtual service are created, version 2 of the reviews microservice of the Bookinfo application is running. However, no traffic is routed to version 2. To route traffic to version 2, you must deploy version 2 in blue-green release mode.

Update the reviews virtual service to perform a blue-green release. For more information, see Manage virtual services. The configuration is as follows.
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: reviews
spec:
  hosts:
  - reviews
  http:
  - route:
    - destination:
        host: reviews
        subset: v2

After the preceding virtual service is created, refresh the page of Bookinfo. The reviews microservice displays ratings as black stars.

Deploy version 3 in phased release mode to handle traffic by weight

You can run both version 2 and version 3 online and route traffic to the two versions by weight, such as 50% to 50%.

Update the virtual service for the reviews service to perform a canary release by weight. For more information, see Manage virtual services. The configuration is as follows.
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: reviews
spec:
  hosts:
    - reviews
  http:
  - route:
    - destination:
        host: reviews
        subset: v2
      weight: 50
    - destination:
        host: reviews
        subset: v3
      weight: 50

After the preceding virtual service is created, refresh the page of Bookinfo. The reviews microservice displays ratings by using version 2 or version 3 at random. The reviews microservice of version 3 displays ratings as red stars.

Deploy version 3 in phased release mode based on the request content

Phased release based on the traffic weight cannot meet the requirements of all scenarios. You can also deploy an application in phased release mode based on the user identity. This way, the application displays different pages for different users.

Update the virtual service to route traffic based on a request header. For more information, see Manage virtual services. The configuration is as follows.
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: reviews
spec:
  hosts:
  - reviews
  http:
  - match:
    - headers:
        end-user:
          exact: jason
    route:
    - destination:
        host: reviews
        subset: v3
  - route:
    - destination:
        host: reviews
        subset: v2
After you apply the configuration, refresh the page. The stars in the ratings section are always black. Now, click Sign in in the upper-right corner and log in with the username jason (no password required). The rating stars turn red.
Note When you sign in and access the backend service, the request includes an HTTP header such as end-user=XXX. After you sign in as jason, the request matches the rule in the YAML, which routes traffic to the v3 version of the reviews service.