How to create identical images across the cloud providers with Packer.io -01

Lets take a example of a Ecommerce Company which have their Application running on Digital Ocean and then they thought they need to migrate to a better service provider and migrate most of their servers from Digital Ocean to Rackspace(Though the decision of changing the Cloud provider is so tough these days as most of the Cloud providers are providing promising Services).

So inorder to understand the stack of what the application consists of with related to its dependencies and other factors which make the application up and running.

Inorder to make the issue more complicated i will go with a  Loosely Coupled Application Architecture of Services interdependent on each others Service.

shopping-system

I have a Frontend service which runs the Application which show most of the inventories of different categories of things for a end user to buy and on the other side i have the Core Logic of the Application Divided in a Micro Service model where every main core logic of the application will be running on its own Service type and the data layer will be connecting to their individual DB’s to do the normal CRUD operations.

So seeing the traffic on the site they would like to scale their servers and move some part of the servers on to Rackspace which eventually change their stack totally from Digital Ocean to Rackspace.To make migration of server every System Admin have their own way of doing it keeping in my mind about the downtime.(This can be implemented in many ways which i will be going up with one approach)

They started using one of the Configuration management tool and started writing the dependency packages and the total infrastructure services and configuration information to provision around 40 servers at a time and divide them into groups based upon the services.

That approach is always good to go but there will be mainly a issue with related to the time it takes to provision all the 40 servers by provisioning them with the services installed and the provisioning should be much faster when there is any scale-up activities happening on demand.

So inorder to reduce this issue we may install the whole application stack before the provisioning starts from any configuration tool so that the time of installing will be reduced in return applying the configurations will be faster.

Introducing Packer.io from Hashicorps where they have a solution to install the application stack across the cloud providers in no time by creating templates which does most of the Application Installations and create a image or a snapshot where the Configuration Management tools take  them as their base image to create servers.

Packer-520x245

 

Packer is a tool which helps us creating the identical machine images across the cloud providers so that the pain of Provisioning the servers by installing the application will be reduced and Configuration of the files to point to multiple services will be taken care by the Configuration management tools.

With this the Approach the Server Migration from one Cloud Provider (Can be a Public — > Private or Private — > Public) will be really easy.

Packer is written in Golang and as of now it supports

1)AWS

2)Digital Ocean

3)GCE

4)Openstack

5)Vmware

6)Virtualbox

7)Parallels

8)Docker

Packer Template are written in Json and Packer Template consists of mostly the given below Template blocks

1)Variables

2)Builders

3)Provisioners

Variables

Variables are like declaring on what variables we need to use in the Template.

Example–

"variables":{
        "aws_access_key":"xxxxxxxxxxxxxxxxxxxxx",
         "aws_secret_key":"yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"
 },
"builders":[{
             "type" : "amazon-ebs",
              "access_key": "{{ user `aws_access_key`}}",
               "secret_key": "{{user `aws_secret_key`}}",

Builders

Builders will help in Creating the Image on which Provider.Like the above example we are using the Amazon EBS storage based instances in creating the image.

Provisioner

Provisioner will help us to write on what packages have to be installed on the image and what files have to be pulled on to the image from the local path where we start running the Packer command.

Working Process

Packer which it takes the given above template blocks to provide the Image will initially start a instance on the respective Cloud provider and does the whole Server Provisioning with related to the Application installation and then when the process is done it creates a Image from that instance and stops running the image and in return terminates when the whole installation process is done.

This Image which have a new Image id will be used by the Configuration management tools in creating the Instances and do the minimal Configuration changes for the Application Stack to get connected.

Packer internals will be in the next part of the Post.Stay Tuned…!!!!

 

 

Leave a comment