Skip to content

Commit 2984be6

Browse files
authored
Create Blue-GreenDeployment
1 parent cd65aa8 commit 2984be6

1 file changed

Lines changed: 71 additions & 0 deletions

File tree

Kubernetese/Blue-GreenDeployment

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
Blue/green Deployment
2+
Blue/green deployment quoted from TechTarget
3+
4+
A blue/green deployment is a change management strategy for releasing software code. Blue/green deployments, which may also be referred to as A/B deployments require two identical hardware environments that are configured exactly the same way. While one environment is active and serving end users, the other environment remains idle.
5+
6+
Container technology offers a stand-alone environment to run the desired service, which makes it super easy to create identical environments as required in the blue/green deployment. The loosely coupled Services - ReplicaSets, and the label/selector-based service routing in Kubernetes make it easy to switch between different backend environments. With these techniques, the blue/green deployments in Kubernetes can be done as follows:
7+
8+
Before the deployment, the infrastructure is prepared like so:
9+
Prepare the blue deployment and green deployment with TOMCAT_VERSION=7 and TARGET_ROLE set to blue or green respectively.
10+
apiVersion: extensions/v1beta1
11+
kind: Deployment
12+
metadata:
13+
name: tomcat-deployment-${TARGET_ROLE}
14+
spec:
15+
replicas: 2
16+
template:
17+
metadata:
18+
labels:
19+
app: tomcat
20+
role: ${TARGET_ROLE}
21+
spec:
22+
containers:
23+
- name: tomcat-container
24+
image: tomcat:${TOMCAT_VERSION}
25+
ports:
26+
- containerPort: 8080
27+
readinessProbe:
28+
httpGet:
29+
path: /
30+
port: 8080
31+
Prepare the public service endpoint, which initially routes to one of the backend environments, say TARGET_ROLE=blue.
32+
kind: Service
33+
apiVersion: v1
34+
metadata:
35+
name: tomcat-service
36+
labels:
37+
app: tomcat
38+
role: ${TARGET_ROLE}
39+
env: prod
40+
spec:
41+
type: LoadBalancer
42+
selector:
43+
app: tomcat
44+
role: ${TARGET_ROLE}
45+
ports:
46+
- port: 80
47+
targetPort: 8080
48+
Optionally, prepare a test endpoint so that we can visit the backend environments for testing. They are similar to the public service endpoint, but they are intended to be accessed internally by the dev/ops team only.
49+
kind: Service
50+
apiVersion: v1
51+
metadata:
52+
name: tomcat-test-${TARGET_ROLE}
53+
labels:
54+
app: tomcat
55+
role: test-${TARGET_ROLE}
56+
spec:
57+
type: LoadBalancer
58+
selector:
59+
app: tomcat
60+
role: ${TARGET_ROLE}
61+
ports:
62+
- port: 80
63+
targetPort: 8080
64+
Update the application in the inactive environment, say green environment. Set TARGET_ROLE=green and TOMCAT_VERSION=8 in the deployment config to update the green environment.
65+
Test the deployment via the tomcat-test-green test endpoint to ensure the green environment is ready to serve client traffic.
66+
Switch the frontend Service routing to the green environment by updating the Service config with TARGET_ROLE=green.
67+
Run additional tests on the public endpoint to ensure it is working properly.
68+
Now the blue environment is idle and we can:
69+
leave it with the old application so that we can roll back if there's issue with the new application
70+
update it to make it a hot backup of the active environment
71+
reduce its replica count to save the occupied resources

0 commit comments

Comments
 (0)