11 November 2020

#Packer

Packers
  • Packer =Reusable machine image.
  • Image is pre-configure by default.
  • We can use that pre-configured image no need to go from starting like install step.
  • Image =Saving the time on installation.
  • One time we install it and next time we take image
  • A tool from Hashicorp to build machine images for most platforms (AWS, Google Cloud, Digital Ocean, Docker, Azureetc.) and automate configurations and installation of software?s that need to be present.
  • We define how to build the image in a JSON template file. This should be version controlled and is treated like any other code.
Sections of Packer template
Variables
  • Packer template should be made generic so it can be used in different environment and keeping secrets/credentials secure by not providing them in the template file.
  • Use user variables in place of such configurations.
Builders
  • A builder takes care of creating an image.
  • Packer provides builders for various platforms. For this example we will be using amazon-ebs as builder.
  • We provide platform specific configurations in the builder section of the template. Like what type of instance (t2-micro m4-large etc) to spin up to create the image, SSH/Access details or credentials.
  • Builders use Communicators to establish connection with the created instance. Either it can be a SSH connection or WINRM for Windows machine.
Provisioners
  • Once a machine is created by the builder we will use provisioners to install software?s and configure the machine to a desired state.
  • Packer provide provisioners for configuration management tools like Chef / Puppet / Ansible or good old shell script.
Post-Processors
  • Once the machine is created and software is installed and configurations applied by Provisioners Post-Processors are run. We can use them for example to push a docker image to a registry. So what exactly does Packer do?
  • Packer will spin up an instance for the specified platform based on the type of builder.
  • Use the Communicator specified to connect to the machine.
  • Run all the provisioners to configure and install software?s.
  • It the runs any post-processors specified in the JSON template.
Finally it terminates machines and any temporary resources it created in the process e.g. security group, temporary ssh key-pair etc.

No comments:

Post a Comment

Most views on this month