DevOps Tools Introduction #09: Machine Deployment
The last few DevOps tools blogs focussed on container virtualization. One of the major benefits of containers is their incredibly fast startup time and their small overhead. However, containers are not suitable for every type of deployment. There are situations where real virtual machines are required. One of them is the provisioning of multiple container infrastructures for different teams, applications or clients.
The DevOps Tools Engineer certification includes three objectives that cover tools which help to speed up the provisioning of virtual machines:
- 703.1, covering Vagrant, which ships and runs virtual machines and appliances,
- 703.2, focussing on cloud-init, which configures IaaS instances when they are started and
- 703.3, Packer, which prepares images for VMs and IaaS instances.
Since these three objectives all relate to machine deployment, we’ll cover all of them this week.
Let’s get started with Vagrant; Vagrant is a tool that facilitates the deployment of virtual machines and appliances. It allows virtual machines to be downloaded and started without worrying about the individual VM’s details. Vagrant is often used to equip developers with an easy way to set up local test environments with just a few commands.
The installation of Vagrant is simple. Once you set it up, read the Vagrant introduction and follow the Getting Started guide. Since the DevOps Tools Engineer objectives explicitly mention Vagrantfile, review its reference documentation. An especially interesting topic is Vagrant Provisioning, which allows you to leverage tools like Ansible to prepare your virtual machines. The exam objectives explicitly mention file, shell, Ansible and Docker provisioning as well as multi-machine Vagrantfiles.
Running virtual machines locally is great for development and testing. Productive deployments tend to happen in IaaS clouds. These clouds spawn new virtual machines based on images. These images usually are generic and need to be adjusted to each virtual machine derived from thoses images. cloud-init does a great job making these adjustments, such as resizing partitions and file systems or adding users and SSH keys. Usually, cloud-init is included in the base images provided by an IaaS cloud and automatically takes care of the specific adjustments required by the cloud. In addition, users can provide so-called user-data when creating a new instance. This data is passed to cloud-init and instructs it to do additional specific tasks. These tasks are performed by modules with the provided sets of configuration options. The cloud-init documentation contains a series of user-data examples that illustrate how to use modules. To get started with cloud-init, you should find out your if your cloud provider uses cloud-init and lets you specify custom user-data. This would be the perfect playground to do some experiments and implement the tasks mentioned in the DevOps Tools Engineer objectives.
The cloud-init documentation contains detailed instructions regarding the integration of cloud-init into a cloud environment. This is highly specific to each cloud and is usually done by your cloud provider. Don’t get lost in these instructions and focus on what you, as a user in an IaaS cloud, can control yourself.
Cloud providers offer images which already include integration components for their specific clouds. When bundling applications into their own images, it is reasonable to leverage these images instead of building your own base images and manually adjusting them for each cloud.
This is exactly what Packer helps you to do; Packer uses an existing image, runs so-called provisioners to customize it and makes the result available as a new image. The clue is that this can be done with multiple images to create customized images for multiple clouds, each image being derived from the respective cloud’s base image. The easiest way to get started with Packer is by following the official Getting Started guide. It is helpful if you have access to one or two IaaS clouds to follow the examples. Afterwards, make sure to review the official documentation, including the reference for Packer templates. For help on running Packer in your favorite cloud, review the Builders reference.
Now that we have virtual machines running locally and in the cloud, it’s time to take a closer look at the configuration of these systems. Both Vagrant and Packer can leverage a series of tools to customize virtual machines. Next week, we will learn more about one these tools, when we get started with configuration management through Ansible.