Use ASM to deploy an application in blue-green release mode and phased release mode
This topic shows you how to use virtual services and destination rules in ASM to perform blue-green and canary releases.
Prerequisites
- Create at least one ASM instance. For more information, see Create an ASM instance.
- Add at least one ACK cluster to the ASM instance. For more information, see Add a cluster to an ASM instance.
- Deploy the Bookinfo sample application to the ACK cluster in your ASM instance. For more information, see Deploy an application in an ACK cluster that is added to an ASM instance.
- Deploy an ingress gateway in the ACK cluster in your ASM instance. For more information, see Create an ingress gateway.
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
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: v1Deploy 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.
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: reviews
spec:
hosts:
- reviews
http:
- route:
- destination:
host: reviews
subset: v2After 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%.
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: 50After 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.
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: v2end-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.