Blue Green Deployment in Openshift
Openshift is a platform for running containerized application workloads which is developed by Red Hat.
Here i am going to explain how we can utilize blue green deployment in openshift.
i have openshift services deployed one is blue and another is green container
Blue Version has old code and Green Version has new code.
Below is the blue version openshift yaml
Deployment
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: bitroid-dev
name: fastapiwebhook-blue
annotations: {}
spec:
selector:
matchLabels:
app: fastapiwebhook-blue
replicas: 2
template:
metadata:
labels:
app: fastapiwebhook-blue
spec:
containers:
- name: container
image: 'quay.io/hemanth22/fastapiwebhook-blue:latest'
ports:
- containerPort: 8080
protocol: TCP
env: []
imagePullSecrets: []
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
paused: false
Service
apiVersion: v1
kind: Service
metadata:
name: fastapiwebhook-blue
namespace: bitroid-dev
spec:
selector:
app: fastapiwebhook-blue
ports:
- protocol: TCP
port: 8000
targetPort: 8000
Below is the green version openshift yaml
Deployment
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: bitroid-dev
name: fastapiwebhook-green
annotations: {}
spec:
selector:
matchLabels:
app: fastapiwebhook-green
replicas: 2
template:
metadata:
labels:
app: fastapiwebhook-green
spec:
containers:
- name: container
image: 'quay.io/hemanth22/fastapiwebhook-green:latest'
ports:
- containerPort: 8080
protocol: TCP
env: []
imagePullSecrets: []
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
paused: false
Service
apiVersion: v1
kind: Service
metadata:
name: fastapiwebhook-green
namespace: bitroid-dev
spec:
selector:
app: fastapiwebhook-green
ports:
- protocol: TCP
port: 8000
targetPort: 8000
Create the route with below yaml file.
kind: Route
apiVersion: route.openshift.io/v1
metadata:
name: fastapiwebhook
namespace: bitroid-dev
labels: {}
spec:
to:
kind: Service
name: fastapiwebhook-blue
weight: 100
alternateBackends:
- weight: 0
kind: Service
name: fastapiwebhook-green
port:
targetPort: 8000
tls: {}
path: /
Once route is created, based on the weight first traffic as showing below, it will hit to service: fastapiwebhook-blue
Below is the sample output where webhook request hit to fastapiwebhook-blue
Now traffic weight has been update to 100 , for service : fastapiwebhook-green
Now traffic will server to green service: fastapiwebhook-green
if you see below, webhook request traffc has been routed green service: fastapiwebhook-green
This is blue green strategy in openshift, this helps if green version is unstable, it is easier to fall back to blue version.