If bootstrapping myself over the past years taught me one thing, it is that virtual machines are invaluable for doing business.
But then I realized that installing a virtual machine that fits your needs can take hours. This is not very efficient. So I thought to myself… how about I automate the whole process of virtual machine installation?
The product of this automation step is a golden virtual machine image, and it is becoming popular in organizations with a lot of projects.
Today we will discuss what golden images are and how you can create a golden image with HashiCorp Packer.
What Are Golden Images
A golden VM image is a ready-to-use image of a virtual machine. It is plug-and-play; you import the image into the virtualization software and start the VM. There are no additional installation steps, and the configuration is ready to go.
It is even possible you have already used a golden VM image without knowing it. When you spin up a virtual machine in Azure, AWS, or any other cloud provider, you are in essence using a golden image. This golden image is usually created by the cloud provider, and it takes away the burden of having to go through the installation steps.
There are times when those images are not enough, though. If an organization has a lot of projects it needs to take care of, there is a good chance it has active policies in place that regulate all projects across the organization. It could be logging and monitoring systems, permissions, firewalls, networking, or whatever. This is when the images from the cloud providers are not enough anymore, and it is best if you produce your own images.
Producing your own images gives you more flexibility in how to design the image. You can configure and customize it to your needs, so that it complies with company policies. But even when your organization does not have a lot of policies, it is still a very efficient automation step. It gives your project control, reproducibility, and documentation through Infrastructure as Code. Every configuration is a file, and with golden images, you comply with this philosophy.
HashiCorp Packer: An Introduction
Automating the installation of a virtual machine is a very niche topic. Therefore, there are not a lot of solutions tackling this problem. You can either use bash scripts (which I would say is the classic way), or you can use HashiCorp Packer. Packer is open-source software licensed under the Business Source License. It is managed and developed to a great part by IBM.
Packer is a great tool to automate the process of provisioning golden machine images, as you can combine multiple sources into one build process. You can run Packer effectively in CI/CD pipelines, and several cloud providers integrate with Packer.
In conclusion, Packer is definitely the best practice when it comes to golden virtual machine images.
However, Packer is not an easy tool to understand. You first have to get your head around what problems virtual machines actually solve. Then you have to understand how the installation of a virtual machine works. Installing Debian once is not enough. Installing more complex operating systems, like Arch or Gentoo, will most certainly help.
You should also know what KVM is. Not by heart, as you would need a very strong heart to understand KVM in its entirety. But you should be able to explain type-1 and type-2 hypervisors and where KVM belongs in the ecosystem of virtual machines.
Packer dives deep into the installation process. It automates everything. You run the packer command in the Linux CLI, and 20 minutes later you get a ready-to-use virtual machine image. This is how it works. It utilizes tools like cloud-init and Red Hat Kickstart to automate the installation process. After that, you can do further provisioning with Bash scripts as needed.
You don’t need knowledge of cloud-init or Kickstart beforehand, but it helps a great deal if you at least know what those tools do.
Advice for Universities
So far, this post has discussed the business perspective of golden images. But there is another perspective we should keep in mind, and that is that of the individual engineer.
In university, they teach about the business perspective of virtual machines a great deal, but this approach to teaching is incorrect.
Virtual machines are not only beneficial for organizations; organizations are profiting about the same as individual engineers from virtual machines.
Sure, organizations run their workloads on virtual machines, but everybody knows that by now. This is the first thing they teach you in university when it comes to virtual machines.
Universities should not only teach the business perspective of technology.
This approach is too narrow and will not spark interest in the students, as they do not understand why they should use virtual machines.
They do not understand the benefits of virtual machines for themselves.
Universities should instead teach the benefits of virtual machines not only for real-world projects but also for individual engineers. This is where it clicks for the students.
Talking about why businesses use virtual machines to 21-year-old students won’t do a thing. But giving them a reason to use virtual machines themselves will greatly improve their understanding of the technology.
Put yourself in the shoes of the student. What do you think will happen faster: you becoming the CIO of an organization or you building your own homelab?