Advanced Deployment Techniques in OpenShift
Objectives
Implement advanced deployment strategies.
Use OpenShift's deployment capabilities to ensure zero-downtime deployments.
Understand the use of Blue-Green, A/B, and Canary deployment strategies.
Tasks
1. Implement a Blue-Green Deployment for a Sample Application
Objective: Instruct participants on implementing a Blue-Green deployment.
Steps:
a. Create two deployment configurations: one for the current (blue) version and one for the new (green) version.
Blue.yaml file:
apiVersion: apps/v1
kind: Deployment
metadata:
name: blue-deployment
spec:
replicas: 1
selector:
matchLabels:
app: bluegreen-test
color: blue
template:
metadata:
labels:
app: bluegreen-test
color: blue
spec:
containers:
- name: nginx
image: linuxacademycontent/ckad-nginx:blue
ports:
- containerPort: 80
Green.yaml file:
apiVersion: apps/v1
kind: Deployment
metadata:
name: green-deployment
spec:
replicas: 1
selector:
matchLabels:
app: bluegreen-test
color: green
template:
metadata:
labels:
app: bluegreen-test
color: green
spec:
containers:
- name: nginx
image: linuxacademycontent/ckad-nginx:green
ports:
- containerPort: 80
b. Use a service and route to control traffic between the blue and green deployments.
BlueGreenService Initial Phase: This was initially setup for blue environment, now that you have created a green environment, you need to edit the bluegreenservice.yaml and change the selector value in color: green
apiVersion: v1
kind: Service
metadata:
name: bluegreen-service
spec:
selector:
app: bluegreen-test
color: blue
ports:
- protocol: TCP
port: 80
targetPort: 80
Route for BlueGreen Deployment:
cat bluegreenroute.yaml
apiVersion: route.openshift.io/v1
kind: Route
metadata:
name: mybluegreen-route
spec:
to:
kind: Service
name: bluegreen-service
port:
targetPort: 80
2. Set Up an A/B Deployment and Understand How to Route Traffic to Different Versions
Objective: Set up an A/B deployment and manage traffic routing.
Steps:
a. Create two deployment configurations for different versions.
Create a versionAdeployment:
apiVersion: apps/v1
kind: Deployment
metadata:
name: version-a-deployment
spec:
replicas: 2
selector:
matchLabels:
app: ab-testing
environment: version-a
template:
metadata:
labels:
app: ab-testing
environment: version-a
spec:
containers:
- name: nginx
image: linuxacademycontent/ckad-nginx:1.0.0
ports:
- containerPort: 80
Create a versionBDeployment:
apiVersion: apps/v1
kind: Deployment
metadata:
name: version-b-deployment
spec:
replicas: 2
selector:
matchLabels:
app: ab-testing
environment: version-b
template:
metadata:
labels:
app: ab-testing
environment: version-b
spec:
containers:
- name: nginx
image: linuxacademycontent/ckad-nginx:canary
ports:
- containerPort: 80
b. Use a service and route to route traffic to versions A and B based on labels.
ABtesting-svc
apiVersion: v1
kind: Service
metadata:
name: abtesting-svc
spec:
selector:
app: ab-testing
ports:
- protocol: TCP
port: 80
targetPort: 80
Route for AB-testing:
apiVersion: route.openshift.io/v1
kind: Route
metadata:
name: ab-route
spec:
to:
kind: Service
name: abtesting-svc
port:
targetPort: 80
3. Implement a Canary Deployment and Gradually Increase Traffic to the New Version
Objective: Implementing a Canary deployment.
Steps:
a. Create two deployment configurations for the baseline and canary versions.
Create a maindeployment.yaml or baseline.yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: main-deployment
spec:
replicas: 3
selector:
matchLabels:
app: canary-test
environment: main
template:
metadata:
labels:
app: canary-test
environment: main
spec:
containers:
- name: nginx
image: linuxacademycontent/ckad-nginx:1.0.0
ports:
- containerPort: 80
Creating a canaryDeployment.yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: canary-deployment
spec:
replicas: 1
selector:
matchLabels:
app: canary-test
environment: canary
template:
metadata:
labels:
app: canary-test
environment: canary
spec:
containers:
- name: nginx
image: linuxacademycontent/ckad-nginx:canary
ports:
- containerPort: 80
b. Gradually increase traffic to the canary version using a route.
Creating a canaryservice.yaml:
apiVersion: v1
kind: Service
metadata:
name: canary-test-svc
spec:
selector:
app: canary-test
ports:
- protocol: TCP
port: 80
targetPort: 80
Create a canary_route.yaml:
apiVersion: route.openshift.io/v1
kind: Route
metadata:
name: mycanary-route
spec:
to:
kind: Service
name: canary-test-svc
port:
targetPort: 80
Finally, this is what it should look like:
Summary
Implementing a Blue-Green Deployment: Created deployment configurations for blue and green versions; controlled traffic between versions using a service and route.
Setting Up an A/B Deployment: Created deployment configurations for versions A and B; routed traffic to different versions using labels in a service and route.
Implementing a Canary Deployment: Created deployment configurations for baseline/main and canary versions; gradually increased traffic to the canary version using a route.