Blue/Green Deployments in OpenShift With Eclipse JKube
Tutorial to implement a Blue/Green deployment to deploy your Java application into OpenShift using Eclipse JKube Maven Plug-In.
Join the DZone community and get the full member experience.Join For Free
Blue/Green Deployment is a well-known application release model 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 management of the production traffic from one color (old version) to the other (new version); the old version can stand by in case of a rollback or it can be 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 downtimes 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 on Maven Profiles and filtering resources. Of course, this is only an integration sample and it is open to having other approaches. For this example, I would like to dig into the Eclipse JKube Profiles as another approach. However, feel free to add your ideas, comments, or suggestions.
Identifying Blue/Green Version
Every time we want to deploy a new version, we must identify the right color to be used to deploy it. This process should be done in the CD pipeline before deploying our next application version.
For example, we could use a variable called
app.bg.version in the
pom.xml file. A Maven Profile could help us to declare each version. This variable will be used to filter some resources at deployment time.
Sample Maven profile for Blue Deployment:
Defining Blue/Green Objects
Each Blue and Green version should use its own resources at deployment time to avoid replacing or redeploying 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 by creating a
deployment.yml file in the
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:
Deploying the Blue Version
Now, we could easily deploy the Blue version by using the Maven Profile. For example, using the OpenShift Maven Plugin the command will be similar to:
Deploying the Green Version
Likewise, we can easily deploy the Green version 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 to all of these objects, we can manage both versions at the same time, and in combination with a CD pipeline and other resources, can 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 version. That route could be similar to:
Rolling From Blue to Green
To roll from Blue to Green version, simply path the load balancer route (in the case of OpenShift) like so:
Rolling From Green to Blue
To roll from Green to Blue version, simply path the load balancer route (in the case of OpenShift) like so:
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.
Published at DZone with permission of Roman Martin Gil. See the original article here.
Opinions expressed by DZone contributors are their own.