Spinnaker

Blue-Green deployment using Spinnaker, Packer and Jenkins on AWS

Posted on

Key Objectives:

  1. Need to create immutable server images of windows or linux server.
  2. Need to achieve desire state using configuration management tools like Chef, Powershell etc..
  3. Need to do deployment on public cloud provider like AWS.
  4. Need to deploy web application without downtime.
  5. Need to support the rollback of deployed web application.

Solution:

To manage the continuous delivery with blue green deployment using spinnaker need to have delivery pipeline which consist of build , bake and deploy phase.

Build Phase

Spinnaker provide integration with Jenkins using Igor micro service. Build phase is nothing but Jenkins Job which consists of following stages.

  1. Check out the source code from git/svn tagged branch.
  2. Build the artifact as per build management tool like MsBuild, Maven, Gradle, SBT etc..
  3. Publish the artifact to artifact repository like AWS S3, Apache Artifactory or Nuget Server as per requirement.
  4. Need to pass the output of the build phase like artifact url to the spinnaker which can be used in bake phase. The supported format is json which is accessed using spinnaker expression language

Bake Phase

Baking immutable server images a.k.a golden images for target platform like AWS, GCP etc.. is done by Packer. By default Packer is provided by spinnaker which helps to bake images for Linux server only if want to bake windows server image then need to have packer as a separate component which can be executed through Jenkins. Following steps need to perform in bake phase or pipeline.

  1. Execute Packer Jenkins Job from spinnaker with parameters like artifact url, AWS credential, instance type etc..
  2. Packer is supporting different types of provisioners like chef-client, shell or for windows server Powershell which help to bring the desire state of the immutable server image. e.g. in case of Web Server AMI need to have base image of windows server on top of it need to install Dot.NET, IIS and configure WEB Application.
  3. Once the desire state is achieved then Packer will create AMI on AWS and produced AMI ID as output which can be used for deployment so that need to pass it to Spinnaker.

Deploy Phase

Spinnaker provides the deploy stage in delivery pipeline with different strategies to do the deployment. Red/Black or Blue-Green deployment is one of the strategy which helps to do the deployment without down time.

On AWS to achieve Blue-Green deployment need to have Elastic load balancer (ELB), Auto scale group (ASG) with launch configuration with immutable server image (AMI Id) produced by bake phase. So that every new deployment will create new ASG with launch configuration will point pre-baked AMI ID and this ASG is attached to ELB. Then need to wait to pass health check of ASG launched instances, once health check is successful then downscale old ASG with min-max configuration to zero.

This complicated thing is smoothly handled by Spinnaker. DevOps only need to tune the health check parameter of ELB as per application need.

Conclusion

One can target continuous delivery by following Blue-Green deployment for web applications using Spinnaker, Jenkins and Packer for public cloud provider like AWS, GCP etc. Even Spinnaker integration with Jenkins can help to manage non web resources(databases, platform specific resources) of cloud providers using Terraform.

References

Advertisements