Golden images: why Packer
Why teams bake software and hardening into a machine image once, instead of installing it on every server at boot, and how one Packer template builds the same image for many platforms.
Diagrams in this video · 2Free in archhy
The diagrams, full size
Copy any of them into archhy, free, and change it for your own system.
After this lesson you can
- Define a machine image and a golden image
- Compare baking an image with configuring each server at boot
- Explain how one Packer template builds images for several platforms
- Place Packer next to Terraform and configuration tools
Transcript
Golden images: why Packer
G'day. Space Llama here. So far, Terraform has been building servers from images somebody else made. Today we start making our own. Welcome to golden images, and to Packer.
What a machine image is
A machine image is a single static unit. It holds an operating system, already set up, plus any software you installed. You launch new servers from it. Every one starts as an exact copy. On AWS, that's an Amazon Machine Image, or AMI. Azure, Google Cloud and the rest have their own. A golden image is one your team has blessed. Patched, hardened, and carrying the tools every server needs.
Bake, don't fry
There are two ways to get software onto a server. People call them frying and baking. Frying means you boot a plain image, then install and configure everything, every single time a server starts. It works, but it's slow. And if a package mirror changes overnight, today's server differs from yesterday's. Baking means you do the installing once, ahead of time, and save the result as an image. Servers launched from it are ready as soon as they boot, and they're all the same. That's the immutable idea from Part 1.
One template, many platforms
This is where Packer comes in. Packer is a HashiCorp tool for creating identical machine images for multiple platforms from a single source configuration. That source is a template. Here it's called web dot P K R dot H C L. Run packer build, and the one template can make an AMI on AWS, a managed image on Azure, and a Docker container image. Packer can build them in parallel. Same steps, same software, three platforms. So if you ever move clouds, or run in two, your image recipe comes with you.
Why teams bake
So why do teams bother baking? Speed, first. When traffic spikes, a baked server is useful in moments, not after a long install. Sameness, second. Dev, staging and production all start from the very same image, so tests mean something. Patching changes, too. You don't log in to fix a hundred servers. You patch the template, build a new image, and replace them. And you can scan an image for vulnerabilities before a single server runs it.
Where Packer fits
Packer and Terraform are a team, with a clean split. Packer builds the image. Terraform builds the infrastructure, and launches servers from that image. Packer doesn't replace configuration tools like Ansible, Chef or Puppet, either. It can run them during the build. The output of Packer, an image ID, becomes an input to Terraform. Hold that thought. It's the whole of Part 7.
Recap
Let's recap. A golden image is a patched, hardened, approved starting point for your servers. Baking installs everything once, so servers start ready and identical. Frying repeats the work at every boot. Packer builds identical images for many platforms from one template. And Packer makes the image, while Terraform launches servers from it.
Practice and what's next
That's golden images. Bake once, launch many, and nobody waits for a package download. Next lesson, Anatomy of a template. We'll open one up, block by block. See you there.
Gazeek Flash · free
Exam questions on your phone
Free questions on Packer and golden images: quick-fire batches and timed exams, on the web or Android.






