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.
- 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-secretimage pull secret
- A successfully deployed Deployflow application named
- An environment that can access the target Kubernetes Engine cluster with local
kubectlcommands
- The basic CI/CD environment configured in Build CI/CD pipeline with Codeflow and Deployflow
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.
- Verify that the Codeflow workflow can run. Under Details > Action settings > Runners in the repository, verify that the runner state is
Idle. - Verify that the
cicd-app-demoDeployflow application has a Sync state ofSyncedand a State ofHealthy. - Open the public
EXTERNAL-IPof thecicd-app-demoService 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.
-
Select the
cicd-app-demoapplication and click [Configure deployment strategy] on the Deployment strategy tab in the details pane. -
In the dialog, configure the following values and click [Save].
Item Value Description Deployment strategy option EnabledWhether to use a deployment strategy (toggle) Deployment type Blue/GreenDeployment strategy to apply Target deployment cicd-app-demoDeployment to which the strategy applies Service to connect cicd-app-demoService whose traffic is switched Preview ingress DisabledIngress for pre-validating Green; not used in this tutorial Relationship with automatic synchronizationIn this tutorial, click [Refresh] to retrieve changes and then click [Synchronize] so you can observe how the Green version is applied.
-
On the Deployment strategy tab, verify that the deployment strategy is
Blue/Green, the resource and Service names arecicd-app-demo, and the Deployment strategy state isStable.
Deployment strategy screen example
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.
-
Build the Green image: Under Details > Workflows in the Codeflow repository, rerun the workflow created in the previous tutorial. Enter the following parameters.
Parameter Value Description taggreenImage tag colorgreenScreen color When the workflow succeeds, it pushes the
cicd-app-demo:greenimage to Container Registry and updates and commits the image tag ink8s/deployment.yamlto:green. -
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. -
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.InformationIt 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.
-
Check Green before switching: Check the Pod state. Verify that the Pod using the new image is
Runningand itsREADYvalue istrue.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, orFailedScheduling, do not switch traffic. Check Events in resource details or the Pod logs first. -
Switch traffic: On the Deployflow Deployment strategy tab, click [Switch traffic], select
Greenunder Traffic switching, and click [Save]. Verify that the Deployment strategy state changes toGreen Active. -
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 example
Step 4. Promote and verify completion
When the Green version is stable after switching, promote it as the production baseline.
- Click [Promote] at the top of the details pane.
- Under Select resource in the promotion dialog, select
Green (promote new version), review the guidance, and click [Confirm]. - Verify that the Sync state (
Synced), State (Healthy), and Deployment strategy state are all normal. - Open the same public URL and verify that the Green screen remains visible.
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.
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.