Wednesday, February 26, 2025

How to do blue green deployment in aro cluster?

Blue-green deployment in an Azure Red Hat OpenShift (ARO) cluster involves deploying two versions of your application in parallel and switching traffic between them, similar to the concept of blue-green deployments in other environments. Here's how you can implement a blue-green deployment in an ARO cluster:

Steps to Implement Blue-Green Deployment in ARO:

1. Set Up Two Application Environments (Blue and Green)

Blue Environment: This is the currently running production environment.

Green Environment: This will host the new version of the application.


In OpenShift, these environments can be represented by separate namespaces, separate deployment configurations, or different services within the same namespace.

Deploy the current (blue) version of your app using a DeploymentConfig or Deployment object.

Deploy the new (green) version in parallel with a separate configuration.


Example of deploying an app version:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: app-blue
spec:
  replicas: 2
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
        version: blue
    spec:
      containers:
      - name: my-app
        image: <blue-app-image>
        ports:
        - containerPort: 8080

For the green environment:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: app-green
spec:
  replicas: 2
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
        version: green
    spec:
      containers:
      - name: my-app
        image: <green-app-image>
        ports:
        - containerPort: 8080

2. Expose the Services for Blue and Green

Create separate Service objects for both the blue and green deployments so that they can be independently accessed.


Example of services:

apiVersion: v1
kind: Service
metadata:
  name: blue-service
spec:
  selector:
    app: my-app
    version: blue
  ports:
  - protocol: TCP
    port: 80
    targetPort: 8080

apiVersion: v1
kind: Service
metadata:
  name: green-service
spec:
  selector:
    app: my-app
    version: green
  ports:
  - protocol: TCP
    port: 80
    targetPort: 8080

3. Set Up a Route or Load Balancer

OpenShift uses Routes to expose services externally. In a blue-green setup, you'll create a route to point to the active environment.

Initially, the route will point to the blue-service.


Example:

apiVersion: route.openshift.io/v1
kind: Route
metadata:
  name: my-app-route
spec:
  host: my-app.example.com
  to:
    kind: Service
    name: blue-service
  port:
    targetPort: 8080

4. Testing the Green Environment

Before switching production traffic to the green environment, thoroughly test it. You can expose the green environment temporarily for testing by creating a separate route or using internal tools.

5. Switching Traffic to Green (Cutover)

Once the green environment is fully tested and validated, you can update the Route to direct traffic to the green-service. This will route all new traffic to the green deployment.

You can either modify the existing route or create a new one, as shown below:

apiVersion: route.openshift.io/v1
kind: Route
metadata:
  name: my-app-route
spec:
  host: my-app.example.com
  to:
    kind: Service
    name: green-service
  port:
    targetPort: 8080

Now, traffic will be routed to the green environment.

6. Monitoring and Rollback

After switching traffic, closely monitor the application to ensure the green version is stable. If any issues arise, you can quickly rollback by switching the route back to the blue-service.

Example rollback:

apiVersion: route.openshift.io/v1
kind: Route
metadata:
  name: my-app-route
spec:
  host: my-app.example.com
  to:
    kind: Service
    name: blue-service
  port:
    targetPort: 8080

7. Decommission the Blue Environment

Once you're confident that the green environment is stable, you can scale down or remove the blue environment to save resources.

Example:

oc scale deployment app-blue --replicas=0

Additional Tools for Automation:

OpenShift Pipelines (based on Tekton) can automate the blue-green deployment process.

CI/CD tools like Jenkins or GitHub Actions integrated with OpenShift can streamline deployments and rollbacks.


Key Considerations:

Traffic Splitting: If you want to gradually route traffic between blue and green environments, you can use an advanced traffic management tool like Istio or an external load balancer like Azure Traffic Manager.

Monitoring: Use built-in OpenShift monitoring (Prometheus, Grafana) or Azure Monitor for observing application performance.


This approach ensures minimal downtime during deployment, and quick rollback capabilities.

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...