Skip to main content

Implement Blue/Green deployment with Deployflow

Use the Blue/Green deployment strategy in Deployflow to deploy a Green version while keeping the existing Blue version, then switch traffic after verification.

Basic information
  • Estimated time: 30 minutes
  • Prerequisites
    • The basic CI/CD environment configured in Build CI/CD pipeline with Codeflow and Deployflow
      • A successfully deployed Deployflow application named cicd-app-demo
      • A Codeflow repository, workflow, and self-hosted runner
      • A Container Registry repository and the cr-pull-secret image pull secret
    • An environment that can access the target Kubernetes Engine cluster with local kubectl commands
Related tutorial

This tutorial continues with the cicd-app-demo application and deployment environment configured in Build CI/CD pipeline with Codeflow and Deployflow. If you have not configured the basic CI/CD pipeline, complete that tutorial first.

About this scenario​

In the previous tutorial, you built a container image with a Codeflow workflow and deployed it to a Kubernetes Engine cluster by using Deployflow Raw Manifest. In this tutorial, you apply the Deployflow Blue/Green deployment strategy to the same application, prepare a new version separately, and then switch traffic.

With a Blue/Green deployment, the Blue version continues serving traffic while you prepare a new Green version. After verification, you switch Service traffic to Green. In this tutorial, you rerun the Codeflow workflow with color=green and tag=green, synchronize the Green version in Deployflow, switch traffic, and promote the version.

You verify the Green build and synchronization, traffic switching, and the post-promotion deployment state in order.

Before you start​

Verify the following before proceeding.

  1. Verify that the Codeflow workflow can run. Under Details > Action settings > Runners in the repository, verify that the runner state is Idle.
  2. Verify that the cicd-app-demo Deployflow application has a Sync state of Synced and a State of Healthy.
  3. Open the public EXTERNAL-IP of the cicd-app-demo Service and verify that a blue screen appears.
kubectl -n deployflow get svc cicd-app-demo

Getting started​

Step 1. Apply Blue/Green strategy​

Apply the Blue/Green strategy to the cicd-app-demo application deployed in the previous tutorial.

  1. Select the cicd-app-demo application and click [Configure deployment strategy] on the Deployment strategy tab in the details pane.

  2. In the dialog, configure the following values and click [Save].

    ItemValueDescription
    Deployment strategy optionEnabledWhether to use a deployment strategy (toggle)
    Deployment typeBlue/GreenDeployment strategy to apply
    Target deploymentcicd-app-demoDeployment to which the strategy applies
    Service to connectcicd-app-demoService whose traffic is switched
    Preview ingressDisabledIngress for pre-validating Green; not used in this tutorial
    Relationship with automatic synchronization

    In this tutorial, click [Refresh] to retrieve changes and then click [Synchronize] so you can observe how the Green version is applied.

  3. On the Deployment strategy tab, verify that the deployment strategy is Blue/Green, the resource and Service names are cicd-app-demo, and the Deployment strategy state is Stable.

    Deployment strategy screen Deployment strategy screen example

Caution

If you select the wrong target Deployment or Service, traffic might be routed to unintended Pods when you switch traffic. Before saving, verify that the Deployment and Service reference the same application (app: cicd-app-demo).

Step 2. Build and synchronize Green version​

Build and deploy the Green image. The Service continues to route traffic to Blue until you switch traffic.

  1. Build the Green image: Under Details > Workflows in the Codeflow repository, rerun the workflow created in the previous tutorial. Enter the following parameters.

    ParameterValueDescription
    taggreenImage tag
    colorgreenScreen color

    When the workflow succeeds, it pushes the cicd-app-demo:green image to Container Registry and updates and commits the image tag in k8s/deployment.yaml to :green.

  2. Synchronize Green in Deployflow: Click [Refresh] in the Deployflow application to retrieve changes and verify that the Sync state is Out of Sync. In DIFF under resource details, verify that the image tag changes to :green, then click [Synchronize]. Deployflow prepares the Green version according to the Blue/Green strategy, while the Service continues to route traffic to Blue.

  3. Verify before switching traffic: Even after Green is synchronized, the active Service still routes to Blue until you switch traffic. Open the same public URL and verify that the blue screen still appears.

    kubectl -n deployflow get svc cicd-app-demo
    # Open http://<EXTERNAL-IP> in a browser. The screen is still blue.
    Information

    It is expected that the screen remains blue even when the Green Pods are ready. With a Blue/Green strategy, the active Service keeps routing to the existing Blue version until you switch traffic.

Step 3. Switch traffic​

Check the Green resource's Pod state, then switch traffic.

  1. Check Green before switching: Check the Pod state. Verify that the Pod using the new image is Running and its READY value is true.

    kubectl -n deployflow get pod -l app=cicd-app-demo \
    -o custom-columns='NAME:.metadata.name,IMAGE:.spec.containers[0].image,PHASE:.status.phase,READY:.status.containerStatuses[0].ready'

    If you see an abnormal state such as ImagePullBackOff, CrashLoopBackOff, or FailedScheduling, do not switch traffic. Check Events in resource details or the Pod logs first.

  2. Switch traffic: On the Deployflow Deployment strategy tab, click [Switch traffic], select Green under Traffic switching, and click [Save]. Verify that the Deployment strategy state changes to Green Active.

  3. Verify after switching: Refresh the browser at the same public URL (http://<EXTERNAL-IP>) and verify that the green screen appears. The load balancer reevaluates its endpoints, so only the color changes and the URL remains the same.

    Green screen Green screen example

Step 4. Promote and verify completion​

When the Green version is stable after switching, promote it as the production baseline.

  1. Click [Promote] at the top of the details pane.
  2. Under Select resource in the promotion dialog, select Green (promote new version), review the guidance, and click [Confirm].
  3. Verify that the Sync state (Synced), State (Healthy), and Deployment strategy state are all normal.
  4. Open the same public URL and verify that the Green screen remains visible.
Caution

Promotion determines which version to retain. Before promoting, verify access to Green, Pod states, events, and logs. If you modified runtime resources directly with kubectl patch or a similar command for incident response, recheck the manifest in the Codeflow repository and the Deployflow synchronization state afterward.

Compare manifest differences

After applying the strategy, you can compare the current manifest, DIFF, and target manifest on the Manifest tab under the Deployflow Resources tab. Locally, use kubectl -n deployflow get deploy -l app=cicd-app-demo -o wide and git log --oneline -5 to review source and runtime changes together.