Blue Green Deployment is an application release model very well-known that gradually transfers user traffic from a previous version of an application or microservice to a nearly identical new release—both of which are running in production.
The old version of the application or microservice is identified with a color (e.g: Blue) while the new version is identified with the other color (e.g: Green). This model allows to manage the production traffic from one color (old version) to the other (new version), and the old version can standby in case of rollback or pulled from production and updated to become the template upon which the next update is made .
This model requires a Continuous Deployment model or pipeline to orchestrate the promotion between each color and manage the down times or rolling process. CD pipelines could be implemented using the capabilities provided by Eclipse JKube .
Eclipse JKube is a collection of plugins that are used for building container images using Docker, JIB or S2I build strategies. In addition, Eclipse JKube generates and deploys Kubernetes/OpenShift manifests (YAML configuration files) at compile time too.
This article describes an approach to integrate a Blue/Green deployment with Eclipse JKube. This approach is based in Maven Profiles and filtering resources. Of course, this is only an integration sample and it is open to have other approaches. For example, I would like to dig into the Eclipse JKube Profiles as other approach . However, feel free to add your ideas, comments or suggestions .
Identifying Blue / Green Version
Every time we want to deploy a new version it is needed to identify the right color to be used to deploy it. This process should be done in the CD pipeline before to deploy our next application version.
For example we could use a variable called
app.bg.version in the
pom.xml file. To
declare each version a Maven Profile could help us. This variable will be used to filter some
resources at deployment time.
Sample Maven profile for Blue Deployment:
Sample Maven profile for Green Deployment:
This value could also be used to define the version of the image built. A sample of that could
be using the
jkube.generator.name property in the
pom.xml file as:
Defining Blue/Green Objects
Each Blue and Green version should use its own resources at deployment time to avoid replace or redeploy the other deployment. To do that we would use Eclipse JKube resource fragments to declare specific definitions of some Kubernetes or OpenShift objects.
In our case we will declare a custom deployment object creating a
deployment.yml file in
jkube folder. This custom deployment will override some properties to use the
active version at deployment time.
A sample of this file could be similar to:
To access the version deployed a service is needed to map it. This service should be
aligned with the right version. A
service.yml file in the
jkube folder similar
to the next one could be similar to:
Deploying the Blue Version
Now, we could deploy the Blue version easily using the Maven Profile. For example, using the OpenShift Maven Plugin the command will be similar to:
Deploying the Green Version
On the other hand, we could deploy the Green version easily using the Maven Profile. For example, using the OpenShift Maven Plugin the command will be similar to:
Blue/Green Resources Deployed
This process generates the following objects:
- Image Streams for each version:
- Build Config for each version:
- Deployments for each version:
- Services for each version:
Thanks of all these objects we could manage both versions at the same time, and in combination with a CD pipeline and other resources could manage the traffic to activate the right version (Blue or Green) to the final users.
For example, we could have an OpenShift route to balance the application between each versions. That route could be similar to:
Rolling from Blue to Green
To roll from Blue to Green version it is only to path the load balancer route (in the case of OpenShift) as:
Rolling from Green to Blue
To roll from Green to Blue version it is only to path the load balancer route (in the case of OpenShift) as:
Show me the code
If you want to test and verify this approach, I developed a sample case in one of my favorite GitHub repo. This repo includes amazing frameworks as Quarkus, Schemas Avro and Apache Kafka in a small Event-Driven Architecture.